checkbox.scss 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //@import '../theme/variables.scss';
  2. // @import '../theme/mixin.scss';
  3. @import "./variables.scss";
  4. @import "./mixin.scss";
  5. $module: #{$prefix}-checkbox;
  6. .#{$module} {
  7. @include box-sizing;
  8. // box-sizing: border-box;
  9. position: relative;
  10. display: flex;
  11. align-items: center;
  12. flex-wrap: wrap;
  13. @include font-size-regular;
  14. cursor: pointer;
  15. transition: background-color $transition_duration-checkbox-bg $transition_function-checkbox-bg $transition_delay-checkbox-bg,
  16. border $transition_duration-checkbox-border $transition_function_checkbox-border $transition_delay-checkbox-border;
  17. transform: scale($transform_scale-checkbox);
  18. input[type="checkbox"] {
  19. position: absolute;
  20. left: 0;
  21. top: 0;
  22. width: 100%;
  23. height: 100%;
  24. margin: 0;
  25. opacity: 0;
  26. }
  27. &-addon {
  28. display: flex;
  29. flex: 1;
  30. align-items: center;
  31. padding-left: $spacing-checkbox_label-paddingLeft;
  32. color: $color-checkbox_label-text-default;
  33. line-height: $font-checkbox_label-lineHeight;
  34. user-select: none;
  35. }
  36. &:hover {
  37. .#{$module}-inner-display {
  38. background: $color-checkbox_default-bg-hover;
  39. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_default-border-hover;
  40. }
  41. .#{$module}-inner-checked {
  42. .#{$module}-inner-display {
  43. background: $color-checkbox_checked-bg-hover;
  44. box-shadow: none;
  45. }
  46. }
  47. }
  48. &:active {
  49. .#{$module}-inner-display {
  50. background: $color-checkbox_default-bg-active;
  51. }
  52. .#{$module}-inner-checked {
  53. .#{$module}-inner-display {
  54. background: $color-checkbox_checked-bg-active;
  55. box-shadow: none;
  56. }
  57. }
  58. }
  59. &.#{$module}-disabled:hover,
  60. &.#{$module}-disabled:active {
  61. .#{$module}-inner-display {
  62. background: $color-checkbox_disabled-bg-default;
  63. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_disabled-border-default;
  64. }
  65. .#{$module}-inner-checked {
  66. .#{$module}-inner-display {
  67. background: $color-checkbox_checked-bg-disabled;
  68. box-shadow: none;
  69. }
  70. }
  71. }
  72. &-inner {
  73. position: relative;
  74. display: flex;
  75. align-items: center;
  76. width: $width-checkbox_inner;
  77. height: $height-checkbox_inner;
  78. user-select: none; // prevent text under it will be selected when double click
  79. cursor: pointer;
  80. transition: background-color $transition_duration-checkbox-bg $transition_function-checkbox-bg $transition_delay-checkbox-bg,
  81. border $transition_duration-checkbox-border $transition_function-checkbox-border $transition_delay-checkbox-border;
  82. &-display {
  83. @include box-sizing;
  84. position: relative;
  85. width: $width-checkbox_inner;
  86. height: $width-checkbox_inner;
  87. margin: 0;
  88. background: $color-checkbox_default-bg-default;
  89. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_default-border-default;
  90. border-radius: $radius-checkbox_inner;
  91. .#{$prefix}-icon {
  92. font-size: 16px;
  93. }
  94. }
  95. }
  96. &-inner-checked {
  97. .#{$module}-inner-display {
  98. background: $color-checkbox_checked-bg-default;
  99. color: $color-checkbox_checked-icon-default;
  100. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_checked-border-default;
  101. border-radius: $radius-checkbox_inner;
  102. }
  103. & > .#{$module}-addon {
  104. color: $color-checkbox_label-text-default;
  105. }
  106. }
  107. &:hover {
  108. .#{$module}-inner-display {
  109. background: $color-checkbox_default-bg-hover;
  110. }
  111. &.#{$module}-indeterminate .#{$module}-inner-display {
  112. background: $color-checkbox_checked-bg-hover;
  113. box-shadow: none;
  114. color: $color-checkbox_checked-icon-hover;
  115. }
  116. .#{$module}-inner-checked {
  117. .#{$module}-inner-display {
  118. background: $color-checkbox_checked-bg-hover;
  119. border-color: $color-checkbox_checked-border-hover;
  120. color: $color-checkbox_checked-icon-hover;
  121. }
  122. }
  123. &.#{$module}-cardType.#{$module}-unChecked.#{$module}-cardType_unDisabled {
  124. .#{$module}-inner-display {
  125. background: $color-checkbox_cardType_inner-bg-hover;
  126. }
  127. }
  128. }
  129. &:active {
  130. .#{$module}-inner-display {
  131. background: $color-checkbox_default-bg-active;
  132. }
  133. &.#{$module}-indeterminate .#{$module}-inner-display {
  134. background: $color-checkbox_checked-bg-active;
  135. border-color: $color-checkbox_checked-border-active;
  136. color: $color-checkbox_checked-icon-active;
  137. box-shadow: none;
  138. }
  139. .#{$module}-inner-checked {
  140. .#{$module}-inner-display {
  141. background: $color-checkbox_checked-bg-active;
  142. border-color: $color-checkbox_checked-border-active;
  143. color: $color-checkbox_checked-icon-active;
  144. }
  145. }
  146. &.#{$module}-cardType.#{$module}-unChecked.#{$module}-cardType_unDisabled {
  147. .#{$module}-inner-display {
  148. background: $color-checkbox_cardType_inner-bg-active;
  149. }
  150. }
  151. }
  152. &-cardType {
  153. flex-wrap: nowrap;
  154. align-items: flex-start;
  155. border-radius: $radius-checkbox_cardType;
  156. padding: $spacing-checkbox_cardType-paddingY $spacing-checkbox_cardType-paddingX;
  157. background: transparent;
  158. border: $width-checkbox_cardType_checked-border solid transparent;
  159. .#{$module}-inner {
  160. position: relative;
  161. &-display {
  162. background: $color-checkbox_cardType_inner-bg-default;
  163. }
  164. margin-right: $spacing-checkbox_cardType_inner-marginRight;
  165. flex-shrink: 0;
  166. }
  167. .#{$module}-inner-pureCardType {
  168. // Reasons to use opacity:0 & width: 0 instead of display: none
  169. // The a11y keyboard focus event of the checkbox depends on the implementation of the input focus/blur event
  170. // input focus/blur cannot take effect when display: none
  171. opacity: 0;
  172. width: 0;
  173. margin-right: 0;
  174. }
  175. .#{$module}-addon {
  176. font-weight: $font-checkbox_cardType_addon-fontWeight;
  177. font-size: $font-checkbox_cardType_addon-size;
  178. line-height: $font-checkbox_cardType_addon-lineHeight;
  179. color: $color-checkbox_cardType_addon-text-default;
  180. margin-left: 0;
  181. padding-left: 0;
  182. }
  183. .#{$module}-extra {
  184. font-weight: $font-checkbox_cardType_extra-fontWeight;
  185. font-size: $font-checkbox_cardType_extra-size;
  186. line-height: $font-checkbox_cardType_extra-lineHeight;
  187. color: $color-checkbox_cardType_extra-text-default;
  188. padding-left: 0;
  189. &.#{$module}-cardType_extra_noChildren {
  190. margin-top: 0;
  191. }
  192. }
  193. &:hover {
  194. background: $color-checkbox_cardType-bg-hover;
  195. }
  196. &:active {
  197. background: $color-checkbox_cardType-bg-active;
  198. }
  199. &_checked {
  200. background: $color-checkbox_cardType_checked-bg;
  201. border: $width-checkbox_cardType_checked-border solid $color-checkbox_cardType_checked_border-default;
  202. &:hover {
  203. background: $color-checkbox_cardType_checked-bg;
  204. border-color: $color-checkbox_cardType_checked_border-hover;
  205. .#{$module}-inner-checked .#{$module}-inner-display {
  206. box-shadow: none;
  207. }
  208. }
  209. &:active {
  210. background: $color-checkbox_cardType_checked-bg;
  211. border-color: $color-checkbox_cardType_checked_border-active;
  212. }
  213. }
  214. &_disabled {
  215. &:active {
  216. background: transparent;
  217. }
  218. &:hover {
  219. background: transparent;
  220. }
  221. }
  222. &_checked_disabled.#{$module}-cardType {
  223. background: $color-checkbox_cardType_checked_disabled-bg;
  224. border: $width-checkbox_cardType_checked_disabled-border solid $color-checkbox_cardType_checked_disabled_border-default;
  225. &:hover {
  226. .#{$module}-inner-checked .#{$module}-inner-display {
  227. box-shadow: none;
  228. }
  229. }
  230. }
  231. }
  232. &-indeterminate,
  233. &-checked {
  234. .#{$module}-inner {
  235. &-display {
  236. background: $color-checkbox_checked-bg-default;
  237. color: $color-checkbox_checked-icon-default;
  238. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_checked-border-default;
  239. border-radius: $radius-checkbox_inner;
  240. &:hover {
  241. background: $color-checkbox_checked-bg-hover;
  242. border-color: $color-checkbox_checked-border-hover;
  243. color: $color-checkbox_checked-icon-hover;
  244. }
  245. &:active {
  246. background: $color-checkbox_checked-bg-active;
  247. border-color: $color-checkbox_checked-border-active;
  248. color: $color-checkbox_checked-icon-active;
  249. }
  250. }
  251. &-addon {
  252. color: $color-checkbox_label-text-default;
  253. }
  254. }
  255. }
  256. &-disabled {
  257. cursor: not-allowed;
  258. .#{$module}-inner {
  259. cursor: not-allowed;
  260. &-display {
  261. color: $color-checkbox_checked-icon-disabled;
  262. background: $color-checkbox_disabled-bg-default;
  263. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_disabled-border-default;
  264. &:hover {
  265. color: $color-checkbox_checked-icon-disabled;
  266. background: transparent;
  267. }
  268. }
  269. &-checked {
  270. color: $color-checkbox_checked-icon-disabled;
  271. .#{$module}-inner-display {
  272. opacity: 0.75;
  273. background: $color-checkbox_checked-bg-disabled;
  274. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_checked-bg-disabled;
  275. &:hover {
  276. color: $color-checkbox_checked-icon-disabled;
  277. background: $color-checkbox_checked-bg-disabled;
  278. }
  279. }
  280. }
  281. }
  282. .#{$module}-addon {
  283. color: $color-checkbox_label-text-disabled;
  284. }
  285. .#{$module}-extra {
  286. color: $color-checkbox_label-text-disabled;
  287. }
  288. }
  289. &.#{$module}-disabled.#{$module}-indeterminate .#{$module}-inner-display {
  290. opacity: 0.75;
  291. background: $color-checkbox_checked-bg-disabled;
  292. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_checked-bg-disabled;
  293. color: $color-checkbox_checked-icon-disabled;
  294. }
  295. &-extra {
  296. flex-shrink: 0;
  297. flex-grow: 1;
  298. flex-basis: 100%;
  299. box-sizing: border-box;
  300. padding-left: $spacing-checkbox_extra-paddingLeft;
  301. color: $color-checkbox_extra-text-default;
  302. margin-top: $spacing-checkbox_extra-marginTop;
  303. }
  304. &-focus {
  305. outline: $width-checkbox-outline solid $color-checkbox_primary-outline-focus;
  306. &-border {
  307. box-shadow: inset 0 0 0 $size-checkbox_inner-shadow $color-checkbox_default-border-hover;
  308. }
  309. }
  310. }
  311. .#{$module}Group {
  312. @include font-size-regular;
  313. // make sure group height 32px
  314. line-height: $font-size-regular;
  315. .#{$module} {
  316. &.#{$module}-vertical {
  317. margin-bottom: $spacing-checkbox_group_vertical-marginBottom;
  318. }
  319. }
  320. &-horizontal {
  321. .#{$module} {
  322. margin-right: $spacing-checkbox_group_horizontal-marginRight;
  323. display: inline-flex;
  324. &:last-of-type {
  325. margin-right: 0;
  326. }
  327. }
  328. }
  329. &-vertical {
  330. .#{$module} {
  331. margin-bottom: $spacing-checkbox_group_vertical_item-marginBottom;
  332. &:last-of-type {
  333. margin-bottom: 0;
  334. }
  335. }
  336. &-cardType {
  337. .#{$module} {
  338. margin-bottom: $spacing-checkbox_card_group_vertical-marginBottom;
  339. }
  340. }
  341. }
  342. }
  343. @import "./rtl.scss";