@ultraviolet/form 3.7.5 → 3.8.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
4
  const ui = require("@ultraviolet/ui");
5
5
  const reactHookForm = require("react-hook-form");
6
+ const isInteger = require("../../validators/isInteger.cjs");
6
7
  const index = require("../../providers/ErrorContext/index.cjs");
7
8
  const NumberInputFieldV2 = ({
8
9
  disabled,
@@ -48,7 +49,10 @@ const NumberInputFieldV2 = ({
48
49
  max,
49
50
  min,
50
51
  required,
51
- validate
52
+ validate: {
53
+ ...validate,
54
+ isInteger: isInteger.isInteger(step)
55
+ }
52
56
  }
53
57
  });
54
58
  return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInputV2, { name: field.name, value: field.value, disabled, onBlur: (event) => {
@@ -60,7 +64,8 @@ const NumberInputFieldV2 = ({
60
64
  }, max, min, size, step, className, "data-testid": dataTestId, id, label, labelDescription, placeholder, error: getError({
61
65
  label: label ?? "",
62
66
  max,
63
- min
67
+ min,
68
+ isInteger: step
64
69
  }, error), success, helper, tooltip, unit, "aria-label": ariaLabel, autoFocus, readOnly, required, controls });
65
70
  };
66
71
  exports.NumberInputFieldV2 = NumberInputFieldV2;
@@ -1,6 +1,7 @@
1
1
  import { jsx } from "@emotion/react/jsx-runtime";
2
2
  import { NumberInputV2 } from "@ultraviolet/ui";
3
3
  import { useController } from "react-hook-form";
4
+ import { isInteger } from "../../validators/isInteger.js";
4
5
  import { useErrors } from "../../providers/ErrorContext/index.js";
5
6
  const NumberInputFieldV2 = ({
6
7
  disabled,
@@ -46,7 +47,10 @@ const NumberInputFieldV2 = ({
46
47
  max,
47
48
  min,
48
49
  required,
49
- validate
50
+ validate: {
51
+ ...validate,
52
+ isInteger: isInteger(step)
53
+ }
50
54
  }
51
55
  });
52
56
  return /* @__PURE__ */ jsx(NumberInputV2, { name: field.name, value: field.value, disabled, onBlur: (event) => {
@@ -58,7 +62,8 @@ const NumberInputFieldV2 = ({
58
62
  }, max, min, size, step, className, "data-testid": dataTestId, id, label, labelDescription, placeholder, error: getError({
59
63
  label: label ?? "",
60
64
  max,
61
- min
65
+ min,
66
+ isInteger: step
62
67
  }, error), success, helper, tooltip, unit, "aria-label": ariaLabel, autoFocus, readOnly, required, controls });
63
68
  };
64
69
  export {
@@ -13,7 +13,7 @@ export declare const RadioGroupField: {
13
13
  className?: string;
14
14
  'data-testid'?: string;
15
15
  tooltip?: string;
16
- } & Required<Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "onChange">> & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "required" | "onBlur" | "disabled" | "name" | "onFocus" | "autoFocus" | "id" | "onKeyDown"> & ({
16
+ } & Required<Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "onChange">> & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "required" | "onBlur" | "disabled" | "name" | "onFocus" | "autoFocus" | "id" | "tabIndex" | "onKeyDown"> & ({
17
17
  'aria-label': string;
18
18
  label?: never;
19
19
  } | {
@@ -49,7 +49,7 @@ const SelectableCardField = ({
49
49
  } else {
50
50
  field.onChange(event);
51
51
  }
52
- onChange?.(event);
52
+ onChange?.(event.currentTarget.value);
53
53
  }, onBlur: (event) => {
54
54
  field.onBlur();
55
55
  onBlur?.(event);
@@ -2,7 +2,7 @@ import { SelectableCard } from '@ultraviolet/ui';
2
2
  import type { ComponentProps } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type SelectableCardFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label' | 'onChange'> & Partial<Pick<ComponentProps<typeof SelectableCard>, 'disabled' | 'onBlur' | 'onChange' | 'onFocus' | 'showTick' | 'type' | 'id' | 'children' | 'tooltip' | 'label' | 'data-testid'>> & {
5
+ type SelectableCardFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Partial<Pick<ComponentProps<typeof SelectableCard>, 'disabled' | 'onBlur' | 'onFocus' | 'showTick' | 'type' | 'id' | 'children' | 'tooltip' | 'label' | 'data-testid'>> & {
6
6
  className?: string;
7
7
  };
8
8
  export declare const SelectableCardField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, control, value, onChange, showTick, type, disabled, children, className, onFocus, onBlur, required, tooltip, id, label, shouldUnregister, validate, "data-testid": dataTestId, }: SelectableCardFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -47,7 +47,7 @@ const SelectableCardField = ({
47
47
  } else {
48
48
  field.onChange(event);
49
49
  }
50
- onChange?.(event);
50
+ onChange?.(event.currentTarget.value);
51
51
  }, onBlur: (event) => {
52
52
  field.onBlur();
53
53
  onBlur?.(event);
@@ -49,7 +49,7 @@ const SelectableCardGroupField = ({
49
49
  } else {
50
50
  field.onChange(event);
51
51
  }
52
- onChange?.(event);
52
+ onChange?.(event.currentTarget.value);
53
53
  }, error: getError({
54
54
  label
55
55
  }, error) ?? customError, className, columns, helper, required, children });
@@ -2,7 +2,7 @@ import { SelectableCardGroup } from '@ultraviolet/ui';
2
2
  import type { ComponentProps, JSX } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type SelectableCardGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label' | 'onChange'> & Partial<Pick<ComponentProps<typeof SelectableCardGroup>, 'helper' | 'error' | 'columns' | 'children' | 'showTick' | 'type' | 'className' | 'onChange'>> & Pick<ComponentProps<typeof SelectableCardGroup>, 'legend'>;
5
+ type SelectableCardGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Partial<Pick<ComponentProps<typeof SelectableCardGroup>, 'helper' | 'error' | 'columns' | 'children' | 'showTick' | 'type' | 'className'>> & Pick<ComponentProps<typeof SelectableCardGroup>, 'legend'>;
6
6
  export declare const SelectableCardGroupField: {
7
7
  <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, legend, control, name, onChange, required, children, label, error: customError, helper, columns, showTick, type, shouldUnregister, validate, }: SelectableCardGroupFieldProps<TFieldValues, TFieldName>): JSX.Element;
8
8
  Card: ({ value, disabled, children, className, isError, onFocus, onBlur, tooltip, id, label, "data-testid": dataTestId, }: import("node_modules/@ultraviolet/ui/dist/components/SelectableCardGroup").CardSelectableCardProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -47,7 +47,7 @@ const SelectableCardGroupField = ({
47
47
  } else {
48
48
  field.onChange(event);
49
49
  }
50
- onChange?.(event);
50
+ onChange?.(event.currentTarget.value);
51
51
  }, error: getError({
52
52
  label
53
53
  }, error) ?? customError, className, columns, helper, required, children });
@@ -79,7 +79,7 @@ const TextInputField = ({
79
79
  field.onBlur();
80
80
  }, onChange: (event) => {
81
81
  field.onChange(event);
82
- onChange?.(event);
82
+ onChange?.(event.target.value);
83
83
  }, onFocus: (event) => {
84
84
  onFocus?.(event);
85
85
  }, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value === void 0 ? "" : field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
@@ -2,7 +2,7 @@ import { TextInputV2 } from '@ultraviolet/ui';
2
2
  import type { ComponentProps } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type TextInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name'> & {
5
+ type TextInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name' | 'onChange'> & {
6
6
  regex?: (RegExp | RegExp[])[];
7
7
  };
8
8
  /**
@@ -77,7 +77,7 @@ const TextInputField = ({
77
77
  field.onBlur();
78
78
  }, onChange: (event) => {
79
79
  field.onChange(event);
80
- onChange?.(event);
80
+ onChange?.(event.target.value);
81
81
  }, onFocus: (event) => {
82
82
  onFocus?.(event);
83
83
  }, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value === void 0 ? "" : field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
@@ -50,7 +50,7 @@ const ToggleField = ({
50
50
  } else {
51
51
  field.onChange(event);
52
52
  }
53
- onChange?.(event);
53
+ onChange?.(event.target.checked);
54
54
  }, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId, error: getError({
55
55
  label: name
56
56
  }, error) });
@@ -2,7 +2,7 @@ import { Toggle } from '@ultraviolet/ui';
2
2
  import type { ComponentProps } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type ToggleFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Pick<ComponentProps<typeof Toggle>, 'disabled' | 'label' | 'onChange' | 'size' | 'tooltip' | 'labelPosition' | 'className' | 'data-testid'> & {
5
+ type ToggleFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Pick<ComponentProps<typeof Toggle>, 'disabled' | 'label' | 'size' | 'tooltip' | 'labelPosition' | 'className' | 'data-testid'> & {
6
6
  parse?: (value: boolean) => any;
7
7
  format?: (value: any) => boolean;
8
8
  };
@@ -48,7 +48,7 @@ const ToggleField = ({
48
48
  } else {
49
49
  field.onChange(event);
50
50
  }
51
- onChange?.(event);
51
+ onChange?.(event.target.checked);
52
52
  }, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId, error: getError({
53
53
  label: name
54
54
  }, error) });
@@ -3,7 +3,6 @@ import type { ComponentProps } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
5
  type UnitInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Pick<ComponentProps<typeof UnitInput>, 'id' | 'name' | 'className' | 'data-testid' | 'disabled' | 'value' | 'max' | 'min' | 'options' | 'placeholder' | 'placeholderUnit' | 'size' | 'unitValue' | 'required' | 'width' | 'helper' | 'selectInputWidth'> & {
6
- onChange?: ComponentProps<typeof UnitInput>['onChange'];
7
6
  onChangeUnitValue?: ComponentProps<typeof UnitInput>['onChangeUnitValue'];
8
7
  label: string;
9
8
  };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Control, FieldError, FieldPath, FieldPathValue, FieldValues, Path, PathValue, UseControllerProps, Validate } from 'react-hook-form';
2
2
  export type MetaField = {
3
+ isInteger?: number | string;
3
4
  min?: number | string;
4
5
  max?: number | string;
5
6
  minLength?: number;
@@ -14,7 +15,7 @@ export type RequiredErrors = {
14
15
  [key in FieldError['type']]: (params: MetaField) => string;
15
16
  };
16
17
  export type FormErrors = {
17
- [key in 'required' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'minDate' | 'maxDate']: RequiredErrors[key];
18
+ [key in 'required' | 'isInteger' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'minDate' | 'maxDate']: RequiredErrors[key];
18
19
  };
19
20
  export type BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
20
21
  name: TFieldName;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isInteger = (step) => (value) => {
4
+ if (value === void 0 || step === void 0) return true;
5
+ if (Number.isInteger(step)) {
6
+ return Number.isInteger(value) && Number.isInteger(value);
7
+ }
8
+ return !Number.isInteger(value) && !Number.isInteger(value);
9
+ };
10
+ exports.isInteger = isInteger;
@@ -0,0 +1 @@
1
+ export declare const isInteger: (step?: number | string) => (value: number) => boolean;
@@ -0,0 +1,10 @@
1
+ const isInteger = (step) => (value) => {
2
+ if (value === void 0 || step === void 0) return true;
3
+ if (Number.isInteger(step)) {
4
+ return Number.isInteger(value) && Number.isInteger(value);
5
+ }
6
+ return !Number.isInteger(value) && !Number.isInteger(value);
7
+ };
8
+ export {
9
+ isInteger
10
+ };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "3.7.5",
3
+ "version": "3.8.1",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/scaleway/ultraviolet",
8
+ "url": "git+https://github.com/scaleway/ultraviolet.git",
9
9
  "directory": "packages/form"
10
10
  },
11
11
  "keywords": [
@@ -71,8 +71,8 @@
71
71
  "@babel/runtime": "7.25.6",
72
72
  "react-hook-form": "7.53.0",
73
73
  "react-select": "5.8.0",
74
- "@ultraviolet/themes": "1.13.0",
75
- "@ultraviolet/ui": "1.68.1"
74
+ "@ultraviolet/themes": "1.14.0",
75
+ "@ultraviolet/ui": "1.70.0"
76
76
  },
77
77
  "scripts": {
78
78
  "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",