index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { clearFix, resetComponent } from '../../style';
  4. import { genCompactItemStyle } from '../../style/compact-item';
  5. export const genPlaceholderStyle = color => ({
  6. // Firefox
  7. '&::-moz-placeholder': {
  8. opacity: 1
  9. },
  10. '&::placeholder': {
  11. color,
  12. userSelect: 'none' // https://github.com/ant-design/ant-design/pull/32639
  13. },
  14. '&:placeholder-shown': {
  15. textOverflow: 'ellipsis'
  16. }
  17. });
  18. export const genHoverStyle = token => ({
  19. borderColor: token.inputBorderHoverColor,
  20. borderInlineEndWidth: token.lineWidth
  21. });
  22. export const genActiveStyle = token => ({
  23. borderColor: token.inputBorderHoverColor,
  24. boxShadow: `0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline}`,
  25. borderInlineEndWidth: token.lineWidth,
  26. outline: 0
  27. });
  28. export const genDisabledStyle = token => ({
  29. color: token.colorTextDisabled,
  30. backgroundColor: token.colorBgContainerDisabled,
  31. borderColor: token.colorBorder,
  32. boxShadow: 'none',
  33. cursor: 'not-allowed',
  34. opacity: 1,
  35. '&:hover': _extends({}, genHoverStyle(mergeToken(token, {
  36. inputBorderHoverColor: token.colorBorder
  37. })))
  38. });
  39. const genInputLargeStyle = token => {
  40. const {
  41. inputPaddingVerticalLG,
  42. fontSizeLG,
  43. lineHeightLG,
  44. borderRadiusLG,
  45. inputPaddingHorizontalLG
  46. } = token;
  47. return {
  48. padding: `${inputPaddingVerticalLG}px ${inputPaddingHorizontalLG}px`,
  49. fontSize: fontSizeLG,
  50. lineHeight: lineHeightLG,
  51. borderRadius: borderRadiusLG
  52. };
  53. };
  54. export const genInputSmallStyle = token => ({
  55. padding: `${token.inputPaddingVerticalSM}px ${token.controlPaddingHorizontalSM - 1}px`,
  56. borderRadius: token.borderRadiusSM
  57. });
  58. export const genStatusStyle = (token, parentCls) => {
  59. const {
  60. componentCls,
  61. colorError,
  62. colorWarning,
  63. colorErrorOutline,
  64. colorWarningOutline,
  65. colorErrorBorderHover,
  66. colorWarningBorderHover
  67. } = token;
  68. return {
  69. [`&-status-error:not(${parentCls}-disabled):not(${parentCls}-borderless)${parentCls}`]: {
  70. borderColor: colorError,
  71. '&:hover': {
  72. borderColor: colorErrorBorderHover
  73. },
  74. '&:focus, &-focused': _extends({}, genActiveStyle(mergeToken(token, {
  75. inputBorderActiveColor: colorError,
  76. inputBorderHoverColor: colorError,
  77. controlOutline: colorErrorOutline
  78. }))),
  79. [`${componentCls}-prefix`]: {
  80. color: colorError
  81. }
  82. },
  83. [`&-status-warning:not(${parentCls}-disabled):not(${parentCls}-borderless)${parentCls}`]: {
  84. borderColor: colorWarning,
  85. '&:hover': {
  86. borderColor: colorWarningBorderHover
  87. },
  88. '&:focus, &-focused': _extends({}, genActiveStyle(mergeToken(token, {
  89. inputBorderActiveColor: colorWarning,
  90. inputBorderHoverColor: colorWarning,
  91. controlOutline: colorWarningOutline
  92. }))),
  93. [`${componentCls}-prefix`]: {
  94. color: colorWarning
  95. }
  96. }
  97. };
  98. };
  99. export const genBasicInputStyle = token => _extends(_extends({
  100. position: 'relative',
  101. display: 'inline-block',
  102. width: '100%',
  103. minWidth: 0,
  104. padding: `${token.inputPaddingVertical}px ${token.inputPaddingHorizontal}px`,
  105. color: token.colorText,
  106. fontSize: token.fontSize,
  107. lineHeight: token.lineHeight,
  108. backgroundColor: token.colorBgContainer,
  109. backgroundImage: 'none',
  110. borderWidth: token.lineWidth,
  111. borderStyle: token.lineType,
  112. borderColor: token.colorBorder,
  113. borderRadius: token.borderRadius,
  114. transition: `all ${token.motionDurationMid}`
  115. }, genPlaceholderStyle(token.colorTextPlaceholder)), {
  116. '&:hover': _extends({}, genHoverStyle(token)),
  117. '&:focus, &-focused': _extends({}, genActiveStyle(token)),
  118. '&-disabled, &[disabled]': _extends({}, genDisabledStyle(token)),
  119. '&-borderless': {
  120. '&, &:hover, &:focus, &-focused, &-disabled, &[disabled]': {
  121. backgroundColor: 'transparent',
  122. border: 'none',
  123. boxShadow: 'none'
  124. }
  125. },
  126. // Reset height for `textarea`s
  127. 'textarea&': {
  128. maxWidth: '100%',
  129. height: 'auto',
  130. minHeight: token.controlHeight,
  131. lineHeight: token.lineHeight,
  132. verticalAlign: 'bottom',
  133. transition: `all ${token.motionDurationSlow}, height 0s`,
  134. resize: 'vertical'
  135. },
  136. // Size
  137. '&-lg': _extends({}, genInputLargeStyle(token)),
  138. '&-sm': _extends({}, genInputSmallStyle(token)),
  139. // RTL
  140. '&-rtl': {
  141. direction: 'rtl'
  142. },
  143. '&-textarea-rtl': {
  144. direction: 'rtl'
  145. }
  146. });
  147. export const genInputGroupStyle = token => {
  148. const {
  149. componentCls,
  150. antCls
  151. } = token;
  152. return {
  153. position: 'relative',
  154. display: 'table',
  155. width: '100%',
  156. borderCollapse: 'separate',
  157. borderSpacing: 0,
  158. // Undo padding and float of grid classes
  159. [`&[class*='col-']`]: {
  160. paddingInlineEnd: token.paddingXS,
  161. '&:last-child': {
  162. paddingInlineEnd: 0
  163. }
  164. },
  165. // Sizing options
  166. [`&-lg ${componentCls}, &-lg > ${componentCls}-group-addon`]: _extends({}, genInputLargeStyle(token)),
  167. [`&-sm ${componentCls}, &-sm > ${componentCls}-group-addon`]: _extends({}, genInputSmallStyle(token)),
  168. [`> ${componentCls}`]: {
  169. display: 'table-cell',
  170. '&:not(:first-child):not(:last-child)': {
  171. borderRadius: 0
  172. }
  173. },
  174. [`${componentCls}-group`]: {
  175. [`&-addon, &-wrap`]: {
  176. display: 'table-cell',
  177. width: 1,
  178. whiteSpace: 'nowrap',
  179. verticalAlign: 'middle',
  180. '&:not(:first-child):not(:last-child)': {
  181. borderRadius: 0
  182. }
  183. },
  184. '&-wrap > *': {
  185. display: 'block !important'
  186. },
  187. '&-addon': {
  188. position: 'relative',
  189. padding: `0 ${token.inputPaddingHorizontal}px`,
  190. color: token.colorText,
  191. fontWeight: 'normal',
  192. fontSize: token.fontSize,
  193. textAlign: 'center',
  194. backgroundColor: token.colorFillAlter,
  195. border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
  196. borderRadius: token.borderRadius,
  197. transition: `all ${token.motionDurationSlow}`,
  198. lineHeight: 1,
  199. // Reset Select's style in addon
  200. [`${antCls}-select`]: {
  201. margin: `-${token.inputPaddingVertical + 1}px -${token.inputPaddingHorizontal}px`,
  202. [`&${antCls}-select-single:not(${antCls}-select-customize-input)`]: {
  203. [`${antCls}-select-selector`]: {
  204. backgroundColor: 'inherit',
  205. border: `${token.lineWidth}px ${token.lineType} transparent`,
  206. boxShadow: 'none'
  207. }
  208. },
  209. '&-open, &-focused': {
  210. [`${antCls}-select-selector`]: {
  211. color: token.colorPrimary
  212. }
  213. }
  214. },
  215. // https://github.com/ant-design/ant-design/issues/31333
  216. [`${antCls}-cascader-picker`]: {
  217. margin: `-9px -${token.inputPaddingHorizontal}px`,
  218. backgroundColor: 'transparent',
  219. [`${antCls}-cascader-input`]: {
  220. textAlign: 'start',
  221. border: 0,
  222. boxShadow: 'none'
  223. }
  224. }
  225. },
  226. '&-addon:first-child': {
  227. borderInlineEnd: 0
  228. },
  229. '&-addon:last-child': {
  230. borderInlineStart: 0
  231. }
  232. },
  233. [`${componentCls}`]: {
  234. float: 'inline-start',
  235. width: '100%',
  236. marginBottom: 0,
  237. textAlign: 'inherit',
  238. '&:focus': {
  239. zIndex: 1,
  240. borderInlineEndWidth: 1
  241. },
  242. '&:hover': {
  243. zIndex: 1,
  244. borderInlineEndWidth: 1,
  245. [`${componentCls}-search-with-button &`]: {
  246. zIndex: 0
  247. }
  248. }
  249. },
  250. // Reset rounded corners
  251. [`> ${componentCls}:first-child, ${componentCls}-group-addon:first-child`]: {
  252. borderStartEndRadius: 0,
  253. borderEndEndRadius: 0,
  254. // Reset Select's style in addon
  255. [`${antCls}-select ${antCls}-select-selector`]: {
  256. borderStartEndRadius: 0,
  257. borderEndEndRadius: 0
  258. }
  259. },
  260. [`> ${componentCls}-affix-wrapper`]: {
  261. [`&:not(:first-child) ${componentCls}`]: {
  262. borderStartStartRadius: 0,
  263. borderEndStartRadius: 0
  264. },
  265. [`&:not(:last-child) ${componentCls}`]: {
  266. borderStartEndRadius: 0,
  267. borderEndEndRadius: 0
  268. }
  269. },
  270. [`> ${componentCls}:last-child, ${componentCls}-group-addon:last-child`]: {
  271. borderStartStartRadius: 0,
  272. borderEndStartRadius: 0,
  273. // Reset Select's style in addon
  274. [`${antCls}-select ${antCls}-select-selector`]: {
  275. borderStartStartRadius: 0,
  276. borderEndStartRadius: 0
  277. }
  278. },
  279. [`${componentCls}-affix-wrapper`]: {
  280. '&:not(:last-child)': {
  281. borderStartEndRadius: 0,
  282. borderEndEndRadius: 0,
  283. [`${componentCls}-search &`]: {
  284. borderStartStartRadius: token.borderRadius,
  285. borderEndStartRadius: token.borderRadius
  286. }
  287. },
  288. [`&:not(:first-child), ${componentCls}-search &:not(:first-child)`]: {
  289. borderStartStartRadius: 0,
  290. borderEndStartRadius: 0
  291. }
  292. },
  293. [`&${componentCls}-group-compact`]: _extends(_extends({
  294. display: 'block'
  295. }, clearFix()), {
  296. [`${componentCls}-group-addon, ${componentCls}-group-wrap, > ${componentCls}`]: {
  297. '&:not(:first-child):not(:last-child)': {
  298. borderInlineEndWidth: token.lineWidth,
  299. '&:hover': {
  300. zIndex: 1
  301. },
  302. '&:focus': {
  303. zIndex: 1
  304. }
  305. }
  306. },
  307. '& > *': {
  308. display: 'inline-block',
  309. float: 'none',
  310. verticalAlign: 'top',
  311. borderRadius: 0
  312. },
  313. [`& > ${componentCls}-affix-wrapper`]: {
  314. display: 'inline-flex'
  315. },
  316. [`& > ${antCls}-picker-range`]: {
  317. display: 'inline-flex'
  318. },
  319. '& > *:not(:last-child)': {
  320. marginInlineEnd: -token.lineWidth,
  321. borderInlineEndWidth: token.lineWidth
  322. },
  323. // Undo float for .ant-input-group .ant-input
  324. [`${componentCls}`]: {
  325. float: 'none'
  326. },
  327. // reset border for Select, DatePicker, AutoComplete, Cascader, Mention, TimePicker, Input
  328. [`& > ${antCls}-select > ${antCls}-select-selector,
  329. & > ${antCls}-select-auto-complete ${componentCls},
  330. & > ${antCls}-cascader-picker ${componentCls},
  331. & > ${componentCls}-group-wrapper ${componentCls}`]: {
  332. borderInlineEndWidth: token.lineWidth,
  333. borderRadius: 0,
  334. '&:hover': {
  335. zIndex: 1
  336. },
  337. '&:focus': {
  338. zIndex: 1
  339. }
  340. },
  341. [`& > ${antCls}-select-focused`]: {
  342. zIndex: 1
  343. },
  344. // update z-index for arrow icon
  345. [`& > ${antCls}-select > ${antCls}-select-arrow`]: {
  346. zIndex: 1 // https://github.com/ant-design/ant-design/issues/20371
  347. },
  348. [`& > *:first-child,
  349. & > ${antCls}-select:first-child > ${antCls}-select-selector,
  350. & > ${antCls}-select-auto-complete:first-child ${componentCls},
  351. & > ${antCls}-cascader-picker:first-child ${componentCls}`]: {
  352. borderStartStartRadius: token.borderRadius,
  353. borderEndStartRadius: token.borderRadius
  354. },
  355. [`& > *:last-child,
  356. & > ${antCls}-select:last-child > ${antCls}-select-selector,
  357. & > ${antCls}-cascader-picker:last-child ${componentCls},
  358. & > ${antCls}-cascader-picker-focused:last-child ${componentCls}`]: {
  359. borderInlineEndWidth: token.lineWidth,
  360. borderStartEndRadius: token.borderRadius,
  361. borderEndEndRadius: token.borderRadius
  362. },
  363. // https://github.com/ant-design/ant-design/issues/12493
  364. [`& > ${antCls}-select-auto-complete ${componentCls}`]: {
  365. verticalAlign: 'top'
  366. },
  367. [`${componentCls}-group-wrapper + ${componentCls}-group-wrapper`]: {
  368. marginInlineStart: -token.lineWidth,
  369. [`${componentCls}-affix-wrapper`]: {
  370. borderRadius: 0
  371. }
  372. },
  373. [`${componentCls}-group-wrapper:not(:last-child)`]: {
  374. [`&${componentCls}-search > ${componentCls}-group`]: {
  375. [`& > ${componentCls}-group-addon > ${componentCls}-search-button`]: {
  376. borderRadius: 0
  377. },
  378. [`& > ${componentCls}`]: {
  379. borderStartStartRadius: token.borderRadius,
  380. borderStartEndRadius: 0,
  381. borderEndEndRadius: 0,
  382. borderEndStartRadius: token.borderRadius
  383. }
  384. }
  385. }
  386. }),
  387. [`&&-sm ${antCls}-btn`]: {
  388. fontSize: token.fontSizeSM,
  389. height: token.controlHeightSM,
  390. lineHeight: 'normal'
  391. },
  392. [`&&-lg ${antCls}-btn`]: {
  393. fontSize: token.fontSizeLG,
  394. height: token.controlHeightLG,
  395. lineHeight: 'normal'
  396. },
  397. // Fix https://github.com/ant-design/ant-design/issues/5754
  398. [`&&-lg ${antCls}-select-single ${antCls}-select-selector`]: {
  399. height: `${token.controlHeightLG}px`,
  400. [`${antCls}-select-selection-item, ${antCls}-select-selection-placeholder`]: {
  401. // -2 is for the border size & override default
  402. lineHeight: `${token.controlHeightLG - 2}px`
  403. },
  404. [`${antCls}-select-selection-search-input`]: {
  405. height: `${token.controlHeightLG}px`
  406. }
  407. },
  408. [`&&-sm ${antCls}-select-single ${antCls}-select-selector`]: {
  409. height: `${token.controlHeightSM}px`,
  410. [`${antCls}-select-selection-item, ${antCls}-select-selection-placeholder`]: {
  411. // -2 is for the border size & override default
  412. lineHeight: `${token.controlHeightSM - 2}px`
  413. },
  414. [`${antCls}-select-selection-search-input`]: {
  415. height: `${token.controlHeightSM}px`
  416. }
  417. }
  418. };
  419. };
  420. const genInputStyle = token => {
  421. const {
  422. componentCls,
  423. controlHeightSM,
  424. lineWidth
  425. } = token;
  426. const FIXED_CHROME_COLOR_HEIGHT = 16;
  427. const colorSmallPadding = (controlHeightSM - lineWidth * 2 - FIXED_CHROME_COLOR_HEIGHT) / 2;
  428. return {
  429. [componentCls]: _extends(_extends(_extends(_extends({}, resetComponent(token)), genBasicInputStyle(token)), genStatusStyle(token, componentCls)), {
  430. '&[type="color"]': {
  431. height: token.controlHeight,
  432. [`&${componentCls}-lg`]: {
  433. height: token.controlHeightLG
  434. },
  435. [`&${componentCls}-sm`]: {
  436. height: controlHeightSM,
  437. paddingTop: colorSmallPadding,
  438. paddingBottom: colorSmallPadding
  439. }
  440. }
  441. })
  442. };
  443. };
  444. const genAllowClearStyle = token => {
  445. const {
  446. componentCls
  447. } = token;
  448. return {
  449. // ========================= Input =========================
  450. [`${componentCls}-clear-icon`]: {
  451. margin: 0,
  452. color: token.colorTextQuaternary,
  453. fontSize: token.fontSizeIcon,
  454. verticalAlign: -1,
  455. // https://github.com/ant-design/ant-design/pull/18151
  456. // https://codesandbox.io/s/wizardly-sun-u10br
  457. cursor: 'pointer',
  458. transition: `color ${token.motionDurationSlow}`,
  459. '&:hover': {
  460. color: token.colorTextTertiary
  461. },
  462. '&:active': {
  463. color: token.colorText
  464. },
  465. '&-hidden': {
  466. visibility: 'hidden'
  467. },
  468. '&-has-suffix': {
  469. margin: `0 ${token.inputAffixPadding}px`
  470. }
  471. },
  472. // ======================= TextArea ========================
  473. '&-textarea-with-clear-btn': {
  474. padding: '0 !important',
  475. border: '0 !important',
  476. [`${componentCls}-clear-icon`]: {
  477. position: 'absolute',
  478. insetBlockStart: token.paddingXS,
  479. insetInlineEnd: token.paddingXS,
  480. zIndex: 1
  481. }
  482. }
  483. };
  484. };
  485. const genAffixStyle = token => {
  486. const {
  487. componentCls,
  488. inputAffixPadding,
  489. colorTextDescription,
  490. motionDurationSlow,
  491. colorIcon,
  492. colorIconHover,
  493. iconCls
  494. } = token;
  495. return {
  496. [`${componentCls}-affix-wrapper`]: _extends(_extends(_extends(_extends(_extends({}, genBasicInputStyle(token)), {
  497. display: 'inline-flex',
  498. [`&:not(${componentCls}-affix-wrapper-disabled):hover`]: _extends(_extends({}, genHoverStyle(token)), {
  499. zIndex: 1,
  500. [`${componentCls}-search-with-button &`]: {
  501. zIndex: 0
  502. }
  503. }),
  504. '&-focused, &:focus': {
  505. zIndex: 1
  506. },
  507. '&-disabled': {
  508. [`${componentCls}[disabled]`]: {
  509. background: 'transparent'
  510. }
  511. },
  512. [`> input${componentCls}`]: {
  513. padding: 0,
  514. fontSize: 'inherit',
  515. border: 'none',
  516. borderRadius: 0,
  517. outline: 'none',
  518. '&:focus': {
  519. boxShadow: 'none !important'
  520. }
  521. },
  522. '&::before': {
  523. width: 0,
  524. visibility: 'hidden',
  525. content: '"\\a0"'
  526. },
  527. [`${componentCls}`]: {
  528. '&-prefix, &-suffix': {
  529. display: 'flex',
  530. flex: 'none',
  531. alignItems: 'center',
  532. '> *:not(:last-child)': {
  533. marginInlineEnd: token.paddingXS
  534. }
  535. },
  536. '&-show-count-suffix': {
  537. color: colorTextDescription
  538. },
  539. '&-show-count-has-suffix': {
  540. marginInlineEnd: token.paddingXXS
  541. },
  542. '&-prefix': {
  543. marginInlineEnd: inputAffixPadding
  544. },
  545. '&-suffix': {
  546. marginInlineStart: inputAffixPadding
  547. }
  548. }
  549. }), genAllowClearStyle(token)), {
  550. // password
  551. [`${iconCls}${componentCls}-password-icon`]: {
  552. color: colorIcon,
  553. cursor: 'pointer',
  554. transition: `all ${motionDurationSlow}`,
  555. '&:hover': {
  556. color: colorIconHover
  557. }
  558. }
  559. }), genStatusStyle(token, `${componentCls}-affix-wrapper`))
  560. };
  561. };
  562. const genGroupStyle = token => {
  563. const {
  564. componentCls,
  565. colorError,
  566. colorSuccess,
  567. borderRadiusLG,
  568. borderRadiusSM
  569. } = token;
  570. return {
  571. [`${componentCls}-group`]: _extends(_extends(_extends({}, resetComponent(token)), genInputGroupStyle(token)), {
  572. '&-rtl': {
  573. direction: 'rtl'
  574. },
  575. '&-wrapper': {
  576. display: 'inline-block',
  577. width: '100%',
  578. textAlign: 'start',
  579. verticalAlign: 'top',
  580. '&-rtl': {
  581. direction: 'rtl'
  582. },
  583. // Size
  584. '&-lg': {
  585. [`${componentCls}-group-addon`]: {
  586. borderRadius: borderRadiusLG
  587. }
  588. },
  589. '&-sm': {
  590. [`${componentCls}-group-addon`]: {
  591. borderRadius: borderRadiusSM
  592. }
  593. },
  594. // Status
  595. '&-status-error': {
  596. [`${componentCls}-group-addon`]: {
  597. color: colorError,
  598. borderColor: colorError
  599. }
  600. },
  601. '&-status-warning': {
  602. [`${componentCls}-group-addon:last-child`]: {
  603. color: colorSuccess,
  604. borderColor: colorSuccess
  605. }
  606. }
  607. }
  608. })
  609. };
  610. };
  611. const genSearchInputStyle = token => {
  612. const {
  613. componentCls,
  614. antCls
  615. } = token;
  616. const searchPrefixCls = `${componentCls}-search`;
  617. return {
  618. [searchPrefixCls]: {
  619. [`${componentCls}`]: {
  620. '&:hover, &:focus': {
  621. borderColor: token.colorPrimaryHover,
  622. [`+ ${componentCls}-group-addon ${searchPrefixCls}-button:not(${antCls}-btn-primary)`]: {
  623. borderInlineStartColor: token.colorPrimaryHover
  624. }
  625. }
  626. },
  627. [`${componentCls}-affix-wrapper`]: {
  628. borderRadius: 0
  629. },
  630. // fix slight height diff in Firefox:
  631. // https://ant.design/components/auto-complete-cn/#components-auto-complete-demo-certain-category
  632. [`${componentCls}-lg`]: {
  633. lineHeight: token.lineHeightLG - 0.0002
  634. },
  635. [`> ${componentCls}-group`]: {
  636. [`> ${componentCls}-group-addon:last-child`]: {
  637. insetInlineStart: -1,
  638. padding: 0,
  639. border: 0,
  640. [`${searchPrefixCls}-button`]: {
  641. paddingTop: 0,
  642. paddingBottom: 0,
  643. borderStartStartRadius: 0,
  644. borderStartEndRadius: token.borderRadius,
  645. borderEndEndRadius: token.borderRadius,
  646. borderEndStartRadius: 0
  647. },
  648. [`${searchPrefixCls}-button:not(${antCls}-btn-primary)`]: {
  649. color: token.colorTextDescription,
  650. '&:hover': {
  651. color: token.colorPrimaryHover
  652. },
  653. '&:active': {
  654. color: token.colorPrimaryActive
  655. },
  656. [`&${antCls}-btn-loading::before`]: {
  657. insetInlineStart: 0,
  658. insetInlineEnd: 0,
  659. insetBlockStart: 0,
  660. insetBlockEnd: 0
  661. }
  662. }
  663. }
  664. },
  665. [`${searchPrefixCls}-button`]: {
  666. height: token.controlHeight,
  667. '&:hover, &:focus': {
  668. zIndex: 1
  669. }
  670. },
  671. [`&-large ${searchPrefixCls}-button`]: {
  672. height: token.controlHeightLG
  673. },
  674. [`&-small ${searchPrefixCls}-button`]: {
  675. height: token.controlHeightSM
  676. },
  677. '&-rtl': {
  678. direction: 'rtl'
  679. },
  680. // ===================== Compact Item Customized Styles =====================
  681. [`&${componentCls}-compact-item`]: {
  682. [`&:not(${componentCls}-compact-last-item)`]: {
  683. [`${componentCls}-group-addon`]: {
  684. [`${componentCls}-search-button`]: {
  685. marginInlineEnd: -token.lineWidth,
  686. borderRadius: 0
  687. }
  688. }
  689. },
  690. [`&:not(${componentCls}-compact-first-item)`]: {
  691. [`${componentCls},${componentCls}-affix-wrapper`]: {
  692. borderRadius: 0
  693. }
  694. },
  695. [`> ${componentCls}-group-addon ${componentCls}-search-button,
  696. > ${componentCls},
  697. ${componentCls}-affix-wrapper`]: {
  698. '&:hover,&:focus,&:active': {
  699. zIndex: 2
  700. }
  701. },
  702. [`> ${componentCls}-affix-wrapper-focused`]: {
  703. zIndex: 2
  704. }
  705. }
  706. }
  707. };
  708. };
  709. export function initInputToken(token) {
  710. // @ts-ignore
  711. return mergeToken(token, {
  712. inputAffixPadding: token.paddingXXS,
  713. inputPaddingVertical: Math.max(Math.round((token.controlHeight - token.fontSize * token.lineHeight) / 2 * 10) / 10 - token.lineWidth, 3),
  714. inputPaddingVerticalLG: Math.ceil((token.controlHeightLG - token.fontSizeLG * token.lineHeightLG) / 2 * 10) / 10 - token.lineWidth,
  715. inputPaddingVerticalSM: Math.max(Math.round((token.controlHeightSM - token.fontSize * token.lineHeight) / 2 * 10) / 10 - token.lineWidth, 0),
  716. inputPaddingHorizontal: token.paddingSM - token.lineWidth,
  717. inputPaddingHorizontalSM: token.paddingXS - token.lineWidth,
  718. inputPaddingHorizontalLG: token.controlPaddingHorizontal - token.lineWidth,
  719. inputBorderHoverColor: token.colorPrimaryHover,
  720. inputBorderActiveColor: token.colorPrimaryHover
  721. });
  722. }
  723. const genTextAreaStyle = token => {
  724. const {
  725. componentCls,
  726. inputPaddingHorizontal,
  727. paddingLG
  728. } = token;
  729. const textareaPrefixCls = `${componentCls}-textarea`;
  730. return {
  731. [textareaPrefixCls]: {
  732. position: 'relative',
  733. [`${textareaPrefixCls}-suffix`]: {
  734. position: 'absolute',
  735. top: 0,
  736. insetInlineEnd: inputPaddingHorizontal,
  737. bottom: 0,
  738. zIndex: 1,
  739. display: 'inline-flex',
  740. alignItems: 'center',
  741. margin: 'auto'
  742. },
  743. [`&-status-error,
  744. &-status-warning,
  745. &-status-success,
  746. &-status-validating`]: {
  747. [`&${textareaPrefixCls}-has-feedback`]: {
  748. [`${componentCls}`]: {
  749. paddingInlineEnd: paddingLG
  750. }
  751. }
  752. },
  753. '&-show-count': {
  754. // https://github.com/ant-design/ant-design/issues/33049
  755. [`> ${componentCls}`]: {
  756. height: '100%'
  757. },
  758. '&::after': {
  759. color: token.colorTextDescription,
  760. whiteSpace: 'nowrap',
  761. content: 'attr(data-count)',
  762. pointerEvents: 'none',
  763. float: 'right'
  764. }
  765. },
  766. '&-rtl': {
  767. '&::after': {
  768. float: 'left'
  769. }
  770. }
  771. }
  772. };
  773. };
  774. // ============================== Export ==============================
  775. export default genComponentStyleHook('Input', token => {
  776. const inputToken = initInputToken(token);
  777. return [genInputStyle(inputToken), genTextAreaStyle(inputToken), genAffixStyle(inputToken), genGroupStyle(inputToken), genSearchInputStyle(inputToken),
  778. // =====================================================
  779. // == Space Compact ==
  780. // =====================================================
  781. genCompactItemStyle(inputToken)];
  782. });