123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- @use 'sass:math';
- $switch-width: 36px;
- $switch-height: 18px;
- $switch-border: 2px;
- $switch-outline: 3px;
- $switch-border-radius: math.div(($switch-height + $switch-border * 2), 2);
- .switch {
- display: inline-flex;
- align-items: center;
- margin: 5px 0;
- position: relative;
-
- width: unset;
- float: unset;
- &__tick {
- width: 12px;
- height: $switch-height;
- position: absolute;
- top: 50%;
- transform: translate(5px, -50%);
- color: $color-white;
- @media (forced-colors: active) {
- color: SelectedItemText;
- }
- }
- &__toggle {
- position: relative;
- cursor: pointer;
- &::before,
- &::after {
- content: '';
- transition: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
- display: block;
- }
- &::before {
- height: $switch-height + $switch-border * 2;
- width: $switch-width + $switch-border * 2;
- border-radius: $switch-border-radius;
- background: theme('colors.grey.400');
- border: $switch-border solid theme('colors.grey.400');
- }
- &::after {
- box-sizing: border-box;
- position: absolute;
- top: 50%;
- transform: translate($switch-border, -50%);
- height: $switch-height;
- width: $switch-height;
- border: $switch-border solid $color-white;
- border-radius: theme('borderRadius.full');
- background-color: $color-white;
- }
- }
- [type='checkbox']:checked + &__toggle::before {
- background: $color-teal;
- border-color: $color-teal;
- @media (forced-colors: active) {
- background: SelectedItem;
- border-color: SelectedItem;
- }
- }
- [type='checkbox']:checked + &__toggle::after {
- transform: translate(calc(#{$switch-width + $switch-border} - 100%), -50%);
- }
- [type='checkbox']:disabled + &__toggle {
- cursor: not-allowed;
- filter: grayscale(100%);
- opacity: 0.3;
- }
- [type='checkbox']:focus + &__toggle {
- outline: $color-focus-outline solid $switch-outline;
- }
- [type='checkbox'] {
- position: absolute;
- opacity: 0;
- pointer-events: none;
- width: 100%;
- height: 100%;
- }
- }
|