@ultraviolet/form 1.4.1 → 1.5.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/dist/components/CheckboxGroupField/index.js +58 -0
- package/dist/index.d.ts +36 -3
- package/dist/index.js +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CheckboxGroup } from '@ultraviolet/ui';
|
|
2
|
+
import { useFieldArray } from 'react-final-form-arrays';
|
|
3
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
4
|
+
import { useErrors } from '../../providers/ErrorContext/index.js';
|
|
5
|
+
|
|
6
|
+
const CheckboxGroupField = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
legend,
|
|
9
|
+
value,
|
|
10
|
+
className,
|
|
11
|
+
helper,
|
|
12
|
+
direction,
|
|
13
|
+
children,
|
|
14
|
+
onChange,
|
|
15
|
+
error: customError,
|
|
16
|
+
name,
|
|
17
|
+
required = false
|
|
18
|
+
} = _ref;
|
|
19
|
+
const {
|
|
20
|
+
getError
|
|
21
|
+
} = useErrors();
|
|
22
|
+
const {
|
|
23
|
+
fields,
|
|
24
|
+
meta
|
|
25
|
+
} = useFieldArray(name, {
|
|
26
|
+
type: 'checkbox',
|
|
27
|
+
value,
|
|
28
|
+
validate: localValue => required && localValue?.length === 0 ? 'Required' : undefined
|
|
29
|
+
});
|
|
30
|
+
const error = getError({
|
|
31
|
+
label: legend,
|
|
32
|
+
meta,
|
|
33
|
+
value: fields.value,
|
|
34
|
+
name
|
|
35
|
+
});
|
|
36
|
+
return jsx(CheckboxGroup, {
|
|
37
|
+
legend: legend,
|
|
38
|
+
name: fields.name,
|
|
39
|
+
value: fields.value,
|
|
40
|
+
onChange: event => {
|
|
41
|
+
if (fields.value?.includes(event.currentTarget.value)) {
|
|
42
|
+
fields.remove(fields.value.indexOf(event.currentTarget?.value));
|
|
43
|
+
} else {
|
|
44
|
+
fields.push(event.currentTarget.value);
|
|
45
|
+
}
|
|
46
|
+
onChange?.(event);
|
|
47
|
+
},
|
|
48
|
+
error: error ?? customError,
|
|
49
|
+
className: className,
|
|
50
|
+
direction: direction,
|
|
51
|
+
helper: helper,
|
|
52
|
+
required: required,
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
CheckboxGroupField.Checkbox = CheckboxGroup.Checkbox;
|
|
57
|
+
|
|
58
|
+
export { CheckboxGroupField };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { Field, FormSpy, useField, useForm, useFormState } from 'react-final-for
|
|
|
6
6
|
import * as react from 'react';
|
|
7
7
|
import { ReactNode, ComponentProps, FocusEvent, JSX, ForwardedRef, FocusEventHandler } from 'react';
|
|
8
8
|
import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
|
|
9
|
-
import { DateInput, Radio, SelectInput, SelectableCard, NumberInput, TagInput, TextInput, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
|
|
9
|
+
import { CheckboxGroup, DateInput, Radio, SelectInput, SelectableCard, NumberInput, TagInput, TextInput, TimeInput, Toggle, Button, RadioGroup } from '@ultraviolet/ui';
|
|
10
10
|
import { CSSObject, Theme, css } from '@emotion/react';
|
|
11
11
|
import Select, { GroupBase, OptionProps, Props, CommonProps } from 'react-select';
|
|
12
12
|
|
|
@@ -101,6 +101,34 @@ declare const CheckboxField: react.ForwardRefExoticComponent<BaseFieldProps<stri
|
|
|
101
101
|
required?: boolean | undefined;
|
|
102
102
|
} & react.RefAttributes<HTMLInputElement>>;
|
|
103
103
|
|
|
104
|
+
type CheckboxGroupValue = string[];
|
|
105
|
+
type CheckboxGroupFieldProps<T = CheckboxGroupValue, K = string> = BaseFieldProps<T, K> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'onChange' | 'required' | 'direction' | 'children' | 'value' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend' | 'name'>>;
|
|
106
|
+
declare const CheckboxGroupField: {
|
|
107
|
+
({ legend, value, className, helper, direction, children, onChange, error: customError, name, required, }: CheckboxGroupFieldProps): _emotion_react_jsx_runtime.JSX.Element;
|
|
108
|
+
Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, }: Omit<({
|
|
109
|
+
error?: react.ReactNode;
|
|
110
|
+
size?: number | undefined;
|
|
111
|
+
progress?: boolean | undefined;
|
|
112
|
+
helper?: react.ReactNode;
|
|
113
|
+
disabled?: boolean | undefined;
|
|
114
|
+
checked?: boolean | "indeterminate" | undefined;
|
|
115
|
+
className?: string | undefined;
|
|
116
|
+
"data-visibility"?: string | undefined;
|
|
117
|
+
required?: boolean | undefined;
|
|
118
|
+
'data-testid'?: string | undefined;
|
|
119
|
+
} & Pick<react.InputHTMLAttributes<HTMLInputElement>, "name" | "value" | "onFocus" | "onBlur" | "autoFocus" | "id" | "onChange"> & (({
|
|
120
|
+
"aria-label"?: undefined;
|
|
121
|
+
} & {
|
|
122
|
+
children: react.ReactNode;
|
|
123
|
+
}) | ({
|
|
124
|
+
children?: undefined;
|
|
125
|
+
} & {
|
|
126
|
+
'aria-label': string;
|
|
127
|
+
}))) & react.RefAttributes<HTMLInputElement>, "required" | "onChange" | "checked"> & {
|
|
128
|
+
value: string;
|
|
129
|
+
}) => _emotion_react_jsx_runtime.JSX.Element;
|
|
130
|
+
};
|
|
131
|
+
|
|
104
132
|
type DateFieldProps = BaseFieldProps<Date> & Omit<ComponentProps<typeof DateInput>, 'maxDate' | 'minDate' | 'disabled' | 'required' | 'locale' | 'name' | 'onChange' | 'onFocus' | 'onBlur' | 'autoFocus'> & {
|
|
105
133
|
name: string;
|
|
106
134
|
maxDate?: Date;
|
|
@@ -376,14 +404,18 @@ declare const TextInputField: react.ForwardRefExoticComponent<BaseFieldProps<Tex
|
|
|
376
404
|
'aria-activedescendant'?: string | undefined;
|
|
377
405
|
'aria-atomic'?: (boolean | "false" | "true") | undefined;
|
|
378
406
|
'aria-autocomplete'?: "list" | "none" | "inline" | "both" | undefined;
|
|
407
|
+
'aria-braillelabel'?: string | undefined;
|
|
408
|
+
'aria-brailleroledescription'?: string | undefined;
|
|
379
409
|
'aria-busy'?: (boolean | "false" | "true") | undefined;
|
|
380
410
|
'aria-checked'?: boolean | "false" | "true" | "mixed" | undefined;
|
|
381
411
|
'aria-colcount'?: number | undefined;
|
|
382
412
|
'aria-colindex'?: number | undefined;
|
|
413
|
+
'aria-colindextext'?: string | undefined;
|
|
383
414
|
'aria-colspan'?: number | undefined;
|
|
384
415
|
'aria-controls'?: string | undefined;
|
|
385
|
-
'aria-current'?: boolean | "time" | "false" | "true" | "
|
|
416
|
+
'aria-current'?: boolean | "time" | "false" | "true" | "page" | "date" | "step" | "location" | undefined;
|
|
386
417
|
'aria-describedby'?: string | undefined;
|
|
418
|
+
'aria-description'?: string | undefined;
|
|
387
419
|
'aria-details'?: string | undefined;
|
|
388
420
|
'aria-disabled'?: (boolean | "false" | "true") | undefined;
|
|
389
421
|
'aria-dropeffect'?: "link" | "move" | "none" | "copy" | "execute" | "popup" | undefined;
|
|
@@ -412,6 +444,7 @@ declare const TextInputField: react.ForwardRefExoticComponent<BaseFieldProps<Tex
|
|
|
412
444
|
'aria-roledescription'?: string | undefined;
|
|
413
445
|
'aria-rowcount'?: number | undefined;
|
|
414
446
|
'aria-rowindex'?: number | undefined;
|
|
447
|
+
'aria-rowindextext'?: string | undefined;
|
|
415
448
|
'aria-rowspan'?: number | undefined;
|
|
416
449
|
'aria-selected'?: (boolean | "false" | "true") | undefined;
|
|
417
450
|
'aria-setsize'?: number | undefined;
|
|
@@ -695,4 +728,4 @@ type ErrorProviderProps = {
|
|
|
695
728
|
declare const ErrorProvider: ({ children, errors, }: ErrorProviderProps) => JSX.Element;
|
|
696
729
|
declare const useErrors: () => ErrorContextValue;
|
|
697
730
|
|
|
698
|
-
export { BaseFieldProps, CheckboxField, DateField, ErrorProvider, Form, FormErrors, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
|
|
731
|
+
export { type BaseFieldProps, CheckboxField, CheckboxGroupField, DateField, ErrorProvider, Form, type FormErrors, NumberInputField, RadioField, RadioGroupField, SelectInputField, SelectableCardField, Submit, SubmitErrorAlert, TagInputField, TextInputField, TimeField, ToggleField, pickValidators, useErrors, useOnFieldChange, useValidation };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { FORM_ERROR } from 'final-form';
|
|
|
3
3
|
export { Field, FormSpy, useField, useForm, useFormState } from 'react-final-form';
|
|
4
4
|
export { ErrorProvider, useErrors } from './providers/ErrorContext/index.js';
|
|
5
5
|
export { CheckboxField } from './components/CheckboxField/index.js';
|
|
6
|
+
export { CheckboxGroupField } from './components/CheckboxGroupField/index.js';
|
|
6
7
|
export { DateField } from './components/DateField/index.js';
|
|
7
8
|
export { Form } from './components/Form/index.js';
|
|
8
9
|
export { RadioField } from './components/RadioField/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@babel/core": "7.22.11",
|
|
42
|
-
"@types/final-form-focus": "1.1.
|
|
43
|
-
"@types/react": "18.2.
|
|
44
|
-
"@types/react-dom": "18.2.
|
|
42
|
+
"@types/final-form-focus": "1.1.4",
|
|
43
|
+
"@types/react": "18.2.14",
|
|
44
|
+
"@types/react-dom": "18.2.6",
|
|
45
45
|
"react": "18.2.0",
|
|
46
46
|
"react-dom": "18.2.0"
|
|
47
47
|
},
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"react-final-form": "6.5.9",
|
|
56
56
|
"react-final-form-arrays": "3.1.4",
|
|
57
57
|
"react-select": "5.7.4",
|
|
58
|
-
"@ultraviolet/ui": "1.
|
|
58
|
+
"@ultraviolet/ui": "1.11.0"
|
|
59
59
|
}
|
|
60
60
|
}
|