checkbox.scss 7.5 KB

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