Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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

Circle, round and line shapes are provided. Circle is the default pill shape, round uses a rounded rectangle, and line does not render switch content.

{{ 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 }}

### 不同形状的开关

提供 circle、round 和 line 3 种形状。circle 为默认胶囊形态,round 为圆角矩形形态,line 为线性形态且不展示开关描述。

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

.@{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--shape-line {
background-color: transparent;
overflow: visible;

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

&:hover {
background-color: transparent;

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

.@{prefix}-switch__handle {
z-index: 1;
top: 50%;
left: 0;
width: calc(@switch-height-default - 2 * @switch-width-border-check-default);
height: calc(@switch-height-default - 2 * @switch-width-border-check-default);
transform: translateY(-50%);
}

.@{prefix}-switch__content {
position: relative;
z-index: 1;
}

&:active:not(.@{prefix}-is-disabled):not(.@{prefix}-is-loading) {
.@{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 {
left: 100%;
transform: translate(-100%, -50%);
}
}

&.@{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;

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

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

.@{prefix}-switch.@{prefix}-size-l.@{prefix}-switch--shape-line {
&::before {
height: @switch-line-track-height-l;
}

.@{prefix}-switch__handle {
width: calc(@switch-height-l - 2 * @switch-width-border-check-l);
height: calc(@switch-height-l - 2 * @switch-width-border-check-l);
}
}

.@{prefix}-switch.@{prefix}-size-s.@{prefix}-switch--shape-line {
&::before {
height: @switch-line-track-height-s;
}

.@{prefix}-switch__handle {
width: calc(@switch-height-s - 2 * @switch-width-border-check-s);
height: calc(@switch-height-s - 2 * @switch-width-border-check-s);
}
}
7 changes: 7 additions & 0 deletions style/web/components/switch/_var.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
@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-track-height-l: 4px;
@switch-line-track-height-default: 4px;
@switch-line-track-height-s: 3px;

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