index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. // ============================== Styles ==============================
  10. // styles from RadioGroup only
  11. const getGroupRadioStyle = token => {
  12. const {
  13. componentCls,
  14. antCls
  15. } = token;
  16. const groupPrefixCls = `${componentCls}-group`;
  17. return {
  18. [groupPrefixCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  19. display: 'inline-block',
  20. fontSize: 0,
  21. // RTL
  22. [`&${groupPrefixCls}-rtl`]: {
  23. direction: 'rtl'
  24. },
  25. [`&${groupPrefixCls}-block`]: {
  26. display: 'flex'
  27. },
  28. [`${antCls}-badge ${antCls}-badge-count`]: {
  29. zIndex: 1
  30. },
  31. [`> ${antCls}-badge:not(:first-child) > ${antCls}-button-wrapper`]: {
  32. borderInlineStart: 'none'
  33. }
  34. })
  35. };
  36. };
  37. // Styles from radio-wrapper
  38. const getRadioBasicStyle = token => {
  39. const {
  40. componentCls,
  41. wrapperMarginInlineEnd,
  42. colorPrimary,
  43. radioSize,
  44. motionDurationSlow,
  45. motionDurationMid,
  46. motionEaseInOutCirc,
  47. colorBgContainer,
  48. colorBorder,
  49. lineWidth,
  50. colorBgContainerDisabled,
  51. colorTextDisabled,
  52. paddingXS,
  53. dotColorDisabled,
  54. lineType,
  55. radioColor,
  56. radioBgColor,
  57. calc
  58. } = token;
  59. const radioInnerPrefixCls = `${componentCls}-inner`;
  60. const dotPadding = 4;
  61. const radioDotDisabledSize = calc(radioSize).sub(calc(dotPadding).mul(2));
  62. const radioSizeCalc = calc(1).mul(radioSize).equal({
  63. unit: true
  64. });
  65. return {
  66. [`${componentCls}-wrapper`]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  67. display: 'inline-flex',
  68. alignItems: 'baseline',
  69. marginInlineStart: 0,
  70. marginInlineEnd: wrapperMarginInlineEnd,
  71. cursor: 'pointer',
  72. '&:last-child': {
  73. marginInlineEnd: 0
  74. },
  75. // RTL
  76. [`&${componentCls}-wrapper-rtl`]: {
  77. direction: 'rtl'
  78. },
  79. '&-disabled': {
  80. cursor: 'not-allowed',
  81. color: token.colorTextDisabled
  82. },
  83. '&::after': {
  84. display: 'inline-block',
  85. width: 0,
  86. overflow: 'hidden',
  87. content: '"\\a0"'
  88. },
  89. '&-block': {
  90. flex: 1,
  91. justifyContent: 'center'
  92. },
  93. // hashId 在 wrapper 上,只能铺平
  94. [`${componentCls}-checked::after`]: {
  95. position: 'absolute',
  96. insetBlockStart: 0,
  97. insetInlineStart: 0,
  98. width: '100%',
  99. height: '100%',
  100. border: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorPrimary}`,
  101. borderRadius: '50%',
  102. visibility: 'hidden',
  103. opacity: 0,
  104. content: '""'
  105. },
  106. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  107. position: 'relative',
  108. display: 'inline-block',
  109. outline: 'none',
  110. cursor: 'pointer',
  111. alignSelf: 'center',
  112. borderRadius: '50%'
  113. }),
  114. [`${componentCls}-wrapper:hover &,
  115. &:hover ${radioInnerPrefixCls}`]: {
  116. borderColor: colorPrimary
  117. },
  118. [`${componentCls}-input:focus-visible + ${radioInnerPrefixCls}`]: (0, _style.genFocusOutline)(token),
  119. [`${componentCls}:hover::after, ${componentCls}-wrapper:hover &::after`]: {
  120. visibility: 'visible'
  121. },
  122. [`${componentCls}-inner`]: {
  123. '&::after': {
  124. boxSizing: 'border-box',
  125. position: 'absolute',
  126. insetBlockStart: '50%',
  127. insetInlineStart: '50%',
  128. display: 'block',
  129. width: radioSizeCalc,
  130. height: radioSizeCalc,
  131. marginBlockStart: calc(1).mul(radioSize).div(-2).equal({
  132. unit: true
  133. }),
  134. marginInlineStart: calc(1).mul(radioSize).div(-2).equal({
  135. unit: true
  136. }),
  137. backgroundColor: radioColor,
  138. borderBlockStart: 0,
  139. borderInlineStart: 0,
  140. borderRadius: radioSizeCalc,
  141. transform: 'scale(0)',
  142. opacity: 0,
  143. transition: `all ${motionDurationSlow} ${motionEaseInOutCirc}`,
  144. content: '""'
  145. },
  146. boxSizing: 'border-box',
  147. position: 'relative',
  148. insetBlockStart: 0,
  149. insetInlineStart: 0,
  150. display: 'block',
  151. width: radioSizeCalc,
  152. height: radioSizeCalc,
  153. backgroundColor: colorBgContainer,
  154. borderColor: colorBorder,
  155. borderStyle: 'solid',
  156. borderWidth: lineWidth,
  157. borderRadius: '50%',
  158. transition: `all ${motionDurationMid}`
  159. },
  160. [`${componentCls}-input`]: {
  161. position: 'absolute',
  162. inset: 0,
  163. zIndex: 1,
  164. cursor: 'pointer',
  165. opacity: 0
  166. },
  167. // 选中状态
  168. [`${componentCls}-checked`]: {
  169. [radioInnerPrefixCls]: {
  170. borderColor: colorPrimary,
  171. backgroundColor: radioBgColor,
  172. '&::after': {
  173. transform: `scale(${token.calc(token.dotSize).div(radioSize).equal()})`,
  174. opacity: 1,
  175. transition: `all ${motionDurationSlow} ${motionEaseInOutCirc}`
  176. }
  177. }
  178. },
  179. [`${componentCls}-disabled`]: {
  180. cursor: 'not-allowed',
  181. [radioInnerPrefixCls]: {
  182. backgroundColor: colorBgContainerDisabled,
  183. borderColor: colorBorder,
  184. cursor: 'not-allowed',
  185. '&::after': {
  186. backgroundColor: dotColorDisabled
  187. }
  188. },
  189. [`${componentCls}-input`]: {
  190. cursor: 'not-allowed'
  191. },
  192. [`${componentCls}-disabled + span`]: {
  193. color: colorTextDisabled,
  194. cursor: 'not-allowed'
  195. },
  196. [`&${componentCls}-checked`]: {
  197. [radioInnerPrefixCls]: {
  198. '&::after': {
  199. transform: `scale(${calc(radioDotDisabledSize).div(radioSize).equal()})`
  200. }
  201. }
  202. }
  203. },
  204. [`span${componentCls} + *`]: {
  205. paddingInlineStart: paddingXS,
  206. paddingInlineEnd: paddingXS
  207. }
  208. })
  209. };
  210. };
  211. // Styles from radio-button
  212. const getRadioButtonStyle = token => {
  213. const {
  214. buttonColor,
  215. controlHeight,
  216. componentCls,
  217. lineWidth,
  218. lineType,
  219. colorBorder,
  220. motionDurationMid,
  221. buttonPaddingInline,
  222. fontSize,
  223. buttonBg,
  224. fontSizeLG,
  225. controlHeightLG,
  226. controlHeightSM,
  227. paddingXS,
  228. borderRadius,
  229. borderRadiusSM,
  230. borderRadiusLG,
  231. buttonCheckedBg,
  232. buttonSolidCheckedColor,
  233. colorTextDisabled,
  234. colorBgContainerDisabled,
  235. buttonCheckedBgDisabled,
  236. buttonCheckedColorDisabled,
  237. colorPrimary,
  238. colorPrimaryHover,
  239. colorPrimaryActive,
  240. buttonSolidCheckedBg,
  241. buttonSolidCheckedHoverBg,
  242. buttonSolidCheckedActiveBg,
  243. calc
  244. } = token;
  245. return {
  246. [`${componentCls}-button-wrapper`]: {
  247. position: 'relative',
  248. display: 'inline-block',
  249. height: controlHeight,
  250. margin: 0,
  251. paddingInline: buttonPaddingInline,
  252. paddingBlock: 0,
  253. color: buttonColor,
  254. fontSize,
  255. lineHeight: (0, _cssinjs.unit)(calc(controlHeight).sub(calc(lineWidth).mul(2)).equal()),
  256. background: buttonBg,
  257. border: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorBorder}`,
  258. // strange align fix for chrome but works
  259. // https://gw.alipayobjects.com/zos/rmsportal/VFTfKXJuogBAXcvfAUWJ.gif
  260. borderBlockStartWidth: calc(lineWidth).add(0.02).equal(),
  261. borderInlineEndWidth: lineWidth,
  262. cursor: 'pointer',
  263. transition: [`color ${motionDurationMid}`, `background ${motionDurationMid}`, `box-shadow ${motionDurationMid}`].join(','),
  264. a: {
  265. color: buttonColor
  266. },
  267. [`> ${componentCls}-button`]: {
  268. position: 'absolute',
  269. insetBlockStart: 0,
  270. insetInlineStart: 0,
  271. zIndex: -1,
  272. width: '100%',
  273. height: '100%'
  274. },
  275. '&:not(:last-child)': {
  276. marginInlineEnd: calc(lineWidth).mul(-1).equal()
  277. },
  278. '&:first-child': {
  279. borderInlineStart: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorBorder}`,
  280. borderStartStartRadius: borderRadius,
  281. borderEndStartRadius: borderRadius
  282. },
  283. '&:last-child': {
  284. borderStartEndRadius: borderRadius,
  285. borderEndEndRadius: borderRadius
  286. },
  287. '&:first-child:last-child': {
  288. borderRadius
  289. },
  290. [`${componentCls}-group-large &`]: {
  291. height: controlHeightLG,
  292. fontSize: fontSizeLG,
  293. lineHeight: (0, _cssinjs.unit)(calc(controlHeightLG).sub(calc(lineWidth).mul(2)).equal()),
  294. '&:first-child': {
  295. borderStartStartRadius: borderRadiusLG,
  296. borderEndStartRadius: borderRadiusLG
  297. },
  298. '&:last-child': {
  299. borderStartEndRadius: borderRadiusLG,
  300. borderEndEndRadius: borderRadiusLG
  301. }
  302. },
  303. [`${componentCls}-group-small &`]: {
  304. height: controlHeightSM,
  305. paddingInline: calc(paddingXS).sub(lineWidth).equal(),
  306. paddingBlock: 0,
  307. lineHeight: (0, _cssinjs.unit)(calc(controlHeightSM).sub(calc(lineWidth).mul(2)).equal()),
  308. '&:first-child': {
  309. borderStartStartRadius: borderRadiusSM,
  310. borderEndStartRadius: borderRadiusSM
  311. },
  312. '&:last-child': {
  313. borderStartEndRadius: borderRadiusSM,
  314. borderEndEndRadius: borderRadiusSM
  315. }
  316. },
  317. '&:hover': {
  318. position: 'relative',
  319. color: colorPrimary
  320. },
  321. '&:has(:focus-visible)': (0, _style.genFocusOutline)(token),
  322. [`${componentCls}-inner, input[type='checkbox'], input[type='radio']`]: {
  323. width: 0,
  324. height: 0,
  325. opacity: 0,
  326. pointerEvents: 'none'
  327. },
  328. [`&-checked:not(${componentCls}-button-wrapper-disabled)`]: {
  329. zIndex: 1,
  330. color: colorPrimary,
  331. background: buttonCheckedBg,
  332. borderColor: colorPrimary,
  333. '&::before': {
  334. backgroundColor: colorPrimary
  335. },
  336. '&:first-child': {
  337. borderColor: colorPrimary
  338. },
  339. '&:hover': {
  340. color: colorPrimaryHover,
  341. borderColor: colorPrimaryHover,
  342. '&::before': {
  343. backgroundColor: colorPrimaryHover
  344. }
  345. },
  346. '&:active': {
  347. color: colorPrimaryActive,
  348. borderColor: colorPrimaryActive,
  349. '&::before': {
  350. backgroundColor: colorPrimaryActive
  351. }
  352. }
  353. },
  354. [`${componentCls}-group-solid &-checked:not(${componentCls}-button-wrapper-disabled)`]: {
  355. color: buttonSolidCheckedColor,
  356. background: buttonSolidCheckedBg,
  357. borderColor: buttonSolidCheckedBg,
  358. '&:hover': {
  359. color: buttonSolidCheckedColor,
  360. background: buttonSolidCheckedHoverBg,
  361. borderColor: buttonSolidCheckedHoverBg
  362. },
  363. '&:active': {
  364. color: buttonSolidCheckedColor,
  365. background: buttonSolidCheckedActiveBg,
  366. borderColor: buttonSolidCheckedActiveBg
  367. }
  368. },
  369. '&-disabled': {
  370. color: colorTextDisabled,
  371. backgroundColor: colorBgContainerDisabled,
  372. borderColor: colorBorder,
  373. cursor: 'not-allowed',
  374. '&:first-child, &:hover': {
  375. color: colorTextDisabled,
  376. backgroundColor: colorBgContainerDisabled,
  377. borderColor: colorBorder
  378. }
  379. },
  380. [`&-disabled${componentCls}-button-wrapper-checked`]: {
  381. color: buttonCheckedColorDisabled,
  382. backgroundColor: buttonCheckedBgDisabled,
  383. borderColor: colorBorder,
  384. boxShadow: 'none'
  385. },
  386. '&-block': {
  387. flex: 1,
  388. textAlign: 'center'
  389. }
  390. }
  391. };
  392. };
  393. // ============================== Export ==============================
  394. const prepareComponentToken = token => {
  395. const {
  396. wireframe,
  397. padding,
  398. marginXS,
  399. lineWidth,
  400. fontSizeLG,
  401. colorText,
  402. colorBgContainer,
  403. colorTextDisabled,
  404. controlItemBgActiveDisabled,
  405. colorTextLightSolid,
  406. colorPrimary,
  407. colorPrimaryHover,
  408. colorPrimaryActive,
  409. colorWhite
  410. } = token;
  411. const dotPadding = 4; // Fixed value
  412. const radioSize = fontSizeLG;
  413. const radioDotSize = wireframe ? radioSize - dotPadding * 2 : radioSize - (dotPadding + lineWidth) * 2;
  414. return {
  415. // Radio
  416. radioSize,
  417. dotSize: radioDotSize,
  418. dotColorDisabled: colorTextDisabled,
  419. // Radio buttons
  420. buttonSolidCheckedColor: colorTextLightSolid,
  421. buttonSolidCheckedBg: colorPrimary,
  422. buttonSolidCheckedHoverBg: colorPrimaryHover,
  423. buttonSolidCheckedActiveBg: colorPrimaryActive,
  424. buttonBg: colorBgContainer,
  425. buttonCheckedBg: colorBgContainer,
  426. buttonColor: colorText,
  427. buttonCheckedBgDisabled: controlItemBgActiveDisabled,
  428. buttonCheckedColorDisabled: colorTextDisabled,
  429. buttonPaddingInline: padding - lineWidth,
  430. wrapperMarginInlineEnd: marginXS,
  431. // internal
  432. radioColor: wireframe ? colorPrimary : colorWhite,
  433. radioBgColor: wireframe ? colorBgContainer : colorPrimary
  434. };
  435. };
  436. exports.prepareComponentToken = prepareComponentToken;
  437. var _default = exports.default = (0, _internal.genStyleHooks)('Radio', token => {
  438. const {
  439. controlOutline,
  440. controlOutlineWidth
  441. } = token;
  442. const radioFocusShadow = `0 0 0 ${(0, _cssinjs.unit)(controlOutlineWidth)} ${controlOutline}`;
  443. const radioButtonFocusShadow = radioFocusShadow;
  444. const radioToken = (0, _internal.mergeToken)(token, {
  445. radioFocusShadow,
  446. radioButtonFocusShadow
  447. });
  448. return [getGroupRadioStyle(radioToken), getRadioBasicStyle(radioToken), getRadioButtonStyle(radioToken)];
  449. }, prepareComponentToken, {
  450. unitless: {
  451. radioSize: true,
  452. dotSize: true
  453. }
  454. });