@alfalab/core-components-number-input 1.3.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/Component.desktop.d.ts +1 -1
  2. package/Component.desktop.js +9 -1
  3. package/Component.mobile.d.ts +1 -1
  4. package/Component.mobile.js +9 -1
  5. package/Component.responsive.d.ts +1 -1
  6. package/Component.responsive.js +14 -1
  7. package/components/number-input/Component.d.ts +21 -46
  8. package/components/number-input/Component.js +97 -84
  9. package/components/number-input/default.css +24 -0
  10. package/components/number-input/index.css +23 -0
  11. package/components/number-input/index.js +8 -0
  12. package/components/number-input/inverted.css +24 -0
  13. package/components/steppers/Component.d.ts +15 -0
  14. package/components/steppers/Component.js +43 -0
  15. package/components/steppers/default.css +20 -0
  16. package/components/steppers/index.css +30 -0
  17. package/components/steppers/index.d.ts +1 -0
  18. package/components/steppers/index.js +15 -0
  19. package/components/steppers/inverted.css +20 -0
  20. package/cssm/Component.desktop.d.ts +1 -1
  21. package/cssm/Component.desktop.js +15 -1
  22. package/cssm/Component.mobile.d.ts +1 -1
  23. package/cssm/Component.mobile.js +15 -1
  24. package/cssm/Component.responsive.d.ts +1 -1
  25. package/cssm/Component.responsive.js +20 -1
  26. package/cssm/components/number-input/Component.d.ts +21 -46
  27. package/cssm/components/number-input/Component.js +97 -84
  28. package/cssm/components/number-input/default.module.css +23 -0
  29. package/cssm/components/number-input/index.js +14 -0
  30. package/cssm/components/number-input/index.module.css +22 -0
  31. package/cssm/components/number-input/inverted.module.css +23 -0
  32. package/cssm/components/steppers/Component.d.ts +15 -0
  33. package/cssm/components/steppers/Component.js +40 -0
  34. package/cssm/components/steppers/default.module.css +19 -0
  35. package/cssm/components/steppers/index.d.ts +1 -0
  36. package/cssm/components/steppers/index.js +18 -0
  37. package/cssm/components/steppers/index.module.css +29 -0
  38. package/cssm/components/steppers/inverted.module.css +19 -0
  39. package/cssm/desktop/index.js +14 -0
  40. package/cssm/index.js +15 -0
  41. package/cssm/mobile/index.js +14 -0
  42. package/cssm/utils.d.ts +19 -9
  43. package/cssm/utils.js +244 -21
  44. package/desktop/index.js +8 -0
  45. package/esm/Component.desktop.d.ts +1 -1
  46. package/esm/Component.desktop.js +9 -1
  47. package/esm/Component.mobile.d.ts +1 -1
  48. package/esm/Component.mobile.js +9 -1
  49. package/esm/Component.responsive.d.ts +1 -1
  50. package/esm/Component.responsive.js +15 -2
  51. package/esm/components/number-input/Component.d.ts +21 -46
  52. package/esm/components/number-input/Component.js +98 -86
  53. package/esm/components/number-input/default.css +24 -0
  54. package/esm/components/number-input/index.css +23 -0
  55. package/esm/components/number-input/index.js +8 -0
  56. package/esm/components/number-input/inverted.css +24 -0
  57. package/esm/components/steppers/Component.d.ts +15 -0
  58. package/esm/components/steppers/Component.js +34 -0
  59. package/esm/components/steppers/default.css +20 -0
  60. package/esm/components/steppers/index.css +30 -0
  61. package/esm/components/steppers/index.d.ts +1 -0
  62. package/esm/components/steppers/index.js +7 -0
  63. package/esm/components/steppers/inverted.css +20 -0
  64. package/esm/desktop/index.js +8 -0
  65. package/esm/index.js +9 -0
  66. package/esm/mobile/index.js +8 -0
  67. package/esm/utils.d.ts +19 -9
  68. package/esm/utils.js +236 -19
  69. package/index.js +9 -0
  70. package/mobile/index.js +8 -0
  71. package/modern/Component.desktop.d.ts +1 -1
  72. package/modern/Component.desktop.js +9 -1
  73. package/modern/Component.mobile.d.ts +1 -1
  74. package/modern/Component.mobile.js +9 -1
  75. package/modern/Component.responsive.d.ts +1 -1
  76. package/modern/Component.responsive.js +13 -1
  77. package/modern/components/number-input/Component.d.ts +21 -46
  78. package/modern/components/number-input/Component.js +94 -86
  79. package/modern/components/number-input/default.css +24 -0
  80. package/modern/components/number-input/index.css +23 -0
  81. package/modern/components/number-input/index.js +8 -0
  82. package/modern/components/number-input/inverted.css +24 -0
  83. package/modern/components/steppers/Component.d.ts +15 -0
  84. package/modern/components/steppers/Component.js +33 -0
  85. package/modern/components/steppers/default.css +20 -0
  86. package/modern/components/steppers/index.css +30 -0
  87. package/modern/components/steppers/index.d.ts +1 -0
  88. package/modern/components/steppers/index.js +7 -0
  89. package/modern/components/steppers/inverted.css +20 -0
  90. package/modern/desktop/index.js +8 -0
  91. package/modern/index.js +9 -0
  92. package/modern/mobile/index.js +8 -0
  93. package/modern/utils.d.ts +19 -9
  94. package/modern/utils.js +223 -18
  95. package/package.json +9 -2
  96. package/src/Component.desktop.tsx +2 -2
  97. package/src/Component.mobile.tsx +2 -2
  98. package/src/Component.responsive.tsx +16 -2
  99. package/src/components/number-input/Component.tsx +204 -128
  100. package/src/components/number-input/default.module.css +10 -0
  101. package/src/components/number-input/index.module.css +9 -0
  102. package/src/components/number-input/inverted.module.css +10 -0
  103. package/src/components/steppers/Component.tsx +75 -0
  104. package/src/components/steppers/default.module.css +5 -0
  105. package/src/components/steppers/index.module.css +20 -0
  106. package/src/components/steppers/index.ts +1 -0
  107. package/src/components/steppers/inverted.module.css +5 -0
  108. package/src/utils.ts +302 -24
  109. package/utils.d.ts +19 -9
  110. package/utils.js +244 -21
@@ -1,99 +1,107 @@
1
- import React, { useRef, useState } from 'react';
1
+ import React, { forwardRef, useMemo, useState, useEffect } from 'react';
2
2
  import mergeRefs from 'react-merge-refs';
3
- import { createSeparatorsRegExp, getAllowedValue, SEPARATORS, SIGNS } from '../../utils.js';
3
+ import { maskitoTransform } from '@maskito/core';
4
+ import { useMaskito } from '@maskito/react';
5
+ import cn from 'classnames';
6
+ import { fnUtils, os } from '@alfalab/core-components-shared/modern';
7
+ import { createMaskOptions, parseNumber, stringifyNumberWithoutExp, MAX_DIGITS, MIN_SAFE_INTEGER, MAX_SAFE_INTEGER, MINUS_SIGN } from '../../utils.js';
8
+ import { Steppers } from '../steppers/Component.js';
9
+ import '@alfalab/core-components-icon-button/modern';
10
+ import '@alfalab/icons-glyph/MinusMIcon';
11
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
4
12
 
5
- const NumberInput = React.forwardRef(({ value: propValue, onChange, onBlur, allowSigns = true, separator = ',', fractionLength, defaultValue, Input, ...restProps }, ref) => {
6
- const uncontrolled = propValue === undefined;
7
- const inputRef = useRef(null);
8
- const [value, setValue] = useState(defaultValue || '');
9
- const getNumberValueFromStr = (valueString) => {
10
- if (valueString === '')
11
- return null;
12
- if (valueString.includes(',')) {
13
- return parseFloat(valueString.replace(',', '.'));
13
+ const defaultColors = {"steppers":"number-input__steppers_vqdas","steppersFocused":"number-input__steppersFocused_vqdas","steppersDisabled":"number-input__steppersDisabled_vqdas"};
14
+ require('./default.css')
15
+
16
+ const styles = {"s":"number-input__s_77v6k","m":"number-input__m_77v6k"};
17
+ require('./index.css')
18
+
19
+ const invertedColors = {"steppers":"number-input__steppers_163tu","steppersFocused":"number-input__steppersFocused_163tu","steppersDisabled":"number-input__steppersDisabled_163tu"};
20
+ require('./inverted.css')
21
+
22
+ const colorStyles = {
23
+ default: defaultColors,
24
+ inverted: invertedColors,
25
+ };
26
+ const NumberInput = forwardRef(({ value: propValue, onChange, separator = ',', fractionLength = MAX_DIGITS, defaultValue, Input, min: minProp, max: maxProp, rightAddons, dataTestId, disabled, onBlur, onFocus, view, step: stepProp, size = 's', disableUserInput, clear: clearProp, colors = 'default', ...restProps }, ref) => {
27
+ const min = Math.max(MIN_SAFE_INTEGER, minProp ?? MIN_SAFE_INTEGER);
28
+ const max = Math.min(MAX_SAFE_INTEGER, maxProp ?? MAX_SAFE_INTEGER);
29
+ const withStepper = stepProp !== undefined;
30
+ const maskOptions = useMemo(() => createMaskOptions({
31
+ separator,
32
+ fractionLength: withStepper ? 0 : fractionLength,
33
+ min,
34
+ max,
35
+ }), [separator, fractionLength, min, max, withStepper]);
36
+ const [focused, setFocused] = useState(false);
37
+ const [value, setValue] = useState(() => {
38
+ if (defaultValue == null) {
39
+ return withStepper ? fnUtils.clamp(0, min, max).toString() : '';
14
40
  }
15
- return parseFloat(valueString);
16
- };
17
- const restoreCaret = (target) => {
18
- setTimeout(() => {
19
- const input = target;
20
- const positionCursor = input.selectionStart || 0;
21
- const isEndPosition = input.value.length === positionCursor;
22
- const enteredSign = SIGNS.some((s) => s === input.value[positionCursor - 1]);
23
- const enteredSeparator = SEPARATORS.filter((s) => s !== separator).some((s) => s === input.value[positionCursor - 1]);
24
- const shouldRestore = enteredSeparator || enteredSign;
25
- if (!isEndPosition && shouldRestore) {
26
- input.selectionStart = positionCursor;
27
- input.selectionEnd = positionCursor;
28
- }
29
- });
30
- };
31
- const handleChange = (event) => {
32
- const input = event.target;
33
- const newValue = input.value.replace(createSeparatorsRegExp(), separator);
34
- const allowedValue = getAllowedValue({
35
- value: newValue,
36
- fractionLength,
37
- allowSigns,
38
- separator,
39
- });
40
- if (onChange) {
41
- onChange(event, {
42
- value: getNumberValueFromStr(allowedValue),
43
- valueString: allowedValue,
41
+ return fnUtils
42
+ .clamp(parseNumber(maskitoTransform(defaultValue.toString(), maskOptions)), min, max)
43
+ .toString();
44
+ });
45
+ const maskRef = useMaskito({ options: maskOptions });
46
+ useEffect(() => {
47
+ if (propValue !== undefined) {
48
+ setValue((prev) => {
49
+ const parsedNumber = parseNumber(propValue);
50
+ if (parsedNumber !== parseNumber(prev)) {
51
+ return maskitoTransform(stringifyNumberWithoutExp(parsedNumber), maskOptions);
52
+ }
53
+ return prev;
44
54
  });
45
55
  }
46
- if (uncontrolled) {
47
- setValue(allowedValue);
48
- }
49
- restoreCaret(input);
50
- };
51
- const handleKeyDown = (event) => {
52
- const disallowedSymbols = /[/|?!@#$%^&*()_=A-Za-zА-Яа-яЁё ]/;
53
- const oneKeyPress = !event.altKey && !event.metaKey && !event.ctrlKey;
54
- const target = event.target;
55
- // Запрещаем вводить неразрешенные символы за исключением комбинаций клавиш
56
- if (oneKeyPress && event.key.length === 1 && disallowedSymbols.test(event.key)) {
57
- return event.preventDefault();
58
- }
59
- const val = target.value;
60
- const hasSeparator = (val.match(createSeparatorsRegExp()) || []).length > 0;
61
- // Запрещаем вводить второй сепаратор
62
- if (hasSeparator && SEPARATORS.some((s) => s === event.key)) {
63
- return event.preventDefault();
64
- }
65
- // Запрещаем вводить лишний знак
66
- if ((!allowSigns || SIGNS.some((s) => s === val[0])) &&
67
- SIGNS.some((s) => s === event.key)) {
68
- return event.preventDefault();
69
- }
70
- const selectionStart = target.selectionStart || 0;
71
- // Запрещаем вводить цифры в дробную часть, если кол-во цифр больше fractionLength
72
- if (hasSeparator &&
73
- fractionLength &&
74
- event.key.length === 1 &&
75
- selectionStart > val.indexOf(separator) &&
76
- val.split(separator)[1].length >= fractionLength) {
77
- return event.preventDefault();
78
- }
79
- return undefined;
56
+ }, [maskOptions, propValue, separator]);
57
+ const getMaxLength = (valueString) => {
58
+ const hasSeparator = valueString?.includes(separator);
59
+ const hasSigns = valueString?.startsWith(MINUS_SIGN);
60
+ return MAX_DIGITS + (hasSeparator ? 1 : 0) + (hasSigns ? 1 : 0);
80
61
  };
81
- const handleBlur = (event) => {
82
- const valueBlur = event.target.value.replace(new RegExp(`\\${separator}$`), '');
83
- if (onChange) {
84
- onChange(event, {
85
- value: getNumberValueFromStr(valueBlur),
86
- valueString: valueBlur,
62
+ const getStep = () => Math.round(stepProp ?? 1);
63
+ const changeValue = (event, newValue) => {
64
+ const isNaNValue = Number.isNaN(newValue);
65
+ const valueString = event?.target.value ?? newValue?.toString() ?? '';
66
+ setValue(valueString);
67
+ if (valueString === '' || !isNaNValue) {
68
+ onChange?.(event, {
69
+ value: isNaNValue ? null : newValue,
87
70
  });
88
71
  }
89
- if (uncontrolled) {
90
- setValue(valueBlur);
72
+ };
73
+ const handleChange = (event) => {
74
+ const valueString = event.target.value;
75
+ changeValue(event, parseNumber(valueString));
76
+ };
77
+ const handleIncrement = () => {
78
+ const parsed = parseNumber(value);
79
+ const nextValue = maskitoTransform((Number.isNaN(parsed) ? min : parsed + getStep()).toString(), maskOptions);
80
+ changeValue(null, parseNumber(nextValue));
81
+ };
82
+ const handleDecrement = () => {
83
+ const parsed = parseNumber(value);
84
+ const nextValue = maskitoTransform((Number.isNaN(parsed) ? max : parsed - getStep()).toString(), maskOptions);
85
+ changeValue(null, parseNumber(nextValue));
86
+ };
87
+ const handleFocus = (e) => {
88
+ onFocus?.(e);
89
+ if (!disableUserInput) {
90
+ setFocused(true);
91
91
  }
92
- if (onBlur)
93
- onBlur(event);
94
92
  };
95
- const visibleValue = uncontrolled ? value : propValue?.toString();
96
- return (React.createElement(Input, { ref: mergeRefs([ref, inputRef]), value: visibleValue, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, inputMode: 'decimal', ...restProps }));
93
+ const handleBlur = (e) => {
94
+ onBlur?.(e);
95
+ setFocused(false);
96
+ };
97
+ return (React.createElement(Input, { maxLength: getMaxLength(value), ...restProps,
98
+ // В iOS в цифровой клавиатуре невозможно ввести минус.
99
+ inputMode: min < 0 && os.isIOS() ? 'text' : 'decimal', ref: mergeRefs([ref, maskRef]), value: value, onInput: handleChange, dataTestId: dataTestId, colors: colors, disabled: disabled, onFocus: handleFocus, onBlur: handleBlur, size: size, disableUserInput: disableUserInput, clear: clearProp && /\d/.test(value), rightAddons: withStepper ? (React.createElement(React.Fragment, null,
100
+ rightAddons,
101
+ React.createElement(Steppers, { colors: colors, dataTestId: dataTestId, disabled: disabled, value: parseNumber(value), min: min, max: max, className: cn(colorStyles[colors].steppers, styles[size], {
102
+ [colorStyles[colors].steppersFocused]: focused,
103
+ [colorStyles[colors].steppersDisabled]: disabled,
104
+ }), onIncrement: handleIncrement, onDecrement: handleDecrement }))) : (rightAddons) }));
97
105
  });
98
106
 
99
107
  export { NumberInput };
@@ -0,0 +1,24 @@
1
+ /* hash: o5lab */
2
+ :root {
3
+ } /* deprecated */ :root {
4
+ --color-light-neutral-1500-inverted: #fff;
5
+ --color-light-neutral-translucent-200: rgba(30, 43, 68, 0.08); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
6
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
7
+ } :root {
8
+ } :root {
9
+
10
+ /* Hard */
11
+
12
+ /* Up */
13
+
14
+ /* Hard up */
15
+ } :root {
16
+ } :root {
17
+ } :root {
18
+ } :root {
19
+ } .number-input__steppers_vqdas {
20
+ background-color: var(--color-light-neutral-1500-inverted);
21
+ } .number-input__steppersFocused_vqdas,
22
+ .number-input__steppersDisabled_vqdas {
23
+ background-color: var(--color-light-neutral-translucent-200);
24
+ }
@@ -0,0 +1,23 @@
1
+ /* hash: bzled */
2
+ :root {
3
+ } /* deprecated */ :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
4
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
5
+ } :root {
6
+ } :root {
7
+
8
+ /* Hard */
9
+
10
+ /* Up */
11
+
12
+ /* Hard up */
13
+ } :root {
14
+ } :root {
15
+ --gap-2xs-neg: -4px;
16
+ --gap-xs-neg: -8px;
17
+ } :root {
18
+ } :root {
19
+ } .number-input__s_77v6k {
20
+ margin-right: var(--gap-xs-neg);
21
+ } .number-input__m_77v6k {
22
+ margin-right: var(--gap-2xs-neg);
23
+ }
@@ -1,4 +1,12 @@
1
1
  export { NumberInput } from './Component.js';
2
2
  import 'react';
3
3
  import 'react-merge-refs';
4
+ import '@maskito/core';
5
+ import '@maskito/react';
6
+ import 'classnames';
7
+ import '@alfalab/core-components-shared/modern';
4
8
  import '../../utils.js';
9
+ import '../steppers/Component.js';
10
+ import '@alfalab/core-components-icon-button/modern';
11
+ import '@alfalab/icons-glyph/MinusMIcon';
12
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
@@ -0,0 +1,24 @@
1
+ /* hash: omvxl */
2
+ :root {
3
+ } /* deprecated */ :root {
4
+ --color-light-neutral-1500: #0e0e0e;
5
+ --color-light-neutral-translucent-300-inverted: rgba(222, 222, 238, 0.13); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
6
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
7
+ } :root {
8
+ } :root {
9
+
10
+ /* Hard */
11
+
12
+ /* Up */
13
+
14
+ /* Hard up */
15
+ } :root {
16
+ } :root {
17
+ } :root {
18
+ } :root {
19
+ } .number-input__steppers_163tu {
20
+ background-color: var(--color-light-neutral-1500);
21
+ } .number-input__steppersFocused_163tu,
22
+ .number-input__steppersDisabled_163tu {
23
+ background-color: var(--color-light-neutral-translucent-300-inverted);
24
+ }
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ type SteppersProps = {
4
+ value: number;
5
+ min: number;
6
+ max: number;
7
+ className?: string;
8
+ disabled?: boolean;
9
+ onIncrement: () => void;
10
+ onDecrement: () => void;
11
+ dataTestId?: string;
12
+ colors: 'default' | 'inverted';
13
+ };
14
+ declare const Steppers: React.FC<SteppersProps>;
15
+ export { SteppersProps, Steppers };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import cn from 'classnames';
3
+ import { IconButton } from '@alfalab/core-components-icon-button/modern';
4
+ import { getDataTestId } from '@alfalab/core-components-shared/modern';
5
+ import { MinusMIcon } from '@alfalab/icons-glyph/MinusMIcon';
6
+ import { PlusMediumMIcon } from '@alfalab/icons-glyph/PlusMediumMIcon';
7
+
8
+ const defaultColors = {"separator":"number-input__separator_1xrwr"};
9
+ require('./default.css')
10
+
11
+ const styles = {"component":"number-input__component_1ab92","separator":"number-input__separator_1ab92","button":"number-input__button_1ab92"};
12
+ require('./index.css')
13
+
14
+ const invertedColors = {"separator":"number-input__separator_1uwaa"};
15
+ require('./inverted.css')
16
+
17
+ const colorStyles = {
18
+ default: defaultColors,
19
+ inverted: invertedColors,
20
+ };
21
+ function preventDefault(e) {
22
+ e.preventDefault();
23
+ }
24
+ const Steppers = ({ className, onIncrement, onDecrement, value, min, max, disabled, dataTestId, colors, }) => {
25
+ const decButtonDisabled = disabled || value <= min;
26
+ const incButtonDisabled = disabled || value >= max;
27
+ return (React.createElement("div", { className: cn(styles.component, className) },
28
+ React.createElement(IconButton, { colors: colors, disabled: decButtonDisabled, className: styles.button, icon: React.createElement(MinusMIcon, null), "aria-label": '\u0443\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C', onMouseDown: preventDefault, onClick: onDecrement, dataTestId: getDataTestId(dataTestId, 'decrement-button'), view: 'secondary' }),
29
+ React.createElement("div", { className: cn(styles.separator, colorStyles[colors].separator) }),
30
+ React.createElement(IconButton, { colors: colors, disabled: incButtonDisabled, className: styles.button, icon: React.createElement(PlusMediumMIcon, null), "aria-label": '\u0443\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C', onMouseDown: preventDefault, onClick: onIncrement, dataTestId: getDataTestId(dataTestId, 'increment-button'), view: 'secondary' })));
31
+ };
32
+
33
+ export { Steppers };
@@ -0,0 +1,20 @@
1
+ /* hash: 306x5 */
2
+ :root {
3
+ } /* deprecated */ :root {
4
+ --color-light-neutral-translucent-300: rgba(15, 25, 55, 0.1); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
5
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
6
+ } :root {
7
+ } :root {
8
+
9
+ /* Hard */
10
+
11
+ /* Up */
12
+
13
+ /* Hard up */
14
+ } :root {
15
+ } :root {
16
+ } :root {
17
+ } :root {
18
+ } .number-input__separator_1xrwr {
19
+ background-color: var(--color-light-neutral-translucent-300);
20
+ }
@@ -0,0 +1,30 @@
1
+ /* hash: 6nhr0 */
2
+ :root {
3
+ } /* deprecated */ :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
4
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
5
+ } :root {
6
+ } :root {
7
+
8
+ /* Hard */
9
+
10
+ /* Up */
11
+
12
+ /* Hard up */
13
+ } :root {
14
+ } :root {
15
+ } :root {
16
+ } :root {
17
+ } .number-input__component_1ab92 {
18
+ display: flex;
19
+ flex-flow: row nowrap;
20
+ align-items: center;
21
+ border-radius: 5px;
22
+ transition: background-color 0.2s ease;
23
+ overflow: visible;
24
+ } .number-input__separator_1ab92 {
25
+ height: 18px;
26
+ width: 1px;
27
+ } .number-input__button_1ab92 {
28
+ width: 40px;
29
+ height: 40px;
30
+ }
@@ -0,0 +1 @@
1
+ export * from "./Component";
@@ -0,0 +1,7 @@
1
+ export { Steppers } from './Component.js';
2
+ import 'react';
3
+ import 'classnames';
4
+ import '@alfalab/core-components-icon-button/modern';
5
+ import '@alfalab/core-components-shared/modern';
6
+ import '@alfalab/icons-glyph/MinusMIcon';
7
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
@@ -0,0 +1,20 @@
1
+ /* hash: 78l4o */
2
+ :root {
3
+ } /* deprecated */ :root {
4
+ --color-light-neutral-translucent-300-inverted: rgba(222, 222, 238, 0.13); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
5
+ } :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
6
+ } :root {
7
+ } :root {
8
+
9
+ /* Hard */
10
+
11
+ /* Up */
12
+
13
+ /* Hard up */
14
+ } :root {
15
+ } :root {
16
+ } :root {
17
+ } :root {
18
+ } .number-input__separator_1uwaa {
19
+ background-color: var(--color-light-neutral-translucent-300-inverted);
20
+ }
@@ -3,4 +3,12 @@ import 'react';
3
3
  import '@alfalab/core-components-input/modern/desktop';
4
4
  import '../components/number-input/Component.js';
5
5
  import 'react-merge-refs';
6
+ import '@maskito/core';
7
+ import '@maskito/react';
8
+ import 'classnames';
9
+ import '@alfalab/core-components-shared/modern';
6
10
  import '../utils.js';
11
+ import '../components/steppers/Component.js';
12
+ import '@alfalab/core-components-icon-button/modern';
13
+ import '@alfalab/icons-glyph/MinusMIcon';
14
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
package/modern/index.js CHANGED
@@ -1,6 +1,15 @@
1
1
  export { NumberInputResponsive as NumberInput } from './Component.responsive.js';
2
2
  import 'react';
3
3
  import '@alfalab/core-components-input/modern';
4
+ import '@alfalab/core-components-mq/modern';
4
5
  import './components/number-input/Component.js';
5
6
  import 'react-merge-refs';
7
+ import '@maskito/core';
8
+ import '@maskito/react';
9
+ import 'classnames';
10
+ import '@alfalab/core-components-shared/modern';
6
11
  import './utils.js';
12
+ import './components/steppers/Component.js';
13
+ import '@alfalab/core-components-icon-button/modern';
14
+ import '@alfalab/icons-glyph/MinusMIcon';
15
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
@@ -3,4 +3,12 @@ import 'react';
3
3
  import '@alfalab/core-components-input/modern/mobile';
4
4
  import '../components/number-input/Component.js';
5
5
  import 'react-merge-refs';
6
+ import '@maskito/core';
7
+ import '@maskito/react';
8
+ import 'classnames';
9
+ import '@alfalab/core-components-shared/modern';
6
10
  import '../utils.js';
11
+ import '../components/steppers/Component.js';
12
+ import '@alfalab/core-components-icon-button/modern';
13
+ import '@alfalab/icons-glyph/MinusMIcon';
14
+ import '@alfalab/icons-glyph/PlusMediumMIcon';
package/modern/utils.d.ts CHANGED
@@ -1,13 +1,23 @@
1
- declare const SIGNS: string[];
1
+ import { MaskitoOptions, MaskitoPlugin } from '@maskito/core';
2
+ declare const MINUS_SIGN = "-";
2
3
  declare const SEPARATORS: string[];
3
- declare function createSeparatorsRegExp(): RegExp;
4
+ declare const MAX_SAFE_INTEGER: number;
5
+ declare const MIN_SAFE_INTEGER: number;
6
+ declare const MAX_DIGITS = 15;
7
+ declare function parseNumber(value?: string | number | null): number;
4
8
  /**
5
- * Проверка вводимых значений.
9
+ * Преобразовать число в строку с заменой экспоненты на десятичную дробь
6
10
  */
7
- declare const getAllowedValue: ({ value, fractionLength, separator, allowSigns, }: {
8
- value: string;
9
- fractionLength?: number | undefined;
11
+ declare function stringifyNumberWithoutExp(value: number): string;
12
+ declare function createMaskOptions({ separator, fractionLength, min, max, }: {
10
13
  separator: string;
11
- allowSigns: boolean;
12
- }) => string;
13
- export { SIGNS, SEPARATORS, createSeparatorsRegExp, getAllowedValue };
14
+ fractionLength: number;
15
+ min: number;
16
+ max: number;
17
+ }): MaskitoOptions;
18
+ declare function createMinMaxPlugin({ min, max }: {
19
+ min: number;
20
+ max: number;
21
+ }): MaskitoPlugin;
22
+ declare function createNotEmptyPartsPlugin(separator: string): MaskitoPlugin;
23
+ export { MINUS_SIGN, SEPARATORS, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, MAX_DIGITS, parseNumber, stringifyNumberWithoutExp, createMaskOptions, createMinMaxPlugin, createNotEmptyPartsPlugin };