index.js 14 KB

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