index.js 10 KB

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