switch.scss 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. @import './variables.scss';
  2. $module: #{$prefix}-switch;
  3. .#{$module} {
  4. box-sizing: border-box;
  5. display: inline-block;
  6. border-radius: $radius-switch;
  7. border: $border-thickness-control $color-switch_default-border-default solid;
  8. position: relative;
  9. cursor: pointer;
  10. background-color: $color-switch_default-bg-default;
  11. // box-shadow: inset 0 0 0 0 $color-switch_default-bg-success;
  12. transition: background-color $motion-switch-transitionDuration ease-in-out;
  13. width: $width-switch;
  14. height: $height-switch;
  15. &:hover {
  16. background-color: $color-switch_default-bg-hover;
  17. }
  18. &:active {
  19. border: $border-thickness-control $color-switch_default-bg-active solid;
  20. .#{$module}-knob {
  21. // width: $knob-size + $knob-active-expand;
  22. width: $width-switch_knob_active;
  23. }
  24. }
  25. &-checked {
  26. background-color: $color-switch_checked-bg-default;
  27. &:hover {
  28. background-color: $color-switch_checked-bg-hover;
  29. }
  30. .#{$module}-knob {
  31. transform: translateX($motion-switch_checked-translateX);
  32. }
  33. &:active {
  34. .#{$module}-knob {
  35. transform: translateX($motion-switch_checked-translateX - $width-switch_knob_expand);
  36. }
  37. }
  38. }
  39. &-active {
  40. background-color: $color-switch_checked-bg-active;
  41. }
  42. &-disabled {
  43. cursor: not-allowed;
  44. background-color: $color-switch_disabled-bg-default;
  45. border: $border-thickness-control $color-switch_disabled-border-default solid;
  46. &:hover {
  47. background-color: $color-switch_disabled-bg-hover;
  48. }
  49. &:active {
  50. background-color: $color-switch_disabled-bg-active;
  51. }
  52. .#{$module}-knob {
  53. cursor: not-allowed;
  54. @include shadow-0;
  55. border: $width-switch_knob_disabled-border $color-switch_knob-border-default solid;
  56. }
  57. &.#{$module}-checked {
  58. border-color: $color-switch_checked_disabled-border-default;
  59. background-color: $color-switch_checked_disabled-bg-default;
  60. .#{$module}-knob {
  61. @include shadow-0;
  62. border: none;
  63. }
  64. }
  65. }
  66. &-knob {
  67. @include shadow-knob;
  68. cursor: pointer;
  69. border-radius: $width-switch_knob_default / 2;
  70. background-color: $color-switch_knob-bg-default;
  71. box-sizing: border-box;
  72. position: absolute;
  73. left: 0;
  74. right: auto;
  75. transition: transform $motion-switch-transitionDuration ease-in-out, width $motion-switch-transitionDuration ease-in-out;
  76. width: $width-switch_knob_default;
  77. height: $width-switch_knob_default;
  78. top: $spacing-switch_knob-padding;
  79. transform: translateX($motion-switch_unchecked-translateX);
  80. }
  81. &-native-control {
  82. &[type="checkbox"] {
  83. width: 100%;
  84. height: 100%;
  85. }
  86. width: 100%;
  87. height: 100%;
  88. opacity: 0;
  89. cursor: inherit;
  90. pointer-events: auto;
  91. margin: 0; // 消除ua样式影响
  92. position: absolute;
  93. top: 0;
  94. left: 0;
  95. }
  96. &-checked-text,
  97. &-unchecked-text {
  98. position: absolute;
  99. font-size: $font-size-small;
  100. height: 100%;
  101. width: 20px;
  102. @include all-center;
  103. }
  104. &-checked-text {
  105. color: $color-switch_checked-text-default;
  106. }
  107. &-unchecked-text {
  108. color: $color-switch_unchecked-text-default;
  109. right: 0;
  110. }
  111. &-loading {
  112. display: inline-flex;
  113. align-items: center;
  114. background-color: $color-switch_spin_unchecked-bg-default;
  115. &-spin {
  116. .#{$prefix}-spin-wrapper{
  117. display: inline-flex;
  118. align-items: center;
  119. color: $color-switch_loading_spin-default;
  120. }
  121. }
  122. }
  123. }
  124. .#{$module}-loading {
  125. .#{$module}-loading-spin {
  126. transform: translateX($motion-switch_spin_unchecked-translateX);
  127. &>.#{$prefix}-spin-wrapper>svg{
  128. width: $width-switch_spin-default;
  129. height: $width-switch_spin-default;
  130. }
  131. }
  132. &.#{$module}-checked {
  133. background-color: $color-switch_spin_checked-bg-default;
  134. .#{$module}-loading-spin {
  135. transform: translateX($motion-switch_spin_checked-translateX);
  136. }
  137. }
  138. }
  139. .#{$module}-loading.#{$module}-small {
  140. .#{$module}-loading-spin {
  141. transform: translateX($motion-switch_spin_unchecked_small-translateX);
  142. &>.#{$prefix}-spin-wrapper>svg{
  143. width: $width-switch_spin-small;
  144. height: $width-switch_spin-small;
  145. }
  146. }
  147. &.#{$module}-checked{
  148. .#{$module}-loading-spin {
  149. transform: translateX($motion-switch_spin_checked_small-translateX);
  150. }
  151. }
  152. }
  153. .#{$module}-loading.#{$module}-large {
  154. .#{$module}-loading-spin {
  155. transform: translateX($motion-switch_spin_unchecked_large-translateX);
  156. &>.#{$prefix}-spin-wrapper>svg{
  157. width: $width-switch_spin-large;
  158. height: $width-switch_spin-large;
  159. }
  160. }
  161. &.#{$module}-checked {
  162. .#{$module}-loading-spin {
  163. transform: translateX($motion-switch_spin_checked_large-translateX);
  164. }
  165. }
  166. }
  167. .#{$module}-disabled.#{$module}-checked {
  168. background-color: $color-switch_checked_disabled-bg-default;
  169. }
  170. .#{$module}-large {
  171. width: $width-switch_large;
  172. height: $height-switch_large;
  173. border-radius: $radius-switch_large;
  174. .#{$module}-knob {
  175. width: $width-switch_knob_large;
  176. height: $width-switch_knob_large;
  177. top: $spacing-switch_knob_large-padding;
  178. border-radius: $width-switch_knob_large / 2;
  179. transform: translateX($motion-switch_unchecked_large-translateX);
  180. }
  181. &.#{$module}-checked {
  182. .#{$module}-knob {
  183. transform: translateX($motion-switch_checked_large-translateX);
  184. }
  185. &:active {
  186. .#{$module}-knob {
  187. transform: translateX($motion-switch_checked_large-translateX - $motion-switch_expand_large-translateX);
  188. }
  189. }
  190. }
  191. &:active {
  192. .#{$module}-knob {
  193. width: $width-switch_knob_large_active;
  194. }
  195. }
  196. .#{$module}-checked-text,
  197. .#{$module}-unchecked-text {
  198. width: $width-switch_checked_unchecked_text;
  199. font-size: $font-size-regular;
  200. }
  201. }
  202. .#{$module}-small {
  203. width: $width-switch_small;
  204. height: $height-switch_small;
  205. border-radius: $radius-switch_small;
  206. .#{$module}-knob {
  207. width: $width-switch_knob_large_small;
  208. height: $width-switch_knob_large_small;
  209. top: $spacing-switch_knob_small-padding;
  210. border-radius: $width-switch_knob_large_small / 2;
  211. transform: translateX($motion-switch_unchecked_small-translateX);
  212. }
  213. &.#{$module}-checked {
  214. .#{$module}-knob {
  215. transform: translateX($motion-switch_checked_small-translateX);
  216. }
  217. &:active {
  218. .#{$module}-knob {
  219. transform: translateX($motion-switch_checked_small-translateX - $motion-switch_expand_small-translateX);
  220. }
  221. }
  222. }
  223. &:active {
  224. .#{$module}-knob {
  225. width: $width-switch_knob_small_active;
  226. }
  227. }
  228. }
  229. .#{$prefix}-form {
  230. .#{$prefix}-switch-native-control {
  231. width: 100%;
  232. height: 100%;
  233. }
  234. }
  235. @import './rtl.scss';