amis/scss/components/form/_switch.scss

119 lines
2.5 KiB
SCSS
Raw Normal View History

2019-04-30 11:11:25 +08:00
.#{$ns}Switch {
2019-12-06 09:58:08 +08:00
cursor: pointer;
position: relative;
display: inline-block;
width: $Switch-width;
height: $Switch-height;
overflow: hidden;
border-radius: px2rem(30px);
background-color: $Switch-onActive-bgColor;
margin: 0;
vertical-align: middle;
text-align: left;
&.is-disabled {
background-color: $Switch-onDisabled-bgColor;
}
i {
&:before {
content: '\5173';
color: $Switch-valueColor;
text-indent: ($Switch-width / 2);
text-transform: uppercase;
font-size: $fontSizeSm;
line-height: $Switch-height;
font-style: normal;
font-weight: bold;
2019-12-06 09:58:08 +08:00
position: absolute;
top: px2rem(-1px);
bottom: px2rem(-1px);
left: px2rem(-1px);
right: px2rem(-1px);
background-color: $Switch-bgColor;
border: px2rem(1px) solid $Switch-borderColor;
border-radius: px2rem(30px);
transition: all 0.2s;
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
&:after {
content: '';
position: absolute;
background-color: $white;
width: $Switch-height - px2rem(2px);
top: px2rem(1px);
bottom: px2rem(1px);
left: px2rem(1px);
border-radius: 50%;
// box-shadow: px2rem(1px) px2rem(1px) px2rem(3px) rgba(0, 0, 0, 0.25);
transition: margin-left 0.3s;
}
}
2019-04-30 11:11:25 +08:00
2019-12-06 09:58:08 +08:00
input {
position: absolute;
opacity: 0;
&:disabled,
&:disabled:checked {
& + i {
&:before {
color: $Switch-onDisabled-color;
background-color: $Switch-onDisabled-bgColor;
2020-03-31 15:54:31 +08:00
cursor: not-allowed;
2019-04-30 11:11:25 +08:00
}
2019-04-30 11:11:25 +08:00
&:after {
2019-12-06 09:58:08 +08:00
background-color: $Switch-onDisabled-circle-BackgroundColor;
color: $Switch-onDisabled-color;
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
}
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
&:checked {
& + i {
&:before {
left: 100%;
border-width: 0;
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
&:after {
margin-left: $Switch-width - $Switch-height;
2019-12-06 09:58:08 +08:00
content: '\5f00';
color: $white;
text-indent: px2rem(-18px); // todo
text-transform: uppercase;
font-size: $fontSizeSm;
font-weight: bold;
font-style: normal;
line-height: $Switch-height;
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
}
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
}
2019-04-30 11:11:25 +08:00
}
.#{$ns}Switch-option {
2019-12-06 09:58:08 +08:00
vertical-align: middle;
margin-left: $Switch-gap;
2019-04-30 11:11:25 +08:00
2019-12-06 09:58:08 +08:00
&:first-child {
margin-left: 0;
margin-right: $Switch-gap;
}
2019-04-30 11:11:25 +08:00
2019-12-06 09:58:08 +08:00
&:empty {
display: none;
}
2019-04-30 11:11:25 +08:00
}
.#{$ns}SwitchControl {
2019-12-06 09:58:08 +08:00
padding-top: ($Form-input-height - $Switch-height) / 2;
2019-04-30 20:52:23 +08:00
2019-12-06 09:58:08 +08:00
&.is-inline {
display: inline-block;
}
}