Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/web/api/switch.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ Switches for normal, loading and disabled are provided. Set the corresponding st
Large, medium (default) and small switches are provided.

{{ size }}

### Switches of Different Shapes

Three shapes are provided: circle, round and line. `label` is not rendered when shape is `line`.
Comment thread
Seeridia marked this conversation as resolved.
Outdated

{{ shape }}
6 changes: 6 additions & 0 deletions docs/web/api/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ spline: form
提供 大、中(默认)、小 3种开关。

{{ size }}

### 不同形状的开关

提供胶囊形、圆角形和线性 3 种形状。`line` 形态不展示开关内容。

{{ shape }}
189 changes: 189 additions & 0 deletions style/web/components/switch/_index.less
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,192 @@
}
}
}

.@{prefix}-switch.@{prefix}-switch--shape-round {
border-radius: @switch-round-track-border-radius;

.@{prefix}-switch__handle,
.@{prefix}-switch__handle::before {
border-radius: @switch-round-handle-border-radius;
}
}

.@{prefix}-switch.@{prefix}-switch--shape-line {
width: @switch-line-width-default;
min-width: @switch-line-width-default;
height: @switch-height-default;
line-height: @switch-height-default;
background-color: transparent;
overflow: visible;
Comment thread
Seeridia marked this conversation as resolved.

&:hover {
background-color: transparent;
}

&::before {
content: '';
position: absolute;
left: @switch-line-track-inset;
right: @switch-line-track-inset;
top: 50%;
height: @switch-line-track-height;
transform: translateY(-50%);
border-radius: @switch-line-track-border-radius;
background-color: @switch-unchecked-bg-color;
transition: @switch-transition;
}

&:hover::before {
background-color: @switch-unchecked-bg-color-hover;
}

.@{prefix}-switch__handle {
top: 50%;
left: 0;
right: auto;
width: @switch-line-handle-size-default;
height: @switch-line-handle-size-default;
transform: translateY(-50%);
box-shadow: @shadow-1;
z-index: 1;

.t-icon {
font-size: @switch-line-handle-size-default;
}
}

&:active:not(.@{prefix}-is-disabled):not(.@{prefix}-is-loading) {
.@{prefix}-switch__handle::before,
&.@{prefix}-is-checked .@{prefix}-switch__handle::before {
left: 0;
right: 0;
}
}

&.@{prefix}-is-checked {
background-color: transparent;

&::before {
background-color: @switch-checked-bg-color;
}

&:hover::before {
background-color: @switch-checked-bg-color-hover;
}

.@{prefix}-switch__handle {
top: 50%;
left: calc(100% - @switch-line-handle-size-checked-default);
right: auto;
width: @switch-line-handle-size-checked-default;
height: @switch-line-handle-size-checked-default;
transform: translateY(-50%);

.t-icon {
font-size: @switch-line-handle-size-checked-default;
}
}
}

&.@{prefix}-is-loading {
background-color: transparent;

&::before {
background-color: @switch-unchecked-bg-color-loading;
}

&.@{prefix}-is-checked::before {
background-color: @switch-checked-bg-color-loading;
}
}

&.@{prefix}-is-disabled {
background-color: transparent;

.@{prefix}-switch__handle {
box-shadow: @shadow-1;
}

&::before {
background-color: @switch-unchecked-bg-color-disabled;
}

&.@{prefix}-is-checked {
background-color: transparent;

&::before {
background-color: @switch-checked-bg-color-disabled;
}

.@{prefix}-switch__handle {
box-shadow: @shadow-1;
}
}
}
}

.@{prefix}-switch.@{prefix}-size-l.@{prefix}-switch--shape-line {
width: @switch-line-width-l;
min-width: @switch-line-width-l;
height: @switch-height-l;
line-height: @switch-height-l;

.@{prefix}-switch__handle {
top: 50%;
left: 0;
right: auto;
width: @switch-line-handle-size-l;
height: @switch-line-handle-size-l;
transform: translateY(-50%);

.t-icon {
font-size: @switch-line-handle-size-l;
}
}

&.@{prefix}-is-checked .@{prefix}-switch__handle {
top: 50%;
left: calc(100% - @switch-line-handle-size-checked-l);
right: auto;
width: @switch-line-handle-size-checked-l;
height: @switch-line-handle-size-checked-l;
transform: translateY(-50%);

.t-icon {
font-size: @switch-line-handle-size-checked-l;
}
}
}

.@{prefix}-switch.@{prefix}-size-s.@{prefix}-switch--shape-line {
width: @switch-line-width-s;
min-width: @switch-line-width-s;
height: @switch-height-s;
line-height: @switch-height-s;

.@{prefix}-switch__handle {
top: 50%;
left: 0;
right: auto;
width: @switch-line-handle-size-s;
height: @switch-line-handle-size-s;
transform: translateY(-50%);

.t-icon {
font-size: @switch-line-handle-size-s;
}
}

&.@{prefix}-is-checked .@{prefix}-switch__handle {
top: 50%;
left: calc(100% - @switch-line-handle-size-checked-s);
right: auto;
width: @switch-line-handle-size-checked-s;
height: @switch-line-handle-size-checked-s;
transform: translateY(-50%);

.t-icon {
font-size: @switch-line-handle-size-checked-s;
}
}
}
17 changes: 17 additions & 0 deletions style/web/components/switch/_var.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@
@switch-width-border-check-default: (@switch-width-border-check-base - @switch-width-border-check-value * 1);
@switch-width-border-check-s: (@switch-width-border-check-base - @switch-width-border-check-value * 2);

// shape
@switch-round-track-border-radius: @border-radius-default;
@switch-round-handle-border-radius: @border-radius-small;

@switch-line-width-l: 39px;
@switch-line-width-default: 32px;
@switch-line-width-s: 26px;
@switch-line-track-inset: 2px;
@switch-line-track-height: 6px;
@switch-line-track-border-radius: @border-radius-round;
@switch-line-handle-size-l: calc(@switch-height-l - 2 * @switch-width-border-l);
@switch-line-handle-size-default: calc(@switch-height-default - 2 * @switch-width-border-default);
@switch-line-handle-size-s: calc(@switch-height-s - 2 * @switch-width-border-s);
Comment thread
Seeridia marked this conversation as resolved.
@switch-line-handle-size-checked-l: calc(@switch-height-l - 2 * @switch-width-border-check-l);
@switch-line-handle-size-checked-default: calc(@switch-height-default - 2 * @switch-width-border-check-default);
@switch-line-handle-size-checked-s: calc(@switch-height-s - 2 * @switch-width-border-check-s);
Comment thread
Seeridia marked this conversation as resolved.

// 字体
@switch-content-font-size-l: @font-size-l;
@switch-content-font-size-default: @font-size-s;
Expand Down