@use 'sass:map';
@keyframes switch-focus {
0% {
box-shadow: 0 0 0 8px rgb(var(--#{$rd-prefix}color-primary-rgb) / var(--#{$rd-prefix}shadow-normal));
}
100% {
box-shadow: 0 0 0 10px rgb(var(--#{$rd-prefix}color-primary-rgb) / var(--#{$rd-prefix}shadow-darker));
}
}
@include b(switch) {
@include polyfill-column-gap(8px);
position: relative;
display: inline-flex;
align-items: center;
&:active {
@include e(state-dot) {
width: 22px;
}
}
@include when(disabled) {
color: var(--#{$rd-prefix}color-disabled);
pointer-events: none;
filter: brightness(110%) grayscale(50%);
@include when(checked) {
filter: saturate(50%) grayscale(50%);
}
@include e(state-dot) {
filter: opacity(50%);
}
}
@include when(loading) {
pointer-events: none;
filter: opacity(70%);
}
@include when(checked) {
@include e(state-container) {
background-color: var(--#{$rd-prefix}color-primary);
}
}
@include e(input) {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 5;
width: 100%;
height: 100%;
margin: 0;
cursor: pointer;
opacity: 0;
appearance: none;
}
@include e(state-container) {
position: relative;
display: inline-flex;
flex-shrink: 0;
align-items: center;
min-width: 42px;
height: 22px;
padding: 0 6px;
background-color: var(--#{$rd-prefix}switch-background-color);
border-radius: 11px;
transition: background-color var(--#{$rd-prefix}animation-duration-fast) ease-out;
}
@include e(state-content) {
display: inline-flex;
justify-content: center;
min-width: 1em;
font-size: 14px;
line-height: 1;
color: map.get($rd-colors, 'white');
transition: opacity var(--#{$rd-prefix}animation-duration-fast) ease-out;
@include m(left) {
margin-right: auto;
}
}
@include e(state-dot) {
position: absolute;
top: 2px;
z-index: 1;
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
font-size: 14px;
color: var(--#{$rd-prefix}color-primary);
background-color: var(--#{$rd-prefix}background-color);
border-radius: 9px;
box-shadow: 0 2px 1px -1px var(--#{$rd-prefix}shadow-color), 0 0 4px 0 var(--#{$rd-prefix}shadow-color);
transition: width var(--#{$rd-prefix}animation-duration-fast) ease-in;
@include when(focus) {
animation: switch-focus 1.2s linear infinite alternate;
animation-fill-mode: both;
}
}
}