index.less 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. @import '../../style/themes/index';
  2. @import '../../style/mixins/index';
  3. @switch-prefix-cls: ~'@{ant-prefix}-switch';
  4. @switch-duration: 0.2s;
  5. @switch-pin-size: @switch-height - 4px;
  6. @switch-sm-pin-size: @switch-sm-height - 4px;
  7. .@{switch-prefix-cls} {
  8. .reset-component();
  9. position: relative;
  10. display: inline-block;
  11. box-sizing: border-box;
  12. min-width: @switch-min-width;
  13. height: @switch-height;
  14. line-height: @switch-height;
  15. vertical-align: middle;
  16. background-color: @disabled-color;
  17. border: 0;
  18. border-radius: 100px;
  19. cursor: pointer;
  20. transition: all @switch-duration;
  21. user-select: none;
  22. &:focus {
  23. outline: 0;
  24. box-shadow: 0 0 0 2px fade(@disabled-color, 10%);
  25. }
  26. &-checked:focus {
  27. box-shadow: 0 0 0 2px @primary-1;
  28. }
  29. &:focus:hover {
  30. box-shadow: none;
  31. }
  32. &-checked {
  33. background-color: @switch-color;
  34. }
  35. &-loading,
  36. &-disabled {
  37. cursor: not-allowed;
  38. opacity: @switch-disabled-opacity;
  39. * {
  40. box-shadow: none;
  41. cursor: not-allowed;
  42. }
  43. }
  44. // ========================= Inner ==========================
  45. &-inner {
  46. display: block;
  47. margin: 0 @switch-inner-margin-min 0 @switch-inner-margin-max;
  48. color: @text-color-inverse;
  49. font-size: @font-size-sm;
  50. transition: margin @switch-duration;
  51. }
  52. &-checked &-inner {
  53. margin: 0 @switch-inner-margin-max 0 @switch-inner-margin-min;
  54. }
  55. // ========================= Handle =========================
  56. &-handle {
  57. position: absolute;
  58. top: @switch-padding;
  59. left: @switch-padding;
  60. width: @switch-pin-size;
  61. height: @switch-pin-size;
  62. transition: all @switch-duration ease-in-out;
  63. &::before {
  64. position: absolute;
  65. top: 0;
  66. right: 0;
  67. bottom: 0;
  68. left: 0;
  69. background-color: @switch-bg;
  70. border-radius: (@switch-pin-size / 2);
  71. box-shadow: 0 2px 4px 0 @switch-shadow-color;
  72. transition: all @switch-duration ease-in-out;
  73. content: '';
  74. }
  75. }
  76. &-checked &-handle {
  77. left: calc(100% - @switch-pin-size - @switch-padding);
  78. }
  79. &:not(&-disabled):active {
  80. .@{switch-prefix-cls}-handle::before {
  81. right: -30%;
  82. left: 0;
  83. }
  84. &.@{switch-prefix-cls}-checked {
  85. .@{switch-prefix-cls}-handle::before {
  86. right: 0;
  87. left: -30%;
  88. }
  89. }
  90. }
  91. // ======================== Loading =========================
  92. &-loading-icon.@{iconfont-css-prefix} {
  93. position: relative;
  94. top: ((@switch-pin-size - @font-size-base) / 2);
  95. color: rgba(0, 0, 0, 0.65);
  96. vertical-align: top;
  97. }
  98. &-checked &-loading-icon {
  99. color: @switch-color;
  100. }
  101. // ========================== Size ==========================
  102. &-small {
  103. min-width: @switch-sm-min-width;
  104. height: @switch-sm-height;
  105. line-height: @switch-sm-height;
  106. .@{switch-prefix-cls}-inner {
  107. margin: 0 @switch-sm-inner-margin-min 0 @switch-sm-inner-margin-max;
  108. font-size: @font-size-sm;
  109. }
  110. .@{switch-prefix-cls}-handle {
  111. width: @switch-sm-pin-size;
  112. height: @switch-sm-pin-size;
  113. }
  114. .@{switch-prefix-cls}-loading-icon {
  115. top: ((@switch-sm-pin-size - 9px) / 2);
  116. font-size: 9px;
  117. }
  118. &.@{switch-prefix-cls}-checked {
  119. .@{switch-prefix-cls}-inner {
  120. margin: 0 @switch-sm-inner-margin-max 0 @switch-sm-inner-margin-min;
  121. }
  122. .@{switch-prefix-cls}-handle {
  123. left: calc(100% - @switch-sm-pin-size - @switch-padding);
  124. }
  125. }
  126. }
  127. }
  128. @import './rtl';