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