_switch.scss 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. @use 'sass:math';
  2. $switch-width: 36px;
  3. $switch-height: 18px;
  4. $switch-border: 2px;
  5. $switch-outline: 3px;
  6. $switch-border-radius: math.div(($switch-height + $switch-border * 2), 2);
  7. .switch {
  8. display: inline-flex;
  9. align-items: center;
  10. margin: 5px 0;
  11. position: relative;
  12. // Disable forms styling that's applied to the <label> tag
  13. width: unset;
  14. float: unset;
  15. &__tick {
  16. width: 12px;
  17. height: $switch-height;
  18. position: absolute;
  19. top: 50%;
  20. transform: translate(5px, -50%);
  21. color: $color-white;
  22. @media (forced-colors: active) {
  23. color: SelectedItemText;
  24. }
  25. }
  26. &__toggle {
  27. position: relative;
  28. cursor: pointer;
  29. &::before,
  30. &::after {
  31. content: '';
  32. transition: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
  33. display: block;
  34. }
  35. &::before {
  36. height: $switch-height + $switch-border * 2;
  37. width: $switch-width + $switch-border * 2;
  38. border-radius: $switch-border-radius;
  39. background: theme('colors.grey.400');
  40. border: $switch-border solid theme('colors.grey.400');
  41. }
  42. &::after {
  43. position: absolute;
  44. top: 50%;
  45. transform: translate($switch-border, -50%);
  46. height: $switch-height;
  47. width: $switch-height;
  48. border: $switch-border solid $color-white;
  49. border-radius: theme('borderRadius.full');
  50. background-color: $color-white;
  51. }
  52. }
  53. [type='checkbox']:checked + &__toggle::before {
  54. background: $color-teal;
  55. border-color: $color-teal;
  56. @media (forced-colors: active) {
  57. background: SelectedItem;
  58. border-color: SelectedItem;
  59. }
  60. }
  61. [type='checkbox']:checked + &__toggle::after {
  62. transform: translate(calc(#{$switch-width + $switch-border} - 100%), -50%);
  63. }
  64. [type='checkbox']:disabled + &__toggle {
  65. cursor: not-allowed;
  66. filter: grayscale(100%);
  67. opacity: 0.3;
  68. }
  69. [type='checkbox']:focus + &__toggle {
  70. outline: $color-focus-outline solid $switch-outline;
  71. }
  72. [type='checkbox'] {
  73. position: absolute;
  74. opacity: 0;
  75. pointer-events: none;
  76. width: 100%;
  77. height: 100%;
  78. }
  79. }