switch.less 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. @switch-circle-diameter: 16px;
  2. @switch-inner-padding: 2px;
  3. @switch-width: 34px;
  4. @switch-height: @switch-circle-diameter + @switch-inner-padding +
  5. @switch-inner-padding;
  6. @switch-circle-translate-x: @switch-width - @switch-circle-diameter -
  7. @switch-inner-padding - @switch-inner-padding;
  8. @switch-circle-wrapper-border-radius: @switch-height / 2;
  9. @switch-transition: 0.4s;
  10. .switch-input {
  11. position: relative;
  12. display: inline-block;
  13. width: @switch-width;
  14. height: @switch-height;
  15. input.invisible-input {
  16. opacity: 0;
  17. width: 0;
  18. height: 0;
  19. // span.switch -> circle "wrapper"
  20. & + span.switch {
  21. background-color: @ol-blue-gray-4;
  22. position: absolute;
  23. cursor: pointer;
  24. top: 0;
  25. left: 0;
  26. right: 0;
  27. bottom: 0;
  28. transition: @switch-transition;
  29. border-radius: @switch-circle-wrapper-border-radius;
  30. }
  31. // span.switch::before is the circle itself
  32. & + span.switch::before {
  33. position: absolute;
  34. content: '';
  35. height: @switch-circle-diameter;
  36. width: @switch-circle-diameter;
  37. left: @switch-inner-padding;
  38. bottom: @switch-inner-padding;
  39. background-color: @white;
  40. transition: @switch-transition;
  41. border-radius: 50%;
  42. }
  43. &:checked + span.switch {
  44. background-color: @ol-green;
  45. }
  46. // when input is checked, move circle to the right
  47. &:checked + span.switch::before {
  48. transform: translateX(@switch-circle-translate-x);
  49. }
  50. }
  51. &.disabled {
  52. input.invisible-input + span.switch {
  53. background-color: @gray-light;
  54. }
  55. }
  56. }