checkbox.scss 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. @use 'sass:map';
  2. @use 'common/var' as *;
  3. @use 'mixins/mixins' as *;
  4. @use 'mixins/var' as *;
  5. @use 'mixins/_button';
  6. @use 'mixins/utils' as *;
  7. $checkbox-height: () !default;
  8. $checkbox-height: map.merge($common-component-size, $checkbox-height);
  9. $checkbox-bordered-input-height: () !default;
  10. $checkbox-bordered-input-height: map.merge(
  11. (
  12. 'large': 14px,
  13. 'default': 12px,
  14. 'small': 12px,
  15. ),
  16. $checkbox-bordered-input-height
  17. );
  18. $checkbox-font-size: () !default;
  19. $checkbox-font-size: map.merge(
  20. (
  21. 'large': 14px,
  22. 'small': 12px,
  23. ),
  24. $checkbox-font-size
  25. );
  26. $checkbox-bordered-input-width: () !default;
  27. $checkbox-bordered-input-width: map.merge(
  28. $checkbox-bordered-input-height,
  29. $checkbox-bordered-input-width
  30. );
  31. @include b(checkbox) {
  32. @include set-component-css-var('checkbox', $checkbox);
  33. }
  34. @include b(checkbox) {
  35. color: getCssVar('checkbox-text-color');
  36. font-weight: getCssVar('checkbox-font-weight');
  37. font-size: getCssVar('font-size', 'base');
  38. position: relative;
  39. cursor: pointer;
  40. display: inline-flex;
  41. align-items: center;
  42. white-space: nowrap;
  43. user-select: none;
  44. margin-right: 30px;
  45. height: map.get($checkbox-height, 'default');
  46. @include when(disabled) {
  47. cursor: not-allowed;
  48. }
  49. @include when(bordered) {
  50. padding: 0 map.get($checkbox-bordered-padding-right, 'default')-$border-width
  51. 0 map.get($checkbox-bordered-padding-left, 'default')-$border-width;
  52. border-radius: getCssVar('border-radius-base');
  53. border: getCssVar('border');
  54. box-sizing: border-box;
  55. &.is-checked {
  56. border-color: getCssVar('color-primary');
  57. }
  58. &.is-disabled {
  59. border-color: getCssVar('border-color-lighter');
  60. }
  61. @each $size in (large, small) {
  62. &.#{$namespace}-checkbox--#{$size} {
  63. padding: 0
  64. map.get($checkbox-bordered-padding-right, $size)-$border-width
  65. 0
  66. map.get($checkbox-bordered-padding-left, $size)-$border-width;
  67. border-radius: map.get($button-border-radius, $size);
  68. .#{$namespace}-checkbox__label {
  69. font-size: map.get($button-font-size, $size);
  70. }
  71. .#{$namespace}-checkbox__inner {
  72. height: map.get($checkbox-bordered-input-height, $size);
  73. width: map.get($checkbox-bordered-input-width, $size);
  74. }
  75. }
  76. }
  77. &.#{$namespace}-checkbox--small {
  78. .#{$namespace}-checkbox__inner {
  79. &::after {
  80. height: 6px;
  81. width: 2px;
  82. }
  83. }
  84. }
  85. }
  86. input:focus-visible {
  87. & + .#{$namespace}-checkbox__inner {
  88. outline: 2px solid getCssVar('checkbox-input-border-color-hover');
  89. outline-offset: 1px;
  90. border-radius: getCssVar('checkbox-border-radius');
  91. }
  92. }
  93. @include e(input) {
  94. white-space: nowrap;
  95. cursor: pointer;
  96. outline: none;
  97. display: inline-flex;
  98. position: relative;
  99. @include when(disabled) {
  100. .#{$namespace}-checkbox__inner {
  101. background-color: getCssVar('checkbox-disabled-input-fill');
  102. border-color: getCssVar('checkbox-disabled-border-color');
  103. cursor: not-allowed;
  104. &::after {
  105. cursor: not-allowed;
  106. border-color: getCssVar('checkbox-disabled-icon-color');
  107. }
  108. }
  109. &.is-checked {
  110. .#{$namespace}-checkbox__inner {
  111. background-color: getCssVar('checkbox-disabled-checked-input-fill');
  112. border-color: getCssVar(
  113. 'checkbox-disabled-checked-input-border-color'
  114. );
  115. &::after {
  116. border-color: getCssVar('checkbox-disabled-checked-icon-color');
  117. }
  118. }
  119. }
  120. &.is-indeterminate {
  121. .#{$namespace}-checkbox__inner {
  122. background-color: getCssVar('checkbox-disabled-checked-input-fill');
  123. border-color: getCssVar(
  124. 'checkbox-disabled-checked-input-border-color'
  125. );
  126. &::before {
  127. background-color: getCssVar('checkbox-disabled-checked-icon-color');
  128. border-color: getCssVar('checkbox-disabled-checked-icon-color');
  129. }
  130. }
  131. }
  132. & + span.#{$namespace}-checkbox__label {
  133. color: getCssVar('disabled-text-color');
  134. cursor: not-allowed;
  135. }
  136. }
  137. @include when(checked) {
  138. .#{$namespace}-checkbox__inner {
  139. background-color: getCssVar('checkbox-checked-bg-color');
  140. border-color: getCssVar('checkbox-checked-input-border-color');
  141. &::after {
  142. transform: rotate(45deg) scaleY(1);
  143. }
  144. }
  145. & + .#{$namespace}-checkbox__label {
  146. color: getCssVar('checkbox-checked-text-color');
  147. }
  148. }
  149. @include when(focus) {
  150. // Visually distinguish when focus
  151. &:not(.is-checked) {
  152. .#{$namespace}-checkbox__original:not(:focus-visible) {
  153. border-color: getCssVar('checkbox-input-border-color-hover');
  154. }
  155. }
  156. }
  157. @include when(indeterminate) {
  158. .#{$namespace}-checkbox__inner {
  159. background-color: getCssVar('checkbox-checked-bg-color');
  160. border-color: getCssVar('checkbox-checked-input-border-color');
  161. &::before {
  162. content: '';
  163. position: absolute;
  164. display: block;
  165. background-color: getCssVar('checkbox-checked-icon-color');
  166. height: 2px;
  167. transform: scale(0.5);
  168. left: 0;
  169. right: 0;
  170. top: 5px;
  171. }
  172. &::after {
  173. display: none;
  174. }
  175. }
  176. }
  177. }
  178. @include e(inner) {
  179. display: inline-block;
  180. position: relative;
  181. border: getCssVar('checkbox-input-border');
  182. border-radius: getCssVar('checkbox-border-radius');
  183. box-sizing: border-box;
  184. width: getCssVar('checkbox-input-width');
  185. height: getCssVar('checkbox-input-height');
  186. background-color: getCssVar('checkbox-bg-color');
  187. z-index: getCssVar('index-normal');
  188. transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
  189. background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
  190. outline 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
  191. &:hover {
  192. border-color: getCssVar('checkbox-input-border-color-hover');
  193. }
  194. &::after {
  195. box-sizing: content-box;
  196. content: '';
  197. border: 1px solid getCssVar('checkbox-checked-icon-color');
  198. border-left: 0;
  199. border-top: 0;
  200. height: 7px;
  201. left: 4px;
  202. position: absolute;
  203. top: 1px;
  204. transform: rotate(45deg) scaleY(0);
  205. width: 3px;
  206. transition: transform 0.15s ease-in 0.05s;
  207. transform-origin: center;
  208. }
  209. }
  210. @include e(original) {
  211. opacity: 0;
  212. outline: none;
  213. position: absolute;
  214. margin: 0;
  215. width: 0;
  216. height: 0;
  217. z-index: -1;
  218. }
  219. @include e(label) {
  220. display: inline-block;
  221. padding-left: 8px;
  222. line-height: 1;
  223. font-size: getCssVar('checkbox-font-size');
  224. }
  225. @each $size in (large, small) {
  226. &.#{$namespace}-checkbox--#{$size} {
  227. height: map.get($checkbox-height, $size);
  228. @include e(label) {
  229. font-size: map.get($checkbox-font-size, $size);
  230. }
  231. @include e(inner) {
  232. width: map.get($checkbox-font-size, $size);
  233. height: map.get($checkbox-font-size, $size);
  234. }
  235. }
  236. }
  237. &.#{$namespace}-checkbox--small {
  238. @include e(input) {
  239. @include when(indeterminate) {
  240. @include e(inner) {
  241. &::before {
  242. top: 4px;
  243. }
  244. }
  245. }
  246. }
  247. @include e(inner) {
  248. &::after {
  249. width: 2px;
  250. height: 6px;
  251. }
  252. }
  253. }
  254. &:last-of-type {
  255. margin-right: 0;
  256. }
  257. }