switch.scss 7.8 KB

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