index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genBasicInputStyle, genInputGroupStyle, genPlaceholderStyle, initInputToken } from '../../input/style';
  3. import { genBorderlessStyle, genFilledGroupStyle, genFilledStyle, genOutlinedGroupStyle, genOutlinedStyle, genUnderlinedStyle } from '../../input/style/variants';
  4. import { resetComponent, resetIcon } from '../../style';
  5. import { genCompactItemStyle } from '../../style/compact-item';
  6. import { genStyleHooks, mergeToken } from '../../theme/internal';
  7. import { prepareComponentToken } from './token';
  8. export const genRadiusStyle = ({
  9. componentCls,
  10. borderRadiusSM,
  11. borderRadiusLG
  12. }, size) => {
  13. const borderRadius = size === 'lg' ? borderRadiusLG : borderRadiusSM;
  14. return {
  15. [`&-${size}`]: {
  16. [`${componentCls}-handler-wrap`]: {
  17. borderStartEndRadius: borderRadius,
  18. borderEndEndRadius: borderRadius
  19. },
  20. [`${componentCls}-handler-up`]: {
  21. borderStartEndRadius: borderRadius
  22. },
  23. [`${componentCls}-handler-down`]: {
  24. borderEndEndRadius: borderRadius
  25. }
  26. }
  27. };
  28. };
  29. const genInputNumberStyles = token => {
  30. const {
  31. componentCls,
  32. lineWidth,
  33. lineType,
  34. borderRadius,
  35. inputFontSizeSM,
  36. inputFontSizeLG,
  37. controlHeightLG,
  38. controlHeightSM,
  39. colorError,
  40. paddingInlineSM,
  41. paddingBlockSM,
  42. paddingBlockLG,
  43. paddingInlineLG,
  44. colorIcon,
  45. motionDurationMid,
  46. handleHoverColor,
  47. handleOpacity,
  48. paddingInline,
  49. paddingBlock,
  50. handleBg,
  51. handleActiveBg,
  52. colorTextDisabled,
  53. borderRadiusSM,
  54. borderRadiusLG,
  55. controlWidth,
  56. handleBorderColor,
  57. filledHandleBg,
  58. lineHeightLG,
  59. calc
  60. } = token;
  61. return [{
  62. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genBasicInputStyle(token)), {
  63. display: 'inline-block',
  64. width: controlWidth,
  65. margin: 0,
  66. padding: 0,
  67. borderRadius
  68. }), genOutlinedStyle(token, {
  69. [`${componentCls}-handler-wrap`]: {
  70. background: handleBg,
  71. [`${componentCls}-handler-down`]: {
  72. borderBlockStart: `${unit(lineWidth)} ${lineType} ${handleBorderColor}`
  73. }
  74. }
  75. })), genFilledStyle(token, {
  76. [`${componentCls}-handler-wrap`]: {
  77. background: filledHandleBg,
  78. [`${componentCls}-handler-down`]: {
  79. borderBlockStart: `${unit(lineWidth)} ${lineType} ${handleBorderColor}`
  80. }
  81. },
  82. '&:focus-within': {
  83. [`${componentCls}-handler-wrap`]: {
  84. background: handleBg
  85. }
  86. }
  87. })), genUnderlinedStyle(token, {
  88. [`${componentCls}-handler-wrap`]: {
  89. background: handleBg,
  90. [`${componentCls}-handler-down`]: {
  91. borderBlockStart: `${unit(lineWidth)} ${lineType} ${handleBorderColor}`
  92. }
  93. }
  94. })), genBorderlessStyle(token)), {
  95. '&-rtl': {
  96. direction: 'rtl',
  97. [`${componentCls}-input`]: {
  98. direction: 'rtl'
  99. }
  100. },
  101. '&-lg': {
  102. padding: 0,
  103. fontSize: inputFontSizeLG,
  104. lineHeight: lineHeightLG,
  105. borderRadius: borderRadiusLG,
  106. [`input${componentCls}-input`]: {
  107. height: calc(controlHeightLG).sub(calc(lineWidth).mul(2)).equal(),
  108. padding: `${unit(paddingBlockLG)} ${unit(paddingInlineLG)}`
  109. }
  110. },
  111. '&-sm': {
  112. padding: 0,
  113. fontSize: inputFontSizeSM,
  114. borderRadius: borderRadiusSM,
  115. [`input${componentCls}-input`]: {
  116. height: calc(controlHeightSM).sub(calc(lineWidth).mul(2)).equal(),
  117. padding: `${unit(paddingBlockSM)} ${unit(paddingInlineSM)}`
  118. }
  119. },
  120. // ===================== Out Of Range =====================
  121. '&-out-of-range': {
  122. [`${componentCls}-input-wrap`]: {
  123. input: {
  124. color: colorError
  125. }
  126. }
  127. },
  128. // Style for input-group: input with label, with button or dropdown...
  129. '&-group': Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genInputGroupStyle(token)), {
  130. '&-wrapper': Object.assign(Object.assign(Object.assign({
  131. display: 'inline-block',
  132. textAlign: 'start',
  133. verticalAlign: 'top',
  134. [`${componentCls}-affix-wrapper`]: {
  135. width: '100%'
  136. },
  137. // Size
  138. '&-lg': {
  139. [`${componentCls}-group-addon`]: {
  140. borderRadius: borderRadiusLG,
  141. fontSize: token.fontSizeLG
  142. }
  143. },
  144. '&-sm': {
  145. [`${componentCls}-group-addon`]: {
  146. borderRadius: borderRadiusSM
  147. }
  148. }
  149. }, genOutlinedGroupStyle(token)), genFilledGroupStyle(token)), {
  150. // Fix the issue of using icons in Space Compact mode
  151. // https://github.com/ant-design/ant-design/issues/45764
  152. [`&:not(${componentCls}-compact-first-item):not(${componentCls}-compact-last-item)${componentCls}-compact-item`]: {
  153. [`${componentCls}, ${componentCls}-group-addon`]: {
  154. borderRadius: 0
  155. }
  156. },
  157. [`&:not(${componentCls}-compact-last-item)${componentCls}-compact-first-item`]: {
  158. [`${componentCls}, ${componentCls}-group-addon`]: {
  159. borderStartEndRadius: 0,
  160. borderEndEndRadius: 0
  161. }
  162. },
  163. [`&:not(${componentCls}-compact-first-item)${componentCls}-compact-last-item`]: {
  164. [`${componentCls}, ${componentCls}-group-addon`]: {
  165. borderStartStartRadius: 0,
  166. borderEndStartRadius: 0
  167. }
  168. }
  169. })
  170. }),
  171. [`&-disabled ${componentCls}-input`]: {
  172. cursor: 'not-allowed'
  173. },
  174. [componentCls]: {
  175. '&-input': Object.assign(Object.assign(Object.assign(Object.assign({}, resetComponent(token)), {
  176. width: '100%',
  177. padding: `${unit(paddingBlock)} ${unit(paddingInline)}`,
  178. textAlign: 'start',
  179. backgroundColor: 'transparent',
  180. border: 0,
  181. borderRadius,
  182. outline: 0,
  183. transition: `all ${motionDurationMid} linear`,
  184. appearance: 'textfield',
  185. fontSize: 'inherit'
  186. }), genPlaceholderStyle(token.colorTextPlaceholder)), {
  187. '&[type="number"]::-webkit-inner-spin-button, &[type="number"]::-webkit-outer-spin-button': {
  188. margin: 0,
  189. appearance: 'none'
  190. }
  191. })
  192. },
  193. [`&:hover ${componentCls}-handler-wrap, &-focused ${componentCls}-handler-wrap`]: {
  194. width: token.handleWidth,
  195. opacity: 1
  196. }
  197. })
  198. },
  199. // Handler
  200. {
  201. [componentCls]: Object.assign(Object.assign(Object.assign({
  202. [`${componentCls}-handler-wrap`]: {
  203. position: 'absolute',
  204. insetBlockStart: 0,
  205. insetInlineEnd: 0,
  206. width: token.handleVisibleWidth,
  207. opacity: handleOpacity,
  208. height: '100%',
  209. borderStartStartRadius: 0,
  210. borderStartEndRadius: borderRadius,
  211. borderEndEndRadius: borderRadius,
  212. borderEndStartRadius: 0,
  213. display: 'flex',
  214. flexDirection: 'column',
  215. alignItems: 'stretch',
  216. transition: `all ${motionDurationMid}`,
  217. overflow: 'hidden',
  218. // Fix input number inside Menu makes icon too large
  219. // We arise the selector priority by nest selector here
  220. // https://github.com/ant-design/ant-design/issues/14367
  221. [`${componentCls}-handler`]: {
  222. display: 'flex',
  223. alignItems: 'center',
  224. justifyContent: 'center',
  225. flex: 'auto',
  226. height: '40%',
  227. [`
  228. ${componentCls}-handler-up-inner,
  229. ${componentCls}-handler-down-inner
  230. `]: {
  231. marginInlineEnd: 0,
  232. fontSize: token.handleFontSize
  233. }
  234. }
  235. },
  236. [`${componentCls}-handler`]: {
  237. height: '50%',
  238. overflow: 'hidden',
  239. color: colorIcon,
  240. fontWeight: 'bold',
  241. lineHeight: 0,
  242. textAlign: 'center',
  243. cursor: 'pointer',
  244. borderInlineStart: `${unit(lineWidth)} ${lineType} ${handleBorderColor}`,
  245. transition: `all ${motionDurationMid} linear`,
  246. '&:active': {
  247. background: handleActiveBg
  248. },
  249. // Hover
  250. '&:hover': {
  251. height: `60%`,
  252. [`
  253. ${componentCls}-handler-up-inner,
  254. ${componentCls}-handler-down-inner
  255. `]: {
  256. color: handleHoverColor
  257. }
  258. },
  259. '&-up-inner, &-down-inner': Object.assign(Object.assign({}, resetIcon()), {
  260. color: colorIcon,
  261. transition: `all ${motionDurationMid} linear`,
  262. userSelect: 'none'
  263. })
  264. },
  265. [`${componentCls}-handler-up`]: {
  266. borderStartEndRadius: borderRadius
  267. },
  268. [`${componentCls}-handler-down`]: {
  269. borderEndEndRadius: borderRadius
  270. }
  271. }, genRadiusStyle(token, 'lg')), genRadiusStyle(token, 'sm')), {
  272. // Disabled
  273. '&-disabled, &-readonly': {
  274. [`${componentCls}-handler-wrap`]: {
  275. display: 'none'
  276. },
  277. [`${componentCls}-input`]: {
  278. color: 'inherit'
  279. }
  280. },
  281. [`
  282. ${componentCls}-handler-up-disabled,
  283. ${componentCls}-handler-down-disabled
  284. `]: {
  285. cursor: 'not-allowed'
  286. },
  287. [`
  288. ${componentCls}-handler-up-disabled:hover &-handler-up-inner,
  289. ${componentCls}-handler-down-disabled:hover &-handler-down-inner
  290. `]: {
  291. color: colorTextDisabled
  292. }
  293. })
  294. }];
  295. };
  296. const genAffixWrapperStyles = token => {
  297. const {
  298. componentCls,
  299. paddingBlock,
  300. paddingInline,
  301. inputAffixPadding,
  302. controlWidth,
  303. borderRadiusLG,
  304. borderRadiusSM,
  305. paddingInlineLG,
  306. paddingInlineSM,
  307. paddingBlockLG,
  308. paddingBlockSM,
  309. motionDurationMid
  310. } = token;
  311. return {
  312. [`${componentCls}-affix-wrapper`]: Object.assign(Object.assign({
  313. [`input${componentCls}-input`]: {
  314. padding: `${unit(paddingBlock)} 0`
  315. }
  316. }, genBasicInputStyle(token)), {
  317. // or number handler will cover form status
  318. position: 'relative',
  319. display: 'inline-flex',
  320. alignItems: 'center',
  321. width: controlWidth,
  322. padding: 0,
  323. paddingInlineStart: paddingInline,
  324. '&-lg': {
  325. borderRadius: borderRadiusLG,
  326. paddingInlineStart: paddingInlineLG,
  327. [`input${componentCls}-input`]: {
  328. padding: `${unit(paddingBlockLG)} 0`
  329. }
  330. },
  331. '&-sm': {
  332. borderRadius: borderRadiusSM,
  333. paddingInlineStart: paddingInlineSM,
  334. [`input${componentCls}-input`]: {
  335. padding: `${unit(paddingBlockSM)} 0`
  336. }
  337. },
  338. [`&:not(${componentCls}-disabled):hover`]: {
  339. zIndex: 1
  340. },
  341. '&-focused, &:focus': {
  342. zIndex: 1
  343. },
  344. [`&-disabled > ${componentCls}-disabled`]: {
  345. background: 'transparent'
  346. },
  347. [`> div${componentCls}`]: {
  348. width: '100%',
  349. border: 'none',
  350. outline: 'none',
  351. [`&${componentCls}-focused`]: {
  352. boxShadow: 'none !important'
  353. }
  354. },
  355. '&::before': {
  356. display: 'inline-block',
  357. width: 0,
  358. visibility: 'hidden',
  359. content: '"\\a0"'
  360. },
  361. [`${componentCls}-handler-wrap`]: {
  362. zIndex: 2
  363. },
  364. [componentCls]: {
  365. position: 'static',
  366. color: 'inherit',
  367. '&-prefix, &-suffix': {
  368. display: 'flex',
  369. flex: 'none',
  370. alignItems: 'center',
  371. pointerEvents: 'none'
  372. },
  373. '&-prefix': {
  374. marginInlineEnd: inputAffixPadding
  375. },
  376. '&-suffix': {
  377. insetBlockStart: 0,
  378. insetInlineEnd: 0,
  379. height: '100%',
  380. marginInlineEnd: paddingInline,
  381. marginInlineStart: inputAffixPadding,
  382. transition: `margin ${motionDurationMid}`
  383. }
  384. },
  385. [`&:hover ${componentCls}-handler-wrap, &-focused ${componentCls}-handler-wrap`]: {
  386. width: token.handleWidth,
  387. opacity: 1
  388. },
  389. [`&:not(${componentCls}-affix-wrapper-without-controls):hover ${componentCls}-suffix`]: {
  390. marginInlineEnd: token.calc(token.handleWidth).add(paddingInline).equal()
  391. }
  392. }),
  393. // 覆盖 affix-wrapper borderRadius!
  394. [`${componentCls}-underlined`]: {
  395. borderRadius: 0
  396. }
  397. };
  398. };
  399. export default genStyleHooks('InputNumber', token => {
  400. const inputNumberToken = mergeToken(token, initInputToken(token));
  401. return [genInputNumberStyles(inputNumberToken), genAffixWrapperStyles(inputNumberToken),
  402. // =====================================================
  403. // == Space Compact ==
  404. // =====================================================
  405. genCompactItemStyle(inputNumberToken)];
  406. }, prepareComponentToken, {
  407. unitless: {
  408. handleOpacity: true
  409. },
  410. resetFont: false
  411. });