index.less 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. @import './var.less';
  2. :root {
  3. --van-switch-size: @switch-size;
  4. --van-switch-width: @switch-width;
  5. --van-switch-height: @switch-height;
  6. --van-switch-node-size: @switch-node-size;
  7. --van-switch-node-background-color: @switch-node-background-color;
  8. --van-switch-node-box-shadow: @switch-node-box-shadow;
  9. --van-switch-background-color: @switch-background-color;
  10. --van-switch-on-background-color: @switch-on-background-color;
  11. --van-switch-transition-duration: @switch-transition-duration;
  12. --van-switch-disabled-opacity: @switch-disabled-opacity;
  13. --van-switch-border: @switch-border;
  14. }
  15. .van-switch {
  16. position: relative;
  17. display: inline-block;
  18. box-sizing: content-box;
  19. width: var(--van-switch-width);
  20. height: var(--van-switch-height);
  21. font-size: var(--van-switch-size);
  22. background: var(--van-switch-background-color);
  23. border: var(--van-switch-border);
  24. border-radius: var(--van-switch-node-size);
  25. cursor: pointer;
  26. transition: background-color var(--van-switch-transition-duration);
  27. &__node {
  28. position: absolute;
  29. top: 0;
  30. left: 0;
  31. width: var(--van-switch-node-size);
  32. height: var(--van-switch-node-size);
  33. // https://github.com/vant-ui/vant/issues/9839
  34. font-size: inherit;
  35. background: var(--van-switch-node-background-color);
  36. border-radius: 100%;
  37. box-shadow: var(--van-switch-node-box-shadow);
  38. transition: transform var(--van-switch-transition-duration)
  39. cubic-bezier(0.3, 1.05, 0.4, 1.05);
  40. }
  41. &__loading {
  42. top: 25%;
  43. left: 25%;
  44. width: 50%;
  45. height: 50%;
  46. line-height: 1;
  47. }
  48. &--on {
  49. background: var(--van-switch-on-background-color);
  50. .van-switch__node {
  51. transform: translateX(
  52. calc(var(--van-switch-width) - var(--van-switch-node-size))
  53. );
  54. }
  55. .van-switch__loading {
  56. color: var(--van-switch-on-background-color);
  57. }
  58. }
  59. &--disabled {
  60. cursor: not-allowed;
  61. opacity: var(--van-switch-disabled-opacity);
  62. }
  63. &--loading {
  64. cursor: default;
  65. }
  66. }