switch.scss 7.7 KB

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