index.js 13 KB

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