index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genActiveStyle, genBasicInputStyle, genDisabledStyle, genHoverStyle, genInputGroupStyle, genPlaceholderStyle, genStatusStyle, initInputToken } from '../../input/style';
  3. import { genComponentStyleHook } from '../../theme/internal';
  4. import { resetComponent, resetIcon } from '../../style';
  5. import { genCompactItemStyle } from '../../style/compact-item';
  6. const genInputNumberStyles = token => {
  7. const {
  8. componentCls,
  9. lineWidth,
  10. lineType,
  11. colorBorder,
  12. borderRadius,
  13. fontSizeLG,
  14. controlHeightLG,
  15. controlHeightSM,
  16. colorError,
  17. inputPaddingHorizontalSM,
  18. colorTextDescription,
  19. motionDurationMid,
  20. colorPrimary,
  21. controlHeight,
  22. inputPaddingHorizontal,
  23. colorBgContainer,
  24. colorTextDisabled,
  25. borderRadiusSM,
  26. borderRadiusLG,
  27. controlWidth,
  28. handleVisible
  29. } = token;
  30. return [{
  31. [componentCls]: _extends(_extends(_extends(_extends({}, resetComponent(token)), genBasicInputStyle(token)), genStatusStyle(token, componentCls)), {
  32. display: 'inline-block',
  33. width: controlWidth,
  34. margin: 0,
  35. padding: 0,
  36. border: `${lineWidth}px ${lineType} ${colorBorder}`,
  37. borderRadius,
  38. '&-rtl': {
  39. direction: 'rtl',
  40. [`${componentCls}-input`]: {
  41. direction: 'rtl'
  42. }
  43. },
  44. '&-lg': {
  45. padding: 0,
  46. fontSize: fontSizeLG,
  47. borderRadius: borderRadiusLG,
  48. [`input${componentCls}-input`]: {
  49. height: controlHeightLG - 2 * lineWidth
  50. }
  51. },
  52. '&-sm': {
  53. padding: 0,
  54. borderRadius: borderRadiusSM,
  55. [`input${componentCls}-input`]: {
  56. height: controlHeightSM - 2 * lineWidth,
  57. padding: `0 ${inputPaddingHorizontalSM}px`
  58. }
  59. },
  60. '&:hover': _extends({}, genHoverStyle(token)),
  61. '&-focused': _extends({}, genActiveStyle(token)),
  62. '&-disabled': _extends(_extends({}, genDisabledStyle(token)), {
  63. [`${componentCls}-input`]: {
  64. cursor: 'not-allowed'
  65. }
  66. }),
  67. // ===================== Out Of Range =====================
  68. '&-out-of-range': {
  69. input: {
  70. color: colorError
  71. }
  72. },
  73. // Style for input-group: input with label, with button or dropdown...
  74. '&-group': _extends(_extends(_extends({}, resetComponent(token)), genInputGroupStyle(token)), {
  75. '&-wrapper': {
  76. display: 'inline-block',
  77. textAlign: 'start',
  78. verticalAlign: 'top',
  79. [`${componentCls}-affix-wrapper`]: {
  80. width: '100%'
  81. },
  82. // Size
  83. '&-lg': {
  84. [`${componentCls}-group-addon`]: {
  85. borderRadius: borderRadiusLG
  86. }
  87. },
  88. '&-sm': {
  89. [`${componentCls}-group-addon`]: {
  90. borderRadius: borderRadiusSM
  91. }
  92. }
  93. }
  94. }),
  95. [componentCls]: {
  96. '&-input': _extends(_extends({
  97. width: '100%',
  98. height: controlHeight - 2 * lineWidth,
  99. padding: `0 ${inputPaddingHorizontal}px`,
  100. textAlign: 'start',
  101. backgroundColor: 'transparent',
  102. border: 0,
  103. borderRadius,
  104. outline: 0,
  105. transition: `all ${motionDurationMid} linear`,
  106. appearance: 'textfield',
  107. color: token.colorText,
  108. fontSize: 'inherit',
  109. verticalAlign: 'top'
  110. }, genPlaceholderStyle(token.colorTextPlaceholder)), {
  111. '&[type="number"]::-webkit-inner-spin-button, &[type="number"]::-webkit-outer-spin-button': {
  112. margin: 0,
  113. /* stylelint-disable-next-line property-no-vendor-prefix */
  114. webkitAppearance: 'none',
  115. appearance: 'none'
  116. }
  117. })
  118. }
  119. })
  120. },
  121. // Handler
  122. {
  123. [componentCls]: {
  124. [`&:hover ${componentCls}-handler-wrap, &-focused ${componentCls}-handler-wrap`]: {
  125. opacity: 1
  126. },
  127. [`${componentCls}-handler-wrap`]: {
  128. position: 'absolute',
  129. insetBlockStart: 0,
  130. insetInlineEnd: 0,
  131. width: token.handleWidth,
  132. height: '100%',
  133. background: colorBgContainer,
  134. borderStartStartRadius: 0,
  135. borderStartEndRadius: borderRadius,
  136. borderEndEndRadius: borderRadius,
  137. borderEndStartRadius: 0,
  138. opacity: handleVisible === true ? 1 : 0,
  139. display: 'flex',
  140. flexDirection: 'column',
  141. alignItems: 'stretch',
  142. transition: `opacity ${motionDurationMid} linear ${motionDurationMid}`,
  143. // Fix input number inside Menu makes icon too large
  144. // We arise the selector priority by nest selector here
  145. // https://github.com/ant-design/ant-design/issues/14367
  146. [`${componentCls}-handler`]: {
  147. display: 'flex',
  148. alignItems: 'center',
  149. justifyContent: 'center',
  150. flex: 'auto',
  151. height: '40%',
  152. [`
  153. ${componentCls}-handler-up-inner,
  154. ${componentCls}-handler-down-inner
  155. `]: {
  156. marginInlineEnd: 0,
  157. fontSize: token.handleFontSize
  158. }
  159. }
  160. },
  161. [`${componentCls}-handler`]: {
  162. height: '50%',
  163. overflow: 'hidden',
  164. color: colorTextDescription,
  165. fontWeight: 'bold',
  166. lineHeight: 0,
  167. textAlign: 'center',
  168. cursor: 'pointer',
  169. borderInlineStart: `${lineWidth}px ${lineType} ${colorBorder}`,
  170. transition: `all ${motionDurationMid} linear`,
  171. '&:active': {
  172. background: token.colorFillAlter
  173. },
  174. // Hover
  175. '&:hover': {
  176. height: `60%`,
  177. [`
  178. ${componentCls}-handler-up-inner,
  179. ${componentCls}-handler-down-inner
  180. `]: {
  181. color: colorPrimary
  182. }
  183. },
  184. '&-up-inner, &-down-inner': _extends(_extends({}, resetIcon()), {
  185. color: colorTextDescription,
  186. transition: `all ${motionDurationMid} linear`,
  187. userSelect: 'none'
  188. })
  189. },
  190. [`${componentCls}-handler-up`]: {
  191. borderStartEndRadius: borderRadius
  192. },
  193. [`${componentCls}-handler-down`]: {
  194. borderBlockStart: `${lineWidth}px ${lineType} ${colorBorder}`,
  195. borderEndEndRadius: borderRadius
  196. },
  197. // Disabled
  198. '&-disabled, &-readonly': {
  199. [`${componentCls}-handler-wrap`]: {
  200. display: 'none'
  201. }
  202. },
  203. [`
  204. ${componentCls}-handler-up-disabled,
  205. ${componentCls}-handler-down-disabled
  206. `]: {
  207. cursor: 'not-allowed'
  208. },
  209. [`
  210. ${componentCls}-handler-up-disabled:hover &-handler-up-inner,
  211. ${componentCls}-handler-down-disabled:hover &-handler-down-inner
  212. `]: {
  213. color: colorTextDisabled
  214. }
  215. }
  216. },
  217. // Border-less
  218. {
  219. [`${componentCls}-borderless`]: {
  220. borderColor: 'transparent',
  221. boxShadow: 'none',
  222. [`${componentCls}-handler-down`]: {
  223. borderBlockStartWidth: 0
  224. }
  225. }
  226. }];
  227. };
  228. const genAffixWrapperStyles = token => {
  229. const {
  230. componentCls,
  231. inputPaddingHorizontal,
  232. inputAffixPadding,
  233. controlWidth,
  234. borderRadiusLG,
  235. borderRadiusSM
  236. } = token;
  237. return {
  238. [`${componentCls}-affix-wrapper`]: _extends(_extends(_extends({}, genBasicInputStyle(token)), genStatusStyle(token, `${componentCls}-affix-wrapper`)), {
  239. // or number handler will cover form status
  240. position: 'relative',
  241. display: 'inline-flex',
  242. width: controlWidth,
  243. padding: 0,
  244. paddingInlineStart: inputPaddingHorizontal,
  245. '&-lg': {
  246. borderRadius: borderRadiusLG
  247. },
  248. '&-sm': {
  249. borderRadius: borderRadiusSM
  250. },
  251. [`&:not(${componentCls}-affix-wrapper-disabled):hover`]: _extends(_extends({}, genHoverStyle(token)), {
  252. zIndex: 1
  253. }),
  254. '&-focused, &:focus': {
  255. zIndex: 1
  256. },
  257. '&-disabled': {
  258. [`${componentCls}[disabled]`]: {
  259. background: 'transparent'
  260. }
  261. },
  262. [`> div${componentCls}`]: {
  263. width: '100%',
  264. border: 'none',
  265. outline: 'none',
  266. [`&${componentCls}-focused`]: {
  267. boxShadow: 'none !important'
  268. }
  269. },
  270. [`input${componentCls}-input`]: {
  271. padding: 0
  272. },
  273. '&::before': {
  274. width: 0,
  275. visibility: 'hidden',
  276. content: '"\\a0"'
  277. },
  278. [`${componentCls}-handler-wrap`]: {
  279. zIndex: 2
  280. },
  281. [componentCls]: {
  282. '&-prefix, &-suffix': {
  283. display: 'flex',
  284. flex: 'none',
  285. alignItems: 'center',
  286. pointerEvents: 'none'
  287. },
  288. '&-prefix': {
  289. marginInlineEnd: inputAffixPadding
  290. },
  291. '&-suffix': {
  292. position: 'absolute',
  293. insetBlockStart: 0,
  294. insetInlineEnd: 0,
  295. zIndex: 1,
  296. height: '100%',
  297. marginInlineEnd: inputPaddingHorizontal,
  298. marginInlineStart: inputAffixPadding
  299. }
  300. }
  301. })
  302. };
  303. };
  304. // ============================== Export ==============================
  305. export default genComponentStyleHook('InputNumber', token => {
  306. const inputNumberToken = initInputToken(token);
  307. return [genInputNumberStyles(inputNumberToken), genAffixWrapperStyles(inputNumberToken),
  308. // =====================================================
  309. // == Space Compact ==
  310. // =====================================================
  311. genCompactItemStyle(inputNumberToken)];
  312. }, token => ({
  313. controlWidth: 90,
  314. handleWidth: token.controlHeightSM - token.lineWidth * 2,
  315. handleFontSize: token.fontSize / 2,
  316. handleVisible: 'auto'
  317. }));