amis/scss/components/form/_switch.scss

119 lines
2.6 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: var(--Switch-width);
height: var(--Switch-height);
2019-12-06 09:58:08 +08:00
overflow: hidden;
border-radius: px2rem(30px);
background: var(--Switch-onActive-bgColor);
2019-12-06 09:58:08 +08:00
margin: 0;
vertical-align: middle;
text-align: left;
&.is-disabled {
background: var(--Switch-onDisabled-bgColor);
2019-12-06 09:58:08 +08:00
}
i {
&:before {
content: '\5173';
color: var(--Switch-valueColor);
text-indent: calc(var(--Switch-width) / 2);
2019-12-06 09:58:08 +08:00
text-transform: uppercase;
font-size: var(--fontSizeSm);
line-height: var(--Switch-height);
2019-12-06 09:58:08 +08:00
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: var(--Switch-bgColor);
border: px2rem(1px) solid var(--Switch-borderColor);
2019-12-06 09:58:08 +08:00
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: var(--white);
width: calc(var(--Switch-height) - #{px2rem(2px)});
2019-12-06 09:58:08 +08:00
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: var(--Switch-onDisabled-color);
background: var(--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 {
background: var(--Switch-onDisabled-circle-BackgroundColor);
color: var(--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: calc(var(--Switch-width) - var(--Switch-height));
2019-12-06 09:58:08 +08:00
content: '\5f00';
color: var(--white);
2019-12-06 09:58:08 +08:00
text-indent: px2rem(-18px); // todo
text-transform: uppercase;
font-size: var(--fontSizeSm);
2019-12-06 09:58:08 +08:00
font-weight: bold;
font-style: normal;
line-height: var(--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: var(--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: var(--Switch-gap);
2019-12-06 09:58:08 +08:00
}
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 {
padding-top: calc((var(--Form-input-height) - var(--Switch-height)) / 2);
2019-04-30 20:52:23 +08:00
2019-12-06 09:58:08 +08:00
&.is-inline {
display: inline-block;
}
}