@snack-uikit/fields 0.17.10 → 0.17.11
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.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.17.11 (2024-03-21)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-0000:** field stepper step buttons ([cdb4f9f](https://github.com/cloud-ru-tech/snack-uikit/commit/cdb4f9ff0c9d315d69afe05ff893c121bec7e821))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.17.10 (2024-03-19)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -365,8 +365,8 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
365
365
|
| name | `string` | - | Значение html-атрибута name |
|
|
366
366
|
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
367
367
|
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
368
|
-
| min | `number` |
|
|
369
|
-
| max | `number` |
|
|
368
|
+
| min | `number` | Number.NEGATIVE_INFINITY | Минимальное значение поля |
|
|
369
|
+
| max | `number` | Number.POSITIVE_INFINITY | Максимальное значение поля |
|
|
370
370
|
| error | `string` | - | |
|
|
371
371
|
| className | `string` | - | CSS-класс |
|
|
372
372
|
| label | `string` | - | Лейбл |
|
|
@@ -24,12 +24,21 @@ import { useValueControl } from '../../hooks';
|
|
|
24
24
|
import { FieldDecorator } from '../FieldDecorator';
|
|
25
25
|
import styles from './styles.module.css';
|
|
26
26
|
const TOOLTIP_TIMEOUT = 2000;
|
|
27
|
+
const getDefaultValue = (min, max) => {
|
|
28
|
+
if (min > 0) {
|
|
29
|
+
return min;
|
|
30
|
+
}
|
|
31
|
+
if (max < 0) {
|
|
32
|
+
return max;
|
|
33
|
+
}
|
|
34
|
+
return 0;
|
|
35
|
+
};
|
|
27
36
|
export const FieldStepper = forwardRef((_a, ref) => {
|
|
28
|
-
var { id, name, value: valueProp, min, max, step = 1, disabled = false, readonly = false, allowMoreThanLimits = true, onChange: onChangeProp, onFocus, onBlur, className, label, labelTooltip, labelTooltipPlacement, required = false, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, error } = _a, rest = __rest(_a, ["id", "name", "value", "min", "max", "step", "disabled", "readonly", "allowMoreThanLimits", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "hint", "showHintIcon", "size", "validationState", "error"]);
|
|
37
|
+
var { id, name, value: valueProp, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step = 1, disabled = false, readonly = false, allowMoreThanLimits = true, onChange: onChangeProp, onFocus, onBlur, className, label, labelTooltip, labelTooltipPlacement, required = false, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, error } = _a, rest = __rest(_a, ["id", "name", "value", "min", "max", "step", "disabled", "readonly", "allowMoreThanLimits", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "hint", "showHintIcon", "size", "validationState", "error"]);
|
|
29
38
|
const { t } = useLocale('Fields');
|
|
30
39
|
const [value = 0, setValue] = useValueControl({
|
|
31
40
|
value: valueProp,
|
|
32
|
-
defaultValue:
|
|
41
|
+
defaultValue: getDefaultValue(min, max),
|
|
33
42
|
onChange: onChangeProp,
|
|
34
43
|
});
|
|
35
44
|
const [tooltipOpen, setTooltipOpen] = useState(false);
|
|
@@ -86,12 +95,12 @@ export const FieldStepper = forwardRef((_a, ref) => {
|
|
|
86
95
|
const handleMinusButtonClick = (e) => {
|
|
87
96
|
e.preventDefault();
|
|
88
97
|
e.stopPropagation();
|
|
89
|
-
setValue(min
|
|
98
|
+
setValue(Math.min(Math.max(min, value - step), max));
|
|
90
99
|
};
|
|
91
100
|
const handlePlusButtonClick = (e) => {
|
|
92
101
|
e.preventDefault();
|
|
93
102
|
e.stopPropagation();
|
|
94
|
-
setValue(max
|
|
103
|
+
setValue(Math.max(Math.min(max, value + step), min));
|
|
95
104
|
};
|
|
96
105
|
const handleMinusButtonKeyDown = event => {
|
|
97
106
|
var _a;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.17.
|
|
7
|
+
"version": "0.17.11",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@snack-uikit/locale": "*"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "e6879c2667509b3e11bf66ce025ac3e687828898"
|
|
60
60
|
}
|
|
@@ -57,14 +57,26 @@ export type FieldStepperProps = WithSupportProps<FieldStepperOwnProps & InputPro
|
|
|
57
57
|
|
|
58
58
|
const TOOLTIP_TIMEOUT = 2000;
|
|
59
59
|
|
|
60
|
+
const getDefaultValue = (min: number, max: number) => {
|
|
61
|
+
if (min > 0) {
|
|
62
|
+
return min;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (max < 0) {
|
|
66
|
+
return max;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
60
72
|
export const FieldStepper = forwardRef<HTMLInputElement, FieldStepperProps>(
|
|
61
73
|
(
|
|
62
74
|
{
|
|
63
75
|
id,
|
|
64
76
|
name,
|
|
65
77
|
value: valueProp,
|
|
66
|
-
min,
|
|
67
|
-
max,
|
|
78
|
+
min = Number.NEGATIVE_INFINITY,
|
|
79
|
+
max = Number.POSITIVE_INFINITY,
|
|
68
80
|
step = 1,
|
|
69
81
|
disabled = false,
|
|
70
82
|
readonly = false,
|
|
@@ -89,7 +101,7 @@ export const FieldStepper = forwardRef<HTMLInputElement, FieldStepperProps>(
|
|
|
89
101
|
const { t } = useLocale('Fields');
|
|
90
102
|
const [value = 0, setValue] = useValueControl<number>({
|
|
91
103
|
value: valueProp,
|
|
92
|
-
defaultValue:
|
|
104
|
+
defaultValue: getDefaultValue(min, max),
|
|
93
105
|
onChange: onChangeProp,
|
|
94
106
|
});
|
|
95
107
|
const [tooltipOpen, setTooltipOpen] = useState(false);
|
|
@@ -161,13 +173,13 @@ export const FieldStepper = forwardRef<HTMLInputElement, FieldStepperProps>(
|
|
|
161
173
|
const handleMinusButtonClick = (e: MouseEvent) => {
|
|
162
174
|
e.preventDefault();
|
|
163
175
|
e.stopPropagation();
|
|
164
|
-
setValue(min
|
|
176
|
+
setValue(Math.min(Math.max(min, value - step), max));
|
|
165
177
|
};
|
|
166
178
|
|
|
167
179
|
const handlePlusButtonClick = (e: MouseEvent) => {
|
|
168
180
|
e.preventDefault();
|
|
169
181
|
e.stopPropagation();
|
|
170
|
-
setValue(max
|
|
182
|
+
setValue(Math.max(Math.min(max, value + step), min));
|
|
171
183
|
};
|
|
172
184
|
|
|
173
185
|
const handleMinusButtonKeyDown: KeyboardEventHandler<HTMLInputElement> = event => {
|