1
0

switch.scss 7.6 KB

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