index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.prepareToken = exports.prepareComponentToken = exports.default = void 0;
  7. var _cssinjs = require("@ant-design/cssinjs");
  8. var _style = require("../../style");
  9. var _motion = require("../../style/motion");
  10. var _internal = require("../../theme/internal");
  11. var _explain = _interopRequireDefault(require("./explain"));
  12. const resetForm = token => ({
  13. legend: {
  14. display: 'block',
  15. width: '100%',
  16. marginBottom: token.marginLG,
  17. padding: 0,
  18. color: token.colorTextDescription,
  19. fontSize: token.fontSizeLG,
  20. lineHeight: 'inherit',
  21. border: 0,
  22. borderBottom: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorBorder}`
  23. },
  24. 'input[type="search"]': {
  25. boxSizing: 'border-box'
  26. },
  27. // Position radios and checkboxes better
  28. 'input[type="radio"], input[type="checkbox"]': {
  29. lineHeight: 'normal'
  30. },
  31. 'input[type="file"]': {
  32. display: 'block'
  33. },
  34. // Make range inputs behave like textual form controls
  35. 'input[type="range"]': {
  36. display: 'block',
  37. width: '100%'
  38. },
  39. // Make multiple select elements height not fixed
  40. 'select[multiple], select[size]': {
  41. height: 'auto'
  42. },
  43. // Focus for file, radio, and checkbox
  44. [`input[type='file']:focus,
  45. input[type='radio']:focus,
  46. input[type='checkbox']:focus`]: {
  47. outline: 0,
  48. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(token.controlOutlineWidth)} ${token.controlOutline}`
  49. },
  50. // Adjust output element
  51. output: {
  52. display: 'block',
  53. paddingTop: 15,
  54. color: token.colorText,
  55. fontSize: token.fontSize,
  56. lineHeight: token.lineHeight
  57. }
  58. });
  59. const genFormSize = (token, height) => {
  60. const {
  61. formItemCls
  62. } = token;
  63. return {
  64. [formItemCls]: {
  65. [`${formItemCls}-label > label`]: {
  66. height
  67. },
  68. [`${formItemCls}-control-input`]: {
  69. minHeight: height
  70. }
  71. }
  72. };
  73. };
  74. const genFormStyle = token => {
  75. const {
  76. componentCls
  77. } = token;
  78. return {
  79. [token.componentCls]: Object.assign(Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), resetForm(token)), {
  80. [`${componentCls}-text`]: {
  81. display: 'inline-block',
  82. paddingInlineEnd: token.paddingSM
  83. },
  84. // ================================================================
  85. // = Size =
  86. // ================================================================
  87. '&-small': Object.assign({}, genFormSize(token, token.controlHeightSM)),
  88. '&-large': Object.assign({}, genFormSize(token, token.controlHeightLG))
  89. })
  90. };
  91. };
  92. const genFormItemStyle = token => {
  93. const {
  94. formItemCls,
  95. iconCls,
  96. rootPrefixCls,
  97. antCls,
  98. labelRequiredMarkColor,
  99. labelColor,
  100. labelFontSize,
  101. labelHeight,
  102. labelColonMarginInlineStart,
  103. labelColonMarginInlineEnd,
  104. itemMarginBottom
  105. } = token;
  106. return {
  107. [formItemCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  108. marginBottom: itemMarginBottom,
  109. verticalAlign: 'top',
  110. '&-with-help': {
  111. transition: 'none'
  112. },
  113. [`&-hidden,
  114. &-hidden${antCls}-row`]: {
  115. // https://github.com/ant-design/ant-design/issues/26141
  116. display: 'none'
  117. },
  118. '&-has-warning': {
  119. [`${formItemCls}-split`]: {
  120. color: token.colorError
  121. }
  122. },
  123. '&-has-error': {
  124. [`${formItemCls}-split`]: {
  125. color: token.colorWarning
  126. }
  127. },
  128. // ==============================================================
  129. // = Label =
  130. // ==============================================================
  131. [`${formItemCls}-label`]: {
  132. flexGrow: 0,
  133. overflow: 'hidden',
  134. whiteSpace: 'nowrap',
  135. textAlign: 'end',
  136. verticalAlign: 'middle',
  137. '&-left': {
  138. textAlign: 'start'
  139. },
  140. '&-wrap': {
  141. overflow: 'unset',
  142. lineHeight: token.lineHeight,
  143. whiteSpace: 'unset',
  144. '> label': {
  145. verticalAlign: 'middle',
  146. textWrap: 'balance'
  147. }
  148. },
  149. '> label': {
  150. position: 'relative',
  151. display: 'inline-flex',
  152. alignItems: 'center',
  153. maxWidth: '100%',
  154. height: labelHeight,
  155. color: labelColor,
  156. fontSize: labelFontSize,
  157. [`> ${iconCls}`]: {
  158. fontSize: token.fontSize,
  159. verticalAlign: 'top'
  160. },
  161. [`&${formItemCls}-required`]: {
  162. '&::before': {
  163. display: 'inline-block',
  164. marginInlineEnd: token.marginXXS,
  165. color: labelRequiredMarkColor,
  166. fontSize: token.fontSize,
  167. fontFamily: 'SimSun, sans-serif',
  168. lineHeight: 1,
  169. content: '"*"'
  170. },
  171. [`&${formItemCls}-required-mark-hidden, &${formItemCls}-required-mark-optional`]: {
  172. '&::before': {
  173. display: 'none'
  174. }
  175. }
  176. },
  177. // Optional mark
  178. [`${formItemCls}-optional`]: {
  179. display: 'inline-block',
  180. marginInlineStart: token.marginXXS,
  181. color: token.colorTextDescription,
  182. [`&${formItemCls}-required-mark-hidden`]: {
  183. display: 'none'
  184. }
  185. },
  186. // Optional mark
  187. [`${formItemCls}-tooltip`]: {
  188. color: token.colorTextDescription,
  189. cursor: 'help',
  190. writingMode: 'horizontal-tb',
  191. marginInlineStart: token.marginXXS
  192. },
  193. '&::after': {
  194. content: '":"',
  195. position: 'relative',
  196. marginBlock: 0,
  197. marginInlineStart: labelColonMarginInlineStart,
  198. marginInlineEnd: labelColonMarginInlineEnd
  199. },
  200. [`&${formItemCls}-no-colon::after`]: {
  201. content: '"\\a0"'
  202. }
  203. }
  204. },
  205. // ==============================================================
  206. // = Input =
  207. // ==============================================================
  208. [`${formItemCls}-control`]: {
  209. ['--ant-display']: 'flex',
  210. flexDirection: 'column',
  211. flexGrow: 1,
  212. [`&:first-child:not([class^="'${rootPrefixCls}-col-'"]):not([class*="' ${rootPrefixCls}-col-'"])`]: {
  213. width: '100%'
  214. },
  215. '&-input': {
  216. position: 'relative',
  217. display: 'flex',
  218. alignItems: 'center',
  219. minHeight: token.controlHeight,
  220. '&-content': {
  221. flex: 'auto',
  222. maxWidth: '100%',
  223. // Fix https://github.com/ant-design/ant-design/issues/54042
  224. // Remove impact of whitespaces
  225. [`&:has(> ${antCls}-switch:only-child, > ${antCls}-rate:only-child)`]: {
  226. display: 'flex',
  227. alignItems: 'center'
  228. }
  229. }
  230. }
  231. },
  232. // ==============================================================
  233. // = Explain =
  234. // ==============================================================
  235. [formItemCls]: {
  236. '&-additional': {
  237. display: 'flex',
  238. flexDirection: 'column'
  239. },
  240. '&-explain, &-extra': {
  241. clear: 'both',
  242. color: token.colorTextDescription,
  243. fontSize: token.fontSize,
  244. lineHeight: token.lineHeight
  245. },
  246. '&-explain-connected': {
  247. width: '100%'
  248. },
  249. '&-extra': {
  250. minHeight: token.controlHeightSM,
  251. transition: `color ${token.motionDurationMid} ${token.motionEaseOut}` // sync input color transition
  252. },
  253. '&-explain': {
  254. '&-error': {
  255. color: token.colorError
  256. },
  257. '&-warning': {
  258. color: token.colorWarning
  259. }
  260. }
  261. },
  262. [`&-with-help ${formItemCls}-explain`]: {
  263. height: 'auto',
  264. opacity: 1
  265. },
  266. // ==============================================================
  267. // = Feedback Icon =
  268. // ==============================================================
  269. [`${formItemCls}-feedback-icon`]: {
  270. fontSize: token.fontSize,
  271. textAlign: 'center',
  272. visibility: 'visible',
  273. animationName: _motion.zoomIn,
  274. animationDuration: token.motionDurationMid,
  275. animationTimingFunction: token.motionEaseOutBack,
  276. pointerEvents: 'none',
  277. '&-success': {
  278. color: token.colorSuccess
  279. },
  280. '&-error': {
  281. color: token.colorError
  282. },
  283. '&-warning': {
  284. color: token.colorWarning
  285. },
  286. '&-validating': {
  287. color: token.colorPrimary
  288. }
  289. }
  290. })
  291. };
  292. };
  293. const makeVerticalLayoutLabel = token => ({
  294. padding: token.verticalLabelPadding,
  295. margin: token.verticalLabelMargin,
  296. whiteSpace: 'initial',
  297. textAlign: 'start',
  298. '> label': {
  299. margin: 0,
  300. '&::after': {
  301. // https://github.com/ant-design/ant-design/issues/43538
  302. visibility: 'hidden'
  303. }
  304. }
  305. });
  306. const genHorizontalStyle = token => {
  307. const {
  308. antCls,
  309. formItemCls
  310. } = token;
  311. return {
  312. [`${formItemCls}-horizontal`]: {
  313. [`${formItemCls}-label`]: {
  314. flexGrow: 0
  315. },
  316. [`${formItemCls}-control`]: {
  317. flex: '1 1 0',
  318. // https://github.com/ant-design/ant-design/issues/32777
  319. // https://github.com/ant-design/ant-design/issues/33773
  320. minWidth: 0
  321. },
  322. // Do not change this to `ant-col-24`! `-24` match all the responsive rules
  323. // https://github.com/ant-design/ant-design/issues/32980
  324. // https://github.com/ant-design/ant-design/issues/34903
  325. // https://github.com/ant-design/ant-design/issues/44538
  326. [`${formItemCls}-label[class$='-24'], ${formItemCls}-label[class*='-24 ']`]: {
  327. [`& + ${formItemCls}-control`]: {
  328. minWidth: 'unset'
  329. }
  330. },
  331. [`${antCls}-col-24${formItemCls}-label,
  332. ${antCls}-col-xl-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  333. }
  334. };
  335. };
  336. const genInlineStyle = token => {
  337. const {
  338. componentCls,
  339. formItemCls,
  340. inlineItemMarginBottom
  341. } = token;
  342. return {
  343. [`${componentCls}-inline`]: {
  344. display: 'flex',
  345. flexWrap: 'wrap',
  346. [`${formItemCls}-inline`]: {
  347. flex: 'none',
  348. marginInlineEnd: token.margin,
  349. marginBottom: inlineItemMarginBottom,
  350. '&-row': {
  351. flexWrap: 'nowrap'
  352. },
  353. [`> ${formItemCls}-label,
  354. > ${formItemCls}-control`]: {
  355. display: 'inline-block',
  356. verticalAlign: 'top'
  357. },
  358. [`> ${formItemCls}-label`]: {
  359. flex: 'none'
  360. },
  361. [`${componentCls}-text`]: {
  362. display: 'inline-block'
  363. },
  364. [`${formItemCls}-has-feedback`]: {
  365. display: 'inline-block'
  366. }
  367. }
  368. }
  369. };
  370. };
  371. const makeVerticalLayout = token => {
  372. const {
  373. componentCls,
  374. formItemCls,
  375. rootPrefixCls
  376. } = token;
  377. return {
  378. [`${formItemCls} ${formItemCls}-label`]: makeVerticalLayoutLabel(token),
  379. // ref: https://github.com/ant-design/ant-design/issues/45122
  380. [`${componentCls}:not(${componentCls}-inline)`]: {
  381. [formItemCls]: {
  382. flexWrap: 'wrap',
  383. [`${formItemCls}-label, ${formItemCls}-control`]: {
  384. // When developer pass `xs: { span }`,
  385. // It should follow the `xs` screen config
  386. // ref: https://github.com/ant-design/ant-design/issues/44386
  387. [`&:not([class*=" ${rootPrefixCls}-col-xs"])`]: {
  388. flex: '0 0 100%',
  389. maxWidth: '100%'
  390. }
  391. }
  392. }
  393. }
  394. };
  395. };
  396. const genVerticalStyle = token => {
  397. const {
  398. componentCls,
  399. formItemCls,
  400. antCls
  401. } = token;
  402. return {
  403. [`${formItemCls}-vertical`]: {
  404. [`${formItemCls}-row`]: {
  405. flexDirection: 'column'
  406. },
  407. [`${formItemCls}-label > label`]: {
  408. height: 'auto'
  409. },
  410. [`${formItemCls}-control`]: {
  411. width: '100%'
  412. },
  413. [`${formItemCls}-label,
  414. ${antCls}-col-24${formItemCls}-label,
  415. ${antCls}-col-xl-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  416. },
  417. [`@media (max-width: ${(0, _cssinjs.unit)(token.screenXSMax)})`]: [makeVerticalLayout(token), {
  418. [componentCls]: {
  419. [`${formItemCls}:not(${formItemCls}-horizontal)`]: {
  420. [`${antCls}-col-xs-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  421. }
  422. }
  423. }],
  424. [`@media (max-width: ${(0, _cssinjs.unit)(token.screenSMMax)})`]: {
  425. [componentCls]: {
  426. [`${formItemCls}:not(${formItemCls}-horizontal)`]: {
  427. [`${antCls}-col-sm-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  428. }
  429. }
  430. },
  431. [`@media (max-width: ${(0, _cssinjs.unit)(token.screenMDMax)})`]: {
  432. [componentCls]: {
  433. [`${formItemCls}:not(${formItemCls}-horizontal)`]: {
  434. [`${antCls}-col-md-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  435. }
  436. }
  437. },
  438. [`@media (max-width: ${(0, _cssinjs.unit)(token.screenLGMax)})`]: {
  439. [componentCls]: {
  440. [`${formItemCls}:not(${formItemCls}-horizontal)`]: {
  441. [`${antCls}-col-lg-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  442. }
  443. }
  444. }
  445. };
  446. };
  447. // ============================== Export ==============================
  448. const prepareComponentToken = token => ({
  449. labelRequiredMarkColor: token.colorError,
  450. labelColor: token.colorTextHeading,
  451. labelFontSize: token.fontSize,
  452. labelHeight: token.controlHeight,
  453. labelColonMarginInlineStart: token.marginXXS / 2,
  454. labelColonMarginInlineEnd: token.marginXS,
  455. itemMarginBottom: token.marginLG,
  456. verticalLabelPadding: `0 0 ${token.paddingXS}px`,
  457. verticalLabelMargin: 0,
  458. inlineItemMarginBottom: 0
  459. });
  460. exports.prepareComponentToken = prepareComponentToken;
  461. const prepareToken = (token, rootPrefixCls) => {
  462. const formToken = (0, _internal.mergeToken)(token, {
  463. formItemCls: `${token.componentCls}-item`,
  464. rootPrefixCls
  465. });
  466. return formToken;
  467. };
  468. exports.prepareToken = prepareToken;
  469. var _default = exports.default = (0, _internal.genStyleHooks)('Form', (token, {
  470. rootPrefixCls
  471. }) => {
  472. const formToken = prepareToken(token, rootPrefixCls);
  473. return [genFormStyle(formToken), genFormItemStyle(formToken), (0, _explain.default)(formToken), genHorizontalStyle(formToken), genInlineStyle(formToken), genVerticalStyle(formToken), (0, _motion.genCollapseMotion)(formToken), _motion.zoomIn];
  474. }, prepareComponentToken, {
  475. // Let From style before the Grid
  476. // ref https://github.com/ant-design/ant-design/issues/44386
  477. order: -1000
  478. });