@ultraviolet/ui 1.43.0 → 1.43.2

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 | null | undefined;
2083
+ onChange?: ((newValue: number | null) => 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,28 @@ 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
+ if (!localRef.current?.value) {
252
+ onChange?.(null);
253
+ } else if (onChange) {
254
+ onChangeValue(localRef.current?.value ?? '');
255
+ }
256
+ }
257
+ },
234
258
  onBlur: event => {
235
259
  if (event.target.value === '') {
236
260
  onBlur?.(event);
261
+ onChange?.(null);
237
262
  return;
238
263
  }
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()));
264
+ if (onChange) {
265
+ onChangeValue(event.target.value);
247
266
  }
248
267
  onBlur?.(event);
249
268
  },
269
+ defaultValue: value?.toString(),
250
270
  onFocus: onFocus,
251
- onChange: onChange,
252
- value: value,
253
271
  "data-size": size,
254
272
  step: step,
255
273
  disabled: disabled,
@@ -58,7 +58,7 @@ const StyledInputWrapper = /*#__PURE__*/_styled('div', {
58
58
  theme
59
59
  }) => theme.colors.success.border, ";}&[data-error='true']{border-color:", ({
60
60
  theme
61
- }) => theme.colors.danger.border, ";}&[data-readOnly='true']{background:", ({
61
+ }) => theme.colors.danger.border, ";}&[data-readonly='true']{background:", ({
62
62
  theme
63
63
  }) => theme.colors.neutral.backgroundWeak, ";border-color:", ({
64
64
  theme
@@ -70,7 +70,7 @@ const StyledInputWrapper = /*#__PURE__*/_styled('div', {
70
70
  theme
71
71
  }) => theme.colors.neutral.textDisabled, ";&::placeholder{color:", ({
72
72
  theme
73
- }) => theme.colors.neutral.textWeakDisabled, ";}}}&:not([data-disabled='true']):not([data-readOnly]):hover{border-color:", ({
73
+ }) => theme.colors.neutral.textWeakDisabled, ";}}}&:not([data-disabled='true']):not([data-readonly]):hover{border-color:", ({
74
74
  theme
75
75
  }) => theme.colors.primary.border, ";}", ({
76
76
  theme,
@@ -159,7 +159,7 @@ const TextInputV2 = /*#__PURE__*/forwardRef(({
159
159
  children: jsxs(StyledInputWrapper, {
160
160
  hasFocus: hasFocus,
161
161
  "data-disabled": disabled,
162
- "data-readOnly": readOnly,
162
+ "data-readonly": readOnly,
163
163
  "data-success": !!success,
164
164
  "data-error": !!error,
165
165
  size: size,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.43.0",
3
+ "version": "1.43.2",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -63,7 +63,7 @@
63
63
  "react-datepicker": "4.25.0",
64
64
  "react-flatten-children": "1.1.2",
65
65
  "react-select": "5.8.0",
66
- "react-toastify": "10.0.4",
66
+ "react-toastify": "10.0.5",
67
67
  "react-use-clipboard": "1.0.9",
68
68
  "reakit": "1.3.11",
69
69
  "@ultraviolet/themes": "1.9.0",