index.less 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. @import "../styles/mixins/index.less";
  2. @import "../styles/themes/index.less";
  3. @switch-handle-height: @switch-height - 1px * 2;
  4. @switch-spin-height: @switch-handle-height / 2;
  5. @switch-spin-marign: (@switch-handle-height - @switch-spin-height) / 2;
  6. .switch-style(@theme, @color) {
  7. &--@{theme} &__spin {
  8. .encoded-svg-background(spin, @color);
  9. }
  10. }
  11. .@{wux-prefix}-switch {
  12. display: inline-block;
  13. vertical-align: middle;
  14. box-sizing: border-box;
  15. position: relative;
  16. align-self: center;
  17. cursor: pointer;
  18. &__input {
  19. position: relative;
  20. min-width: 52px;
  21. height: @switch-height;
  22. border: 1px solid @switch-bg;
  23. outline: 0;
  24. border-radius: @switch-height / 2;
  25. box-sizing: border-box;
  26. background-color: @switch-bg;
  27. transition: background-color 0.1s, border 0.1s;
  28. &::before {
  29. content: " ";
  30. position: absolute;
  31. top: 0;
  32. left: 0;
  33. width: 100%;
  34. height: @switch-handle-height;
  35. border-radius: @switch-handle-height / 2;
  36. background-color: #FDFDFD;
  37. transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1);
  38. }
  39. &::after {
  40. content: " ";
  41. position: absolute;
  42. top: 0;
  43. left: 0;
  44. width: @switch-handle-height;
  45. height: @switch-handle-height;
  46. border-radius: @switch-handle-height / 2;
  47. background-color: #FFF;
  48. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  49. // transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
  50. transition: left 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
  51. }
  52. &--checked {
  53. border-color: @switch-color;
  54. background-color: @switch-color;
  55. &::before {
  56. transform: scale(0);
  57. }
  58. &::after {
  59. // transform: translateX(20px);
  60. left: calc(~"100% - 30px - 1px / 2");
  61. }
  62. }
  63. &--disabled {
  64. opacity: @disabled-opacity;
  65. }
  66. }
  67. &__text {
  68. position: relative;
  69. z-index: 10;
  70. display: flex;
  71. justify-content: center;
  72. align-items: center;
  73. height: 100%;
  74. transition: margin .2s;
  75. margin: 0 8px 0 calc(@switch-height - 1px + 4px);
  76. }
  77. &--checked &__text {
  78. color: @text-color-inverse;
  79. margin: 0 calc(@switch-height - 1px + 5px) 0 10px;
  80. }
  81. &__spin {
  82. position: absolute;
  83. left: @switch-spin-marign;
  84. top: @switch-spin-marign;
  85. z-index: 10;
  86. width: @switch-spin-height;
  87. height: @switch-spin-height;
  88. background-size: contain;
  89. animation: switch-spin-rotate 1s linear infinite;
  90. .encoded-svg-background(spin, @switch-color);
  91. }
  92. &--checked &__spin {
  93. left: unset;
  94. right: @switch-spin-marign;
  95. }
  96. .switch-style(light, @light);
  97. .switch-style(stable, @stable);
  98. .switch-style(positive, @positive);
  99. .switch-style(calm, @calm);
  100. .switch-style(assertive, @assertive);
  101. .switch-style(balanced, @balanced);
  102. .switch-style(energized, @energized);
  103. .switch-style(royal, @royal);
  104. .switch-style(dark, @dark);
  105. }
  106. @keyframes switch-spin-rotate {
  107. to {
  108. transform: rotate(1turn);
  109. }
  110. }