index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.genCheckboxStyle = exports.default = void 0;
  7. exports.getStyle = getStyle;
  8. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  9. var _cssinjs = require("../../_util/cssinjs");
  10. var _internal = require("../../theme/internal");
  11. var _style = require("../../style");
  12. // ============================== Motion ==============================
  13. const antCheckboxEffect = new _cssinjs.Keyframes('antCheckboxEffect', {
  14. '0%': {
  15. transform: 'scale(1)',
  16. opacity: 0.5
  17. },
  18. '100%': {
  19. transform: 'scale(1.6)',
  20. opacity: 0
  21. }
  22. });
  23. // ============================== Styles ==============================
  24. const genCheckboxStyle = token => {
  25. const {
  26. checkboxCls
  27. } = token;
  28. const wrapperCls = `${checkboxCls}-wrapper`;
  29. return [
  30. // ===================== Basic =====================
  31. {
  32. // Group
  33. [`${checkboxCls}-group`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  34. display: 'inline-flex',
  35. flexWrap: 'wrap',
  36. columnGap: token.marginXS,
  37. // Group > Grid
  38. [`> ${token.antCls}-row`]: {
  39. flex: 1
  40. }
  41. }),
  42. // Wrapper
  43. [wrapperCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  44. display: 'inline-flex',
  45. alignItems: 'baseline',
  46. cursor: 'pointer',
  47. // Fix checkbox & radio in flex align #30260
  48. '&:after': {
  49. display: 'inline-block',
  50. width: 0,
  51. overflow: 'hidden',
  52. content: "'\\a0'"
  53. },
  54. // Checkbox near checkbox
  55. [`& + ${wrapperCls}`]: {
  56. marginInlineStart: 0
  57. },
  58. [`&${wrapperCls}-in-form-item`]: {
  59. 'input[type="checkbox"]': {
  60. width: 14,
  61. height: 14 // FIXME: magic
  62. }
  63. }
  64. }),
  65. // Wrapper > Checkbox
  66. [checkboxCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  67. position: 'relative',
  68. whiteSpace: 'nowrap',
  69. lineHeight: 1,
  70. cursor: 'pointer',
  71. // To make alignment right when `controlHeight` is changed
  72. // Ref: https://github.com/ant-design/ant-design/issues/41564
  73. alignSelf: 'center',
  74. // Wrapper > Checkbox > input
  75. [`${checkboxCls}-input`]: {
  76. position: 'absolute',
  77. // Since baseline align will get additional space offset,
  78. // we need to move input to top to make it align with text.
  79. // Ref: https://github.com/ant-design/ant-design/issues/38926#issuecomment-1486137799
  80. inset: 0,
  81. zIndex: 1,
  82. cursor: 'pointer',
  83. opacity: 0,
  84. margin: 0,
  85. [`&:focus-visible + ${checkboxCls}-inner`]: (0, _extends2.default)({}, (0, _style.genFocusOutline)(token))
  86. },
  87. // Wrapper > Checkbox > inner
  88. [`${checkboxCls}-inner`]: {
  89. boxSizing: 'border-box',
  90. position: 'relative',
  91. top: 0,
  92. insetInlineStart: 0,
  93. display: 'block',
  94. width: token.checkboxSize,
  95. height: token.checkboxSize,
  96. direction: 'ltr',
  97. backgroundColor: token.colorBgContainer,
  98. border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
  99. borderRadius: token.borderRadiusSM,
  100. borderCollapse: 'separate',
  101. transition: `all ${token.motionDurationSlow}`,
  102. '&:after': {
  103. boxSizing: 'border-box',
  104. position: 'absolute',
  105. top: '50%',
  106. insetInlineStart: '21.5%',
  107. display: 'table',
  108. width: token.checkboxSize / 14 * 5,
  109. height: token.checkboxSize / 14 * 8,
  110. border: `${token.lineWidthBold}px solid ${token.colorWhite}`,
  111. borderTop: 0,
  112. borderInlineStart: 0,
  113. transform: 'rotate(45deg) scale(0) translate(-50%,-50%)',
  114. opacity: 0,
  115. content: '""',
  116. transition: `all ${token.motionDurationFast} ${token.motionEaseInBack}, opacity ${token.motionDurationFast}`
  117. }
  118. },
  119. // Wrapper > Checkbox + Text
  120. '& + span': {
  121. paddingInlineStart: token.paddingXS,
  122. paddingInlineEnd: token.paddingXS
  123. }
  124. })
  125. },
  126. // ================= Indeterminate =================
  127. {
  128. [checkboxCls]: {
  129. '&-indeterminate': {
  130. // Wrapper > Checkbox > inner
  131. [`${checkboxCls}-inner`]: {
  132. '&:after': {
  133. top: '50%',
  134. insetInlineStart: '50%',
  135. width: token.fontSizeLG / 2,
  136. height: token.fontSizeLG / 2,
  137. backgroundColor: token.colorPrimary,
  138. border: 0,
  139. transform: 'translate(-50%, -50%) scale(1)',
  140. opacity: 1,
  141. content: '""'
  142. }
  143. }
  144. }
  145. }
  146. },
  147. // ===================== Hover =====================
  148. {
  149. // Wrapper
  150. [`${wrapperCls}:hover ${checkboxCls}:after`]: {
  151. visibility: 'visible'
  152. },
  153. // Wrapper & Wrapper > Checkbox
  154. [`
  155. ${wrapperCls}:not(${wrapperCls}-disabled),
  156. ${checkboxCls}:not(${checkboxCls}-disabled)
  157. `]: {
  158. [`&:hover ${checkboxCls}-inner`]: {
  159. borderColor: token.colorPrimary
  160. }
  161. },
  162. [`${wrapperCls}:not(${wrapperCls}-disabled)`]: {
  163. [`&:hover ${checkboxCls}-checked:not(${checkboxCls}-disabled) ${checkboxCls}-inner`]: {
  164. backgroundColor: token.colorPrimaryHover,
  165. borderColor: 'transparent'
  166. },
  167. [`&:hover ${checkboxCls}-checked:not(${checkboxCls}-disabled):after`]: {
  168. borderColor: token.colorPrimaryHover
  169. }
  170. }
  171. },
  172. // ==================== Checked ====================
  173. {
  174. // Wrapper > Checkbox
  175. [`${checkboxCls}-checked`]: {
  176. [`${checkboxCls}-inner`]: {
  177. backgroundColor: token.colorPrimary,
  178. borderColor: token.colorPrimary,
  179. '&:after': {
  180. opacity: 1,
  181. transform: 'rotate(45deg) scale(1) translate(-50%,-50%)',
  182. transition: `all ${token.motionDurationMid} ${token.motionEaseOutBack} ${token.motionDurationFast}`
  183. }
  184. },
  185. // Checked Effect
  186. '&:after': {
  187. position: 'absolute',
  188. top: 0,
  189. insetInlineStart: 0,
  190. width: '100%',
  191. height: '100%',
  192. borderRadius: token.borderRadiusSM,
  193. visibility: 'hidden',
  194. border: `${token.lineWidthBold}px solid ${token.colorPrimary}`,
  195. animationName: antCheckboxEffect,
  196. animationDuration: token.motionDurationSlow,
  197. animationTimingFunction: 'ease-in-out',
  198. animationFillMode: 'backwards',
  199. content: '""',
  200. transition: `all ${token.motionDurationSlow}`
  201. }
  202. },
  203. [`
  204. ${wrapperCls}-checked:not(${wrapperCls}-disabled),
  205. ${checkboxCls}-checked:not(${checkboxCls}-disabled)
  206. `]: {
  207. [`&:hover ${checkboxCls}-inner`]: {
  208. backgroundColor: token.colorPrimaryHover,
  209. borderColor: 'transparent'
  210. },
  211. [`&:hover ${checkboxCls}:after`]: {
  212. borderColor: token.colorPrimaryHover
  213. }
  214. }
  215. },
  216. // ==================== Disable ====================
  217. {
  218. // Wrapper
  219. [`${wrapperCls}-disabled`]: {
  220. cursor: 'not-allowed'
  221. },
  222. // Wrapper > Checkbox
  223. [`${checkboxCls}-disabled`]: {
  224. // Wrapper > Checkbox > input
  225. [`&, ${checkboxCls}-input`]: {
  226. cursor: 'not-allowed',
  227. // Disabled for native input to enable Tooltip event handler
  228. // ref: https://github.com/ant-design/ant-design/issues/39822#issuecomment-1365075901
  229. pointerEvents: 'none'
  230. },
  231. // Wrapper > Checkbox > inner
  232. [`${checkboxCls}-inner`]: {
  233. background: token.colorBgContainerDisabled,
  234. borderColor: token.colorBorder,
  235. '&:after': {
  236. borderColor: token.colorTextDisabled
  237. }
  238. },
  239. '&:after': {
  240. display: 'none'
  241. },
  242. '& + span': {
  243. color: token.colorTextDisabled
  244. },
  245. [`&${checkboxCls}-indeterminate ${checkboxCls}-inner::after`]: {
  246. background: token.colorTextDisabled
  247. }
  248. }
  249. }];
  250. };
  251. // ============================== Export ==============================
  252. exports.genCheckboxStyle = genCheckboxStyle;
  253. function getStyle(prefixCls, token) {
  254. const checkboxToken = (0, _internal.mergeToken)(token, {
  255. checkboxCls: `.${prefixCls}`,
  256. checkboxSize: token.controlInteractiveSize
  257. });
  258. return [genCheckboxStyle(checkboxToken)];
  259. }
  260. var _default = exports.default = (0, _internal.genComponentStyleHook)('Checkbox', (token, _ref) => {
  261. let {
  262. prefixCls
  263. } = _ref;
  264. return [getStyle(prefixCls, token)];
  265. });