@snack-uikit/fields 0.42.0 → 0.42.2-preview-b28bfeb6.0

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.42.1 (2025-05-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **PDS-2180:** added float support for slider field ([2c2986b](https://github.com/cloud-ru-tech/snack-uikit/commit/2c2986b1ac81034feb1cd38a7d9ea98188354007))
12
+
13
+
14
+
15
+
16
+
6
17
  # 0.42.0 (2025-04-23)
7
18
 
8
19
 
@@ -109,11 +109,6 @@ exports.FieldSelectMultiple = (0, react_1.forwardRef)((props, ref) => {
109
109
  postfix,
110
110
  disabled
111
111
  });
112
- (0, react_1.useEffect)(() => {
113
- if (options.length === 0 && value && value.length > 0) {
114
- setValue(undefined);
115
- }
116
- }, [options.length, setValue, value]);
117
112
  (0, utils_1.useLayoutEffect)(() => {
118
113
  setItems(_ref => {
119
114
  let {
@@ -107,11 +107,6 @@ exports.FieldSelectSingle = (0, react_1.forwardRef)((props, ref) => {
107
107
  postfix,
108
108
  disabled
109
109
  });
110
- (0, react_1.useEffect)(() => {
111
- if (options.length < 1 && Boolean(value)) {
112
- setValue(undefined);
113
- }
114
- }, [options.length, setValue, value]);
115
110
  (0, utils_1.useLayoutEffect)(() => {
116
111
  setItems(_ref => {
117
112
  let {
@@ -157,7 +152,7 @@ exports.FieldSelectSingle = (0, react_1.forwardRef)((props, ref) => {
157
152
  } = (0, hooks_2.useButtons)({
158
153
  readonly,
159
154
  size,
160
- showClearButton: showClearButton && !disabled && !readonly && value !== undefined,
155
+ showClearButton: showClearButton && !disabled && !readonly && value !== undefined && selectedItem !== undefined,
161
156
  showCopyButton,
162
157
  inputRef: localRef,
163
158
  onClear,
@@ -94,7 +94,7 @@ exports.FieldSlider = (0, react_1.forwardRef)((_a, ref) => {
94
94
  }, [marks]);
95
95
  const hasMarksEqualToValues = (0, react_1.useMemo)(() => Object.keys(marks).every(key => key === getMarkValue(key)), [getMarkValue, marks]);
96
96
  const onTextFieldChange = textFieldValue => {
97
- const numValue = parseInt(textFieldValue);
97
+ const numValue = parseFloat(textFieldValue);
98
98
  if (textFieldValue && Number.isNaN(numValue)) {
99
99
  return;
100
100
  }
@@ -107,15 +107,15 @@ exports.FieldSlider = (0, react_1.forwardRef)((_a, ref) => {
107
107
  };
108
108
  const allowedValues = Object.keys(marks).map(key => ({
109
109
  key,
110
- value: parseInt(String(getMarkValue(key)))
110
+ value: parseFloat(String(getMarkValue(key)))
111
111
  }));
112
112
  const suitableEntry = allowedValues.find(entry => entry.value === textFieldNumValue);
113
113
  if (suitableEntry) {
114
114
  handleChange(suitableEntry.key);
115
115
  return;
116
116
  }
117
- const actualMin = parseInt(String(getMarkValue(min)));
118
- const actualMax = parseInt(String(getMarkValue(max)));
117
+ const actualMin = parseFloat(String(getMarkValue(min)));
118
+ const actualMax = parseFloat(String(getMarkValue(max)));
119
119
  if (textFieldNumValue < actualMin) {
120
120
  handleChange(min);
121
121
  return;
@@ -169,8 +169,8 @@ exports.FieldSlider = (0, react_1.forwardRef)((_a, ref) => {
169
169
  if (range) {
170
170
  return;
171
171
  }
172
- const parsedValue = parseInt(textFieldInputValue);
173
- const actualMinByMark = parseInt(String(getMarkValue(min)));
172
+ const parsedValue = parseFloat(textFieldInputValue);
173
+ const actualMinByMark = parseFloat(String(getMarkValue(min)));
174
174
  const actualMin = Number.isNaN(actualMinByMark) ? min : actualMinByMark;
175
175
  const textFieldNumValue = textFieldInputValue ? parsedValue : actualMin;
176
176
  if (Number.isNaN(textFieldNumValue)) {
@@ -8,7 +8,7 @@ const generateAllowedValues = (min, max, step) => {
8
8
  const values = [];
9
9
  let current = min;
10
10
  while (current <= max) {
11
- values.push(current);
11
+ values.push(parseFloat(current.toFixed(10)));
12
12
  current += step;
13
13
  }
14
14
  return values;
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import mergeRefs from 'merge-refs';
15
- import { forwardRef, useEffect, useRef, useState } from 'react';
15
+ import { forwardRef, useRef, useState } from 'react';
16
16
  import { InputPrivate } from '@snack-uikit/input-private';
17
17
  import { Droplist } from '@snack-uikit/list';
18
18
  import { Tag } from '@snack-uikit/tag';
@@ -47,11 +47,6 @@ export const FieldSelectMultiple = forwardRef((props, ref) => {
47
47
  resetSearchOnOptionSelection }));
48
48
  const prefixSettings = usePrefix({ prefix, disabled });
49
49
  const postfixSettings = usePostfix({ postfix, disabled });
50
- useEffect(() => {
51
- if (options.length === 0 && value && value.length > 0) {
52
- setValue(undefined);
53
- }
54
- }, [options.length, setValue, value]);
55
50
  useLayoutEffect(() => {
56
51
  setItems(({ selectedItems }) => updateMultipleItems({ options, value, selectedItems }));
57
52
  }, [options, value]);
@@ -43,11 +43,6 @@ export const FieldSelectSingle = forwardRef((props, ref) => {
43
43
  const prevSelectedItem = useRef(selectedItem);
44
44
  const prefixSettings = usePrefix({ prefix, disabled });
45
45
  const postfixSettings = usePostfix({ postfix, disabled });
46
- useEffect(() => {
47
- if (options.length < 1 && Boolean(value)) {
48
- setValue(undefined);
49
- }
50
- }, [options.length, setValue, value]);
51
46
  useLayoutEffect(() => {
52
47
  setItems(({ selectedItem }) => updateItems({ options, value, selectedItem }));
53
48
  }, [options, value]);
@@ -75,7 +70,7 @@ export const FieldSelectSingle = forwardRef((props, ref) => {
75
70
  const { postfixButtons, inputKeyDownNavigationHandler, buttonsRefs } = useButtons({
76
71
  readonly,
77
72
  size,
78
- showClearButton: showClearButton && !disabled && !readonly && value !== undefined,
73
+ showClearButton: showClearButton && !disabled && !readonly && value !== undefined && selectedItem !== undefined,
79
74
  showCopyButton,
80
75
  inputRef: localRef,
81
76
  onClear,
@@ -50,7 +50,7 @@ export const FieldSlider = forwardRef((_a, ref) => {
50
50
  }, [marks]);
51
51
  const hasMarksEqualToValues = useMemo(() => Object.keys(marks).every(key => key === getMarkValue(key)), [getMarkValue, marks]);
52
52
  const onTextFieldChange = (textFieldValue) => {
53
- const numValue = parseInt(textFieldValue);
53
+ const numValue = parseFloat(textFieldValue);
54
54
  if (textFieldValue && Number.isNaN(numValue)) {
55
55
  return;
56
56
  }
@@ -63,15 +63,15 @@ export const FieldSlider = forwardRef((_a, ref) => {
63
63
  };
64
64
  const allowedValues = Object.keys(marks).map(key => ({
65
65
  key,
66
- value: parseInt(String(getMarkValue(key))),
66
+ value: parseFloat(String(getMarkValue(key))),
67
67
  }));
68
68
  const suitableEntry = allowedValues.find(entry => entry.value === textFieldNumValue);
69
69
  if (suitableEntry) {
70
70
  handleChange(suitableEntry.key);
71
71
  return;
72
72
  }
73
- const actualMin = parseInt(String(getMarkValue(min)));
74
- const actualMax = parseInt(String(getMarkValue(max)));
73
+ const actualMin = parseFloat(String(getMarkValue(min)));
74
+ const actualMax = parseFloat(String(getMarkValue(max)));
75
75
  if (textFieldNumValue < actualMin) {
76
76
  handleChange(min);
77
77
  return;
@@ -119,8 +119,8 @@ export const FieldSlider = forwardRef((_a, ref) => {
119
119
  if (range) {
120
120
  return;
121
121
  }
122
- const parsedValue = parseInt(textFieldInputValue);
123
- const actualMinByMark = parseInt(String(getMarkValue(min)));
122
+ const parsedValue = parseFloat(textFieldInputValue);
123
+ const actualMinByMark = parseFloat(String(getMarkValue(min)));
124
124
  const actualMin = Number.isNaN(actualMinByMark) ? min : actualMinByMark;
125
125
  const textFieldNumValue = textFieldInputValue ? parsedValue : actualMin;
126
126
  if (Number.isNaN(textFieldNumValue)) {
@@ -2,7 +2,7 @@ export const generateAllowedValues = (min, max, step) => {
2
2
  const values = [];
3
3
  let current = min;
4
4
  while (current <= max) {
5
- values.push(current);
5
+ values.push(parseFloat(current.toFixed(10)));
6
6
  current += step;
7
7
  }
8
8
  return values;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Fields",
7
- "version": "0.42.0",
7
+ "version": "0.42.2-preview-b28bfeb6.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -65,5 +65,5 @@
65
65
  "peerDependencies": {
66
66
  "@snack-uikit/locale": "*"
67
67
  },
68
- "gitHead": "9786e3a2d1ef58fd4b1002d4bc69a61a70113acf"
68
+ "gitHead": "ba980d62f5d8c0dc023391184812ff742f69281f"
69
69
  }
@@ -1,6 +1,6 @@
1
1
  import cn from 'classnames';
2
2
  import mergeRefs from 'merge-refs';
3
- import { FocusEvent, forwardRef, KeyboardEvent, KeyboardEventHandler, useEffect, useRef, useState } from 'react';
3
+ import { FocusEvent, forwardRef, KeyboardEvent, KeyboardEventHandler, useRef, useState } from 'react';
4
4
 
5
5
  import { InputPrivate } from '@snack-uikit/input-private';
6
6
  import { BaseItemProps, Droplist, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
@@ -82,12 +82,6 @@ export const FieldSelectMultiple = forwardRef<HTMLInputElement, FieldSelectMulti
82
82
  const prefixSettings = usePrefix({ prefix, disabled });
83
83
  const postfixSettings = usePostfix({ postfix, disabled });
84
84
 
85
- useEffect(() => {
86
- if (options.length === 0 && value && value.length > 0) {
87
- setValue(undefined);
88
- }
89
- }, [options.length, setValue, value]);
90
-
91
85
  useLayoutEffect(() => {
92
86
  setItems(({ selectedItems }) => updateMultipleItems({ options, value, selectedItems }));
93
87
  }, [options, value]);
@@ -88,12 +88,6 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
88
88
  const prefixSettings = usePrefix({ prefix, disabled });
89
89
  const postfixSettings = usePostfix({ postfix, disabled });
90
90
 
91
- useEffect(() => {
92
- if (options.length < 1 && Boolean(value)) {
93
- setValue(undefined);
94
- }
95
- }, [options.length, setValue, value]);
96
-
97
91
  useLayoutEffect(() => {
98
92
  setItems(({ selectedItem }) => updateItems({ options, value, selectedItem }));
99
93
  }, [options, value]);
@@ -128,7 +122,7 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
128
122
  const { postfixButtons, inputKeyDownNavigationHandler, buttonsRefs } = useButtons({
129
123
  readonly,
130
124
  size,
131
- showClearButton: showClearButton && !disabled && !readonly && value !== undefined,
125
+ showClearButton: showClearButton && !disabled && !readonly && value !== undefined && selectedItem !== undefined,
132
126
  showCopyButton,
133
127
  inputRef: localRef,
134
128
  onClear,
@@ -143,7 +143,7 @@ export const FieldSlider = forwardRef<HTMLInputElement, FieldSliderProps>(
143
143
  );
144
144
 
145
145
  const onTextFieldChange = (textFieldValue: string) => {
146
- const numValue = parseInt(textFieldValue);
146
+ const numValue = parseFloat(textFieldValue);
147
147
 
148
148
  if (textFieldValue && Number.isNaN(numValue)) {
149
149
  return;
@@ -160,7 +160,7 @@ export const FieldSlider = forwardRef<HTMLInputElement, FieldSliderProps>(
160
160
 
161
161
  const allowedValues = Object.keys(marks).map(key => ({
162
162
  key,
163
- value: parseInt(String(getMarkValue(key))),
163
+ value: parseFloat(String(getMarkValue(key))),
164
164
  }));
165
165
  const suitableEntry = allowedValues.find(entry => entry.value === textFieldNumValue);
166
166
 
@@ -169,8 +169,8 @@ export const FieldSlider = forwardRef<HTMLInputElement, FieldSliderProps>(
169
169
  return;
170
170
  }
171
171
 
172
- const actualMin = parseInt(String(getMarkValue(min)));
173
- const actualMax = parseInt(String(getMarkValue(max)));
172
+ const actualMin = parseFloat(String(getMarkValue(min)));
173
+ const actualMax = parseFloat(String(getMarkValue(max)));
174
174
 
175
175
  if (textFieldNumValue < actualMin) {
176
176
  handleChange(min);
@@ -230,8 +230,8 @@ export const FieldSlider = forwardRef<HTMLInputElement, FieldSliderProps>(
230
230
  return;
231
231
  }
232
232
 
233
- const parsedValue = parseInt(textFieldInputValue);
234
- const actualMinByMark = parseInt(String(getMarkValue(min)));
233
+ const parsedValue = parseFloat(textFieldInputValue);
234
+ const actualMinByMark = parseFloat(String(getMarkValue(min)));
235
235
  const actualMin = Number.isNaN(actualMinByMark) ? min : actualMinByMark;
236
236
 
237
237
  const textFieldNumValue = textFieldInputValue ? parsedValue : actualMin;
@@ -4,7 +4,7 @@ export const generateAllowedValues = (min: number, max: number, step: number): n
4
4
  let current = min;
5
5
 
6
6
  while (current <= max) {
7
- values.push(current);
7
+ values.push(parseFloat(current.toFixed(10)));
8
8
  current += step;
9
9
  }
10
10