@ultraviolet/ui 1.43.0 → 1.43.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.
package/dist/index.d.ts CHANGED
@@ -2079,8 +2079,11 @@ declare const NumberInputV2: react.ForwardRefExoticComponent<{
2079
2079
  error?: string | undefined;
2080
2080
  success?: string | boolean | undefined;
2081
2081
  helper?: ReactNode;
2082
- value?: string | number | undefined;
2083
- } & Pick<InputHTMLAttributes<HTMLInputElement>, "autoFocus" | "id" | "aria-label" | "onFocus" | "onBlur" | "onChange" | "max" | "min" | "name" | "disabled" | "step" | "placeholder" | "readOnly" | "required"> & react.RefAttributes<HTMLInputElement>>;
2082
+ value?: number | undefined;
2083
+ onChange?: ((newValue: number) => void) | undefined;
2084
+ min?: number | undefined;
2085
+ max?: number | undefined;
2086
+ } & Pick<InputHTMLAttributes<HTMLInputElement>, "autoFocus" | "id" | "aria-label" | "onFocus" | "onBlur" | "name" | "disabled" | "step" | "placeholder" | "readOnly" | "required"> & react.RefAttributes<HTMLInputElement>>;
2084
2087
 
2085
2088
  type PaginationProps = {
2086
2089
  /**
@@ -9,6 +9,7 @@ import { Tooltip } from '../Tooltip/index.js';
9
9
  import { jsxs, jsx } from '@emotion/react/jsx-runtime';
10
10
 
11
11
  function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
12
+ const NUMBER_INPUT_MAX_STR_LENGTH = /*#__PURE__*/Number.MAX_SAFE_INTEGER.toString().length;
12
13
  const SIZES = {
13
14
  small: '30px',
14
15
  medium: '38px',
@@ -101,7 +102,7 @@ const Container = /*#__PURE__*/_styled("div", {
101
102
  */
102
103
  const NumberInputV2 = /*#__PURE__*/forwardRef(({
103
104
  disabled = false,
104
- max = Infinity,
105
+ max = Number.MAX_SAFE_INTEGER,
105
106
  min = 0,
106
107
  name,
107
108
  onChange,
@@ -130,21 +131,35 @@ const NumberInputV2 = /*#__PURE__*/forwardRef(({
130
131
  useImperativeHandle(ref, () => localRef.current);
131
132
  const uniqueId = useId();
132
133
  const localId = id ?? uniqueId;
133
- const createChangeEvent = newValue => ({
134
- target: {
135
- value: newValue
136
- }
137
- });
138
134
  const onClickSideButton = useCallback(direction => () => {
139
135
  if (direction === 'up') {
140
136
  localRef.current?.stepUp();
141
- onChange?.(createChangeEvent(localRef.current?.value ?? min));
142
- }
143
- if (direction === 'down') {
137
+ } else if (direction === 'down') {
144
138
  localRef.current?.stepDown();
145
- onChange?.(createChangeEvent(localRef.current?.value ?? min));
146
139
  }
140
+ onChange?.(parseInt(localRef.current?.value ?? '', 10) ?? min);
147
141
  }, [localRef, min, onChange]);
142
+ const onChangeValue = inputStr => {
143
+ if (onChange) {
144
+ let numericValue;
145
+ if (inputStr.length > NUMBER_INPUT_MAX_STR_LENGTH && inputStr.startsWith('-')) {
146
+ numericValue = min;
147
+ } else if (inputStr.length > NUMBER_INPUT_MAX_STR_LENGTH) {
148
+ numericValue = max;
149
+ } else {
150
+ numericValue = parseInt(inputStr, 10);
151
+ if (Number.isNaN(numericValue) || numericValue < min) {
152
+ numericValue = min;
153
+ } else if (numericValue > max) {
154
+ numericValue = max;
155
+ }
156
+ }
157
+ onChange(numericValue);
158
+ if (localRef.current) {
159
+ localRef.current.value = numericValue.toString();
160
+ }
161
+ }
162
+ };
148
163
  const isMinusDisabled = useMemo(() => {
149
164
  if (!localRef?.current?.value || localRef?.current?.value === '') {
150
165
  return false;
@@ -231,25 +246,23 @@ const NumberInputV2 = /*#__PURE__*/forwardRef(({
231
246
  name: name,
232
247
  id: localId,
233
248
  placeholder: placeholder,
249
+ onKeyDown: event => {
250
+ if (event.key === 'Enter') {
251
+ onChangeValue(localRef.current?.value ?? '');
252
+ }
253
+ },
234
254
  onBlur: event => {
235
255
  if (event.target.value === '') {
236
256
  onBlur?.(event);
237
257
  return;
238
258
  }
239
- const numericValue = Number(event.target.value);
240
- const maxValue = typeof max === 'number' ? max : Number(max);
241
- const minValue = typeof min === 'number' ? min : Number(min);
242
- if (Number.isNaN(numericValue) || !Number.isNaN(minValue) && numericValue < minValue) {
243
- onChange?.(createChangeEvent(min.toString()));
244
- }
245
- if (Number.isNaN(numericValue) || !Number.isNaN(maxValue) && numericValue > maxValue) {
246
- onChange?.(createChangeEvent(max.toString()));
259
+ if (onChange) {
260
+ onChangeValue(event.target.value);
247
261
  }
248
262
  onBlur?.(event);
249
263
  },
264
+ defaultValue: value,
250
265
  onFocus: onFocus,
251
- onChange: onChange,
252
- value: value,
253
266
  "data-size": size,
254
267
  step: step,
255
268
  disabled: disabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.43.0",
3
+ "version": "1.43.1",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {