amis/scss/components/form/_switch.scss

98 lines
1.8 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;
height: var(--Switch-height);
min-width: var(--Switch-width);
2019-12-06 09:58:08 +08:00
overflow: hidden;
border-radius: px2rem(30px);
background: var(--Switch-bgColor);
2019-12-06 09:58:08 +08:00
margin: 0;
vertical-align: middle;
text-align: left;
&.is-disabled {
cursor: not-allowed;
opacity: 0.4;
2019-12-06 09:58:08 +08:00
}
.text {
margin: 0 px2rem(7px) 0 px2rem(25px);
color: var(--Switch-valueColor);
text-indent: calc(var(--Switch-width) / 2);
text-transform: uppercase;
font-size: var(--fontSizeSm);
line-height: var(--Switch-height);
font-style: normal;
font-weight: bold;
transition: all var(--animation-duration);
}
2019-04-30 11:11:25 +08:00
.slider {
&:before {
2019-12-06 09:58:08 +08:00
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%;
transition: margin-left var(--animation-duration);
2019-12-06 09:58:08 +08:00
}
}
2019-04-30 11:11:25 +08:00
&.is-checked {
background: var(--Switch-onActive-bgColor);
.slider::before {
left: auto;
right: px2rem(1px);
border-width: 0;
2019-04-30 11:11:25 +08:00
}
.text {
margin: 0 25px 0 7px;
color: var(--white);
text-indent: var(--gap-xs); // todo
}
}
2019-04-30 11:11:25 +08:00
&.is-checked.is-disabled {
.slider:before {
color: var(--Switch-onDisabled-color);
}
.text {
color: var(--Switch-onDisabled-color);
2019-04-30 11:11:25 +08:00
}
2019-12-06 09:58:08 +08:00
}
input {
position: absolute;
opacity: 0;
}
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;
}
}