index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 _motion = require("../../style/motion");
  9. var _internal = require("../../theme/internal");
  10. var _style = require("../../style");
  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: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`
  23. },
  24. label: {
  25. fontSize: token.fontSize
  26. },
  27. 'input[type="search"]': {
  28. boxSizing: 'border-box'
  29. },
  30. // Position radios and checkboxes better
  31. 'input[type="radio"], input[type="checkbox"]': {
  32. lineHeight: 'normal'
  33. },
  34. 'input[type="file"]': {
  35. display: 'block'
  36. },
  37. // Make range inputs behave like textual form controls
  38. 'input[type="range"]': {
  39. display: 'block',
  40. width: '100%'
  41. },
  42. // Make multiple select elements height not fixed
  43. 'select[multiple], select[size]': {
  44. height: 'auto'
  45. },
  46. // Focus for file, radio, and checkbox
  47. [`input[type='file']:focus,
  48. input[type='radio']:focus,
  49. input[type='checkbox']:focus`]: {
  50. outline: 0,
  51. boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`
  52. },
  53. // Adjust output element
  54. output: {
  55. display: 'block',
  56. paddingTop: 15,
  57. color: token.colorText,
  58. fontSize: token.fontSize,
  59. lineHeight: token.lineHeight
  60. }
  61. });
  62. const genFormSize = (token, height) => {
  63. const {
  64. formItemCls
  65. } = token;
  66. return {
  67. [formItemCls]: {
  68. [`${formItemCls}-label > label`]: {
  69. height
  70. },
  71. [`${formItemCls}-control-input`]: {
  72. minHeight: height
  73. }
  74. }
  75. };
  76. };
  77. const genFormStyle = token => {
  78. const {
  79. componentCls
  80. } = token;
  81. return {
  82. [token.componentCls]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), resetForm(token)), {
  83. [`${componentCls}-text`]: {
  84. display: 'inline-block',
  85. paddingInlineEnd: token.paddingSM
  86. },
  87. // ================================================================
  88. // = Size =
  89. // ================================================================
  90. '&-small': (0, _extends2.default)({}, genFormSize(token, token.controlHeightSM)),
  91. '&-large': (0, _extends2.default)({}, genFormSize(token, token.controlHeightLG))
  92. })
  93. };
  94. };
  95. const genFormItemStyle = token => {
  96. const {
  97. formItemCls,
  98. iconCls,
  99. componentCls,
  100. rootPrefixCls
  101. } = token;
  102. return {
  103. [formItemCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  104. marginBottom: token.marginLG,
  105. verticalAlign: 'top',
  106. '&-with-help': {
  107. transition: 'none'
  108. },
  109. [`&-hidden,
  110. &-hidden.${rootPrefixCls}-row`]: {
  111. // https://github.com/ant-design/ant-design/issues/26141
  112. display: 'none'
  113. },
  114. '&-has-warning': {
  115. [`${formItemCls}-split`]: {
  116. color: token.colorError
  117. }
  118. },
  119. '&-has-error': {
  120. [`${formItemCls}-split`]: {
  121. color: token.colorWarning
  122. }
  123. },
  124. // ==============================================================
  125. // = Label =
  126. // ==============================================================
  127. [`${formItemCls}-label`]: {
  128. display: 'inline-block',
  129. flexGrow: 0,
  130. overflow: 'hidden',
  131. whiteSpace: 'nowrap',
  132. textAlign: 'end',
  133. verticalAlign: 'middle',
  134. '&-left': {
  135. textAlign: 'start'
  136. },
  137. '&-wrap': {
  138. overflow: 'unset',
  139. lineHeight: `${token.lineHeight} - 0.25em`,
  140. whiteSpace: 'unset'
  141. },
  142. '> label': {
  143. position: 'relative',
  144. display: 'inline-flex',
  145. alignItems: 'center',
  146. maxWidth: '100%',
  147. height: token.controlHeight,
  148. color: token.colorTextHeading,
  149. fontSize: token.fontSize,
  150. [`> ${iconCls}`]: {
  151. fontSize: token.fontSize,
  152. verticalAlign: 'top'
  153. },
  154. // Required mark
  155. [`&${formItemCls}-required:not(${formItemCls}-required-mark-optional)::before`]: {
  156. display: 'inline-block',
  157. marginInlineEnd: token.marginXXS,
  158. color: token.colorError,
  159. fontSize: token.fontSize,
  160. fontFamily: 'SimSun, sans-serif',
  161. lineHeight: 1,
  162. content: '"*"',
  163. [`${componentCls}-hide-required-mark &`]: {
  164. display: 'none'
  165. }
  166. },
  167. // Optional mark
  168. [`${formItemCls}-optional`]: {
  169. display: 'inline-block',
  170. marginInlineStart: token.marginXXS,
  171. color: token.colorTextDescription,
  172. [`${componentCls}-hide-required-mark &`]: {
  173. display: 'none'
  174. }
  175. },
  176. // Optional mark
  177. [`${formItemCls}-tooltip`]: {
  178. color: token.colorTextDescription,
  179. cursor: 'help',
  180. writingMode: 'horizontal-tb',
  181. marginInlineStart: token.marginXXS
  182. },
  183. '&::after': {
  184. content: '":"',
  185. position: 'relative',
  186. marginBlock: 0,
  187. marginInlineStart: token.marginXXS / 2,
  188. marginInlineEnd: token.marginXS
  189. },
  190. [`&${formItemCls}-no-colon::after`]: {
  191. content: '" "'
  192. }
  193. }
  194. },
  195. // ==============================================================
  196. // = Input =
  197. // ==============================================================
  198. [`${formItemCls}-control`]: {
  199. display: 'flex',
  200. flexDirection: 'column',
  201. flexGrow: 1,
  202. [`&:first-child:not([class^="'${rootPrefixCls}-col-'"]):not([class*="' ${rootPrefixCls}-col-'"])`]: {
  203. width: '100%'
  204. },
  205. '&-input': {
  206. position: 'relative',
  207. display: 'flex',
  208. alignItems: 'center',
  209. minHeight: token.controlHeight,
  210. '&-content': {
  211. flex: 'auto',
  212. maxWidth: '100%'
  213. }
  214. }
  215. },
  216. // ==============================================================
  217. // = Explain =
  218. // ==============================================================
  219. [formItemCls]: {
  220. '&-explain, &-extra': {
  221. clear: 'both',
  222. color: token.colorTextDescription,
  223. fontSize: token.fontSize,
  224. lineHeight: token.lineHeight
  225. },
  226. '&-explain-connected': {
  227. width: '100%'
  228. },
  229. '&-extra': {
  230. minHeight: token.controlHeightSM,
  231. transition: `color ${token.motionDurationMid} ${token.motionEaseOut}` // sync input color transition
  232. },
  233. '&-explain': {
  234. '&-error': {
  235. color: token.colorError
  236. },
  237. '&-warning': {
  238. color: token.colorWarning
  239. }
  240. }
  241. },
  242. [`&-with-help ${formItemCls}-explain`]: {
  243. height: 'auto',
  244. opacity: 1
  245. },
  246. // ==============================================================
  247. // = Feedback Icon =
  248. // ==============================================================
  249. [`${formItemCls}-feedback-icon`]: {
  250. fontSize: token.fontSize,
  251. textAlign: 'center',
  252. visibility: 'visible',
  253. animationName: _motion.zoomIn,
  254. animationDuration: token.motionDurationMid,
  255. animationTimingFunction: token.motionEaseOutBack,
  256. pointerEvents: 'none',
  257. '&-success': {
  258. color: token.colorSuccess
  259. },
  260. '&-error': {
  261. color: token.colorError
  262. },
  263. '&-warning': {
  264. color: token.colorWarning
  265. },
  266. '&-validating': {
  267. color: token.colorPrimary
  268. }
  269. }
  270. })
  271. };
  272. };
  273. const genHorizontalStyle = token => {
  274. const {
  275. componentCls,
  276. formItemCls,
  277. rootPrefixCls
  278. } = token;
  279. return {
  280. [`${componentCls}-horizontal`]: {
  281. [`${formItemCls}-label`]: {
  282. flexGrow: 0
  283. },
  284. [`${formItemCls}-control`]: {
  285. flex: '1 1 0',
  286. // https://github.com/ant-design/ant-design/issues/32777
  287. // https://github.com/ant-design/ant-design/issues/33773
  288. minWidth: 0
  289. },
  290. // https://github.com/ant-design/ant-design/issues/32980
  291. [`${formItemCls}-label.${rootPrefixCls}-col-24 + ${formItemCls}-control`]: {
  292. minWidth: 'unset'
  293. }
  294. }
  295. };
  296. };
  297. const genInlineStyle = token => {
  298. const {
  299. componentCls,
  300. formItemCls
  301. } = token;
  302. return {
  303. [`${componentCls}-inline`]: {
  304. display: 'flex',
  305. flexWrap: 'wrap',
  306. [formItemCls]: {
  307. flex: 'none',
  308. flexWrap: 'nowrap',
  309. marginInlineEnd: token.margin,
  310. marginBottom: 0,
  311. '&-with-help': {
  312. marginBottom: token.marginLG
  313. },
  314. [`> ${formItemCls}-label,
  315. > ${formItemCls}-control`]: {
  316. display: 'inline-block',
  317. verticalAlign: 'top'
  318. },
  319. [`> ${formItemCls}-label`]: {
  320. flex: 'none'
  321. },
  322. [`${componentCls}-text`]: {
  323. display: 'inline-block'
  324. },
  325. [`${formItemCls}-has-feedback`]: {
  326. display: 'inline-block'
  327. }
  328. }
  329. }
  330. };
  331. };
  332. const makeVerticalLayoutLabel = token => ({
  333. margin: 0,
  334. padding: `0 0 ${token.paddingXS}px`,
  335. whiteSpace: 'initial',
  336. textAlign: 'start',
  337. '> label': {
  338. margin: 0,
  339. '&::after': {
  340. display: 'none'
  341. }
  342. }
  343. });
  344. const makeVerticalLayout = token => {
  345. const {
  346. componentCls,
  347. formItemCls
  348. } = token;
  349. return {
  350. [`${formItemCls} ${formItemCls}-label`]: makeVerticalLayoutLabel(token),
  351. [componentCls]: {
  352. [formItemCls]: {
  353. flexWrap: 'wrap',
  354. [`${formItemCls}-label,
  355. ${formItemCls}-control`]: {
  356. flex: '0 0 100%',
  357. maxWidth: '100%'
  358. }
  359. }
  360. }
  361. };
  362. };
  363. const genVerticalStyle = token => {
  364. const {
  365. componentCls,
  366. formItemCls,
  367. rootPrefixCls
  368. } = token;
  369. return {
  370. [`${componentCls}-vertical`]: {
  371. [formItemCls]: {
  372. '&-row': {
  373. flexDirection: 'column'
  374. },
  375. '&-label > label': {
  376. height: 'auto'
  377. },
  378. [`${componentCls}-item-control`]: {
  379. width: '100%'
  380. }
  381. }
  382. },
  383. [`${componentCls}-vertical ${formItemCls}-label,
  384. .${rootPrefixCls}-col-24${formItemCls}-label,
  385. .${rootPrefixCls}-col-xl-24${formItemCls}-label`]: makeVerticalLayoutLabel(token),
  386. [`@media (max-width: ${token.screenXSMax}px)`]: [makeVerticalLayout(token), {
  387. [componentCls]: {
  388. [`.${rootPrefixCls}-col-xs-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  389. }
  390. }],
  391. [`@media (max-width: ${token.screenSMMax}px)`]: {
  392. [componentCls]: {
  393. [`.${rootPrefixCls}-col-sm-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  394. }
  395. },
  396. [`@media (max-width: ${token.screenMDMax}px)`]: {
  397. [componentCls]: {
  398. [`.${rootPrefixCls}-col-md-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  399. }
  400. },
  401. [`@media (max-width: ${token.screenLGMax}px)`]: {
  402. [componentCls]: {
  403. [`.${rootPrefixCls}-col-lg-24${formItemCls}-label`]: makeVerticalLayoutLabel(token)
  404. }
  405. }
  406. };
  407. };
  408. // ============================== Export ==============================
  409. var _default = exports.default = (0, _internal.genComponentStyleHook)('Form', (token, _ref) => {
  410. let {
  411. rootPrefixCls
  412. } = _ref;
  413. const formToken = (0, _internal.mergeToken)(token, {
  414. formItemCls: `${token.componentCls}-item`,
  415. rootPrefixCls
  416. });
  417. return [genFormStyle(formToken), genFormItemStyle(formToken), (0, _explain.default)(formToken), genHorizontalStyle(formToken), genInlineStyle(formToken), genVerticalStyle(formToken), (0, _motion.genCollapseMotion)(formToken), _motion.zoomIn];
  418. });