@graphcommerce/ecommerce-ui 5.2.0-canary.2 → 5.2.0-canary.3
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 +2 -0
- package/components/FormComponents/AutoCompleteElement.tsx +1 -4
- package/components/FormComponents/CheckboxButtonGroup.tsx +2 -5
- package/components/FormComponents/CheckboxElement.tsx +5 -10
- package/components/FormComponents/MultiSelectElement.tsx +11 -9
- package/components/FormComponents/PasswordRepeatElement.tsx +3 -5
- package/components/FormComponents/RadioButtonGroup.tsx +2 -5
- package/components/FormComponents/SelectElement.tsx +1 -1
- package/components/FormComponents/SliderElement.tsx +1 -6
- package/components/FormComponents/SwitchElement.tsx +2 -5
- package/components/FormComponents/TextFieldElement.tsx +1 -1
- package/components/FormComponents/ToggleButtonGroup.tsx +6 -11
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -20,13 +20,10 @@ export type AutocompleteElementProps<
|
|
|
20
20
|
M extends boolean | undefined,
|
|
21
21
|
D extends boolean | undefined,
|
|
22
22
|
> = {
|
|
23
|
-
name: Path<F>
|
|
24
|
-
control?: Control<F>
|
|
25
23
|
options: T[]
|
|
26
24
|
loading?: boolean
|
|
27
25
|
multiple?: M
|
|
28
26
|
matchId?: boolean
|
|
29
|
-
rules?: ControllerProps['rules']
|
|
30
27
|
required?: boolean
|
|
31
28
|
label?: TextFieldProps['label']
|
|
32
29
|
showCheckbox?: boolean
|
|
@@ -35,7 +32,7 @@ export type AutocompleteElementProps<
|
|
|
35
32
|
'name' | 'options' | 'loading' | 'renderInput'
|
|
36
33
|
>
|
|
37
34
|
textFieldProps?: Omit<TextFieldProps, 'name' | 'required' | 'label'>
|
|
38
|
-
}
|
|
35
|
+
} & ControllerProps<F>
|
|
39
36
|
|
|
40
37
|
type AutoDefault = {
|
|
41
38
|
id: string | number // must keep id in case of keepObject
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Control,
|
|
3
2
|
FieldError,
|
|
4
|
-
Path,
|
|
5
3
|
useController,
|
|
6
4
|
FieldValues,
|
|
5
|
+
UseControllerProps,
|
|
7
6
|
} from '@graphcommerce/react-hook-form'
|
|
8
7
|
import {
|
|
9
8
|
Checkbox,
|
|
@@ -19,7 +18,6 @@ import {
|
|
|
19
18
|
export type CheckboxButtonGroupProps<T extends FieldValues> = {
|
|
20
19
|
options: { id: string | number; label: string }[] | any[]
|
|
21
20
|
helperText?: string
|
|
22
|
-
name: Path<T>
|
|
23
21
|
required?: boolean
|
|
24
22
|
parseError?: (error: FieldError) => string
|
|
25
23
|
label?: string
|
|
@@ -29,9 +27,8 @@ export type CheckboxButtonGroupProps<T extends FieldValues> = {
|
|
|
29
27
|
returnObject?: boolean
|
|
30
28
|
disabled?: boolean
|
|
31
29
|
row?: boolean
|
|
32
|
-
control?: Control<T>
|
|
33
30
|
checkboxColor?: CheckboxProps['color']
|
|
34
|
-
}
|
|
31
|
+
} & UseControllerProps<T>
|
|
35
32
|
|
|
36
33
|
export function CheckboxButtonGroup<TFieldValues extends FieldValues>({
|
|
37
34
|
helperText,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Control,
|
|
3
2
|
Controller,
|
|
4
3
|
ControllerProps,
|
|
5
4
|
FieldError,
|
|
6
|
-
Path,
|
|
7
5
|
FieldValues,
|
|
8
6
|
} from '@graphcommerce/react-hook-form'
|
|
9
7
|
import {
|
|
@@ -17,17 +15,14 @@ import {
|
|
|
17
15
|
} from '@mui/material'
|
|
18
16
|
|
|
19
17
|
export type CheckboxElementProps<T extends FieldValues> = Omit<CheckboxProps, 'name'> & {
|
|
20
|
-
validation?: ControllerProps['rules']
|
|
21
|
-
name: Path<T>
|
|
22
18
|
parseError?: (error: FieldError) => string
|
|
23
19
|
label?: FormControlLabelProps['label']
|
|
24
20
|
helperText?: string
|
|
25
|
-
|
|
26
|
-
}
|
|
21
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
27
22
|
|
|
28
23
|
export function CheckboxElement<TFieldValues extends FieldValues>({
|
|
29
24
|
name,
|
|
30
|
-
|
|
25
|
+
rules = {},
|
|
31
26
|
required,
|
|
32
27
|
parseError,
|
|
33
28
|
label,
|
|
@@ -35,14 +30,14 @@ export function CheckboxElement<TFieldValues extends FieldValues>({
|
|
|
35
30
|
helperText,
|
|
36
31
|
...rest
|
|
37
32
|
}: CheckboxElementProps<TFieldValues>): JSX.Element {
|
|
38
|
-
if (required && !
|
|
39
|
-
|
|
33
|
+
if (required && !rules.required) {
|
|
34
|
+
rules.required = 'This field is required'
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
return (
|
|
43
38
|
<Controller
|
|
44
39
|
name={name}
|
|
45
|
-
rules={
|
|
40
|
+
rules={rules}
|
|
46
41
|
control={control}
|
|
47
42
|
render={({ field: { value, onChange }, fieldState: { invalid, error } }) => {
|
|
48
43
|
const parsedHelperText = error
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
2
|
import { IconSvg, iconClose } from '@graphcommerce/next-ui'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Controller,
|
|
5
|
+
FieldError,
|
|
6
|
+
FieldValues,
|
|
7
|
+
ControllerProps,
|
|
8
|
+
} from '@graphcommerce/react-hook-form'
|
|
4
9
|
import {
|
|
5
10
|
Checkbox,
|
|
6
11
|
Chip,
|
|
@@ -21,18 +26,15 @@ export type MultiSelectElementProps<T extends FieldValues> = Omit<SelectProps, '
|
|
|
21
26
|
itemValue?: string
|
|
22
27
|
itemLabel?: string
|
|
23
28
|
required?: boolean
|
|
24
|
-
validation?: any
|
|
25
|
-
name: Path<T>
|
|
26
29
|
parseError?: (error: FieldError) => string
|
|
27
30
|
minWidth?: number
|
|
28
31
|
menuMaxHeight?: number
|
|
29
32
|
menuMaxWidth?: number
|
|
30
33
|
helperText?: string
|
|
31
34
|
showChips?: boolean
|
|
32
|
-
control?: Control<T>
|
|
33
35
|
showCheckbox?: boolean
|
|
34
36
|
formControlProps?: Omit<FormControlProps, 'fullWidth' | 'variant'>
|
|
35
|
-
}
|
|
37
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
36
38
|
|
|
37
39
|
const ITEM_HEIGHT = 48
|
|
38
40
|
const ITEM_PADDING_TOP = 8
|
|
@@ -47,7 +49,7 @@ export function MultiSelectElement<TFieldValues extends FieldValues>(
|
|
|
47
49
|
itemValue = '',
|
|
48
50
|
itemLabel = 'label',
|
|
49
51
|
required = false,
|
|
50
|
-
|
|
52
|
+
rules = {},
|
|
51
53
|
parseError,
|
|
52
54
|
name,
|
|
53
55
|
menuMaxHeight = ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
|
|
@@ -60,14 +62,14 @@ export function MultiSelectElement<TFieldValues extends FieldValues>(
|
|
|
60
62
|
formControlProps,
|
|
61
63
|
...rest
|
|
62
64
|
} = props
|
|
63
|
-
if (required && !
|
|
64
|
-
|
|
65
|
+
if (required && !rules.required) {
|
|
66
|
+
rules.required = 'This field is required'
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
return (
|
|
68
70
|
<Controller
|
|
69
71
|
name={name}
|
|
70
|
-
rules={
|
|
72
|
+
rules={rules}
|
|
71
73
|
control={control}
|
|
72
74
|
render={({ field: { value, onChange, onBlur }, fieldState: { invalid, error } }) => {
|
|
73
75
|
helperText = error
|
|
@@ -3,16 +3,14 @@ import { i18n } from '@lingui/core'
|
|
|
3
3
|
import { PasswordElement, PasswordElementProps } from './PasswordElement'
|
|
4
4
|
|
|
5
5
|
export type PasswordRepeatElementProps<T extends FieldValues> = PasswordElementProps<T> & {
|
|
6
|
-
passwordFieldName:
|
|
6
|
+
passwordFieldName: PasswordElementProps<T>['name']
|
|
7
7
|
}
|
|
8
|
+
|
|
8
9
|
export function PasswordRepeatElement<TFieldValues extends FieldValues>({
|
|
9
10
|
passwordFieldName,
|
|
10
11
|
...rest
|
|
11
12
|
}: PasswordRepeatElementProps<TFieldValues>) {
|
|
12
|
-
const pwValue = useWatch({
|
|
13
|
-
name: passwordFieldName,
|
|
14
|
-
control: rest.control,
|
|
15
|
-
})
|
|
13
|
+
const pwValue = useWatch({ name: passwordFieldName, control: rest.control })
|
|
16
14
|
return (
|
|
17
15
|
<PasswordElement
|
|
18
16
|
{...rest}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Control,
|
|
3
2
|
FieldError,
|
|
4
|
-
Path,
|
|
5
3
|
useController,
|
|
6
4
|
FieldValues,
|
|
5
|
+
UseControllerProps,
|
|
7
6
|
} from '@graphcommerce/react-hook-form'
|
|
8
7
|
import {
|
|
9
8
|
FormControl,
|
|
@@ -19,7 +18,6 @@ import { ChangeEvent } from 'react'
|
|
|
19
18
|
export type RadioButtonGroupProps<T extends FieldValues> = {
|
|
20
19
|
options: { label: string; id: string | number }[] | any[]
|
|
21
20
|
helperText?: string
|
|
22
|
-
name: Path<T>
|
|
23
21
|
required?: boolean
|
|
24
22
|
parseError?: (error: FieldError) => string
|
|
25
23
|
label?: string
|
|
@@ -30,8 +28,7 @@ export type RadioButtonGroupProps<T extends FieldValues> = {
|
|
|
30
28
|
onChange?: (value: any) => void
|
|
31
29
|
returnObject?: boolean
|
|
32
30
|
row?: boolean
|
|
33
|
-
|
|
34
|
-
}
|
|
31
|
+
} & UseControllerProps<T>
|
|
35
32
|
|
|
36
33
|
export function RadioButtonGroup<TFieldValues extends FieldValues>({
|
|
37
34
|
helperText,
|
|
@@ -12,7 +12,7 @@ export type SelectElementProps<T extends FieldValues> = Omit<
|
|
|
12
12
|
type?: 'string' | 'number'
|
|
13
13
|
objectOnChange?: boolean
|
|
14
14
|
onChange?: (value: any) => void
|
|
15
|
-
} &
|
|
15
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
16
16
|
|
|
17
17
|
export function SelectElement<TFieldValues extends FieldValues>({
|
|
18
18
|
name,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Control,
|
|
3
2
|
Controller,
|
|
4
3
|
ControllerProps,
|
|
5
4
|
FieldError,
|
|
6
|
-
Path,
|
|
7
5
|
FieldValues,
|
|
8
6
|
} from '@graphcommerce/react-hook-form'
|
|
9
7
|
import {
|
|
@@ -16,14 +14,11 @@ import {
|
|
|
16
14
|
} from '@mui/material'
|
|
17
15
|
|
|
18
16
|
export type SliderElementProps<T extends FieldValues> = Omit<SliderProps, 'control'> & {
|
|
19
|
-
name: Path<T>
|
|
20
|
-
control?: Control<T>
|
|
21
17
|
label?: string
|
|
22
|
-
rules?: ControllerProps['rules']
|
|
23
18
|
parseError?: (error: FieldError) => string
|
|
24
19
|
required?: boolean
|
|
25
20
|
formControlProps?: FormControlProps
|
|
26
|
-
}
|
|
21
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
27
22
|
|
|
28
23
|
export function SliderElement<TFieldValues extends FieldValues>({
|
|
29
24
|
name,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Controller, FieldValues, ControllerProps } from '@graphcommerce/react-hook-form'
|
|
2
2
|
import { FormControlLabel, FormControlLabelProps, Switch } from '@mui/material'
|
|
3
3
|
|
|
4
4
|
type IProps = Omit<FormControlLabelProps, 'control'>
|
|
5
5
|
|
|
6
|
-
export type SwitchElementProps<T extends FieldValues> = IProps &
|
|
7
|
-
name: Path<T>
|
|
8
|
-
control?: Control<T>
|
|
9
|
-
}
|
|
6
|
+
export type SwitchElementProps<T extends FieldValues> = IProps & Omit<ControllerProps<T>, 'render'>
|
|
10
7
|
|
|
11
8
|
export function SwitchElement<TFieldValues extends FieldValues>({
|
|
12
9
|
name,
|
|
@@ -13,7 +13,7 @@ export type TextFieldElementProps<T extends FieldValues = FieldValues> = Omit<
|
|
|
13
13
|
> & {
|
|
14
14
|
validation?: ControllerProps['rules']
|
|
15
15
|
parseError?: (error: FieldError) => string
|
|
16
|
-
} &
|
|
16
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
17
17
|
|
|
18
18
|
/** This is a copy of the default one, but allowing defaultValue */
|
|
19
19
|
export function TextFieldElement<TFieldValues extends FieldValues = FieldValues>({
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Control,
|
|
3
2
|
Controller,
|
|
4
3
|
ControllerProps,
|
|
5
4
|
FieldError,
|
|
6
|
-
Path,
|
|
7
5
|
FieldValues,
|
|
8
6
|
} from '@graphcommerce/react-hook-form'
|
|
9
7
|
import {
|
|
@@ -26,20 +24,17 @@ type SingleToggleButtonProps = Omit<ToggleButtonProps, 'value' | 'children'> & {
|
|
|
26
24
|
export type ToggleButtonGroupElementProps<T extends FieldValues> = ToggleButtonGroupProps & {
|
|
27
25
|
required?: boolean
|
|
28
26
|
label?: string
|
|
29
|
-
validation?: ControllerProps['rules']
|
|
30
|
-
name: Path<T>
|
|
31
27
|
parseError?: (error: FieldError) => string
|
|
32
|
-
control?: Control<T>
|
|
33
28
|
options: SingleToggleButtonProps[]
|
|
34
29
|
formLabelProps?: FormLabelProps
|
|
35
30
|
helperText?: string
|
|
36
|
-
}
|
|
31
|
+
} & Omit<ControllerProps<T>, 'render'>
|
|
37
32
|
|
|
38
33
|
export function ToggleButtonGroupElement<TFieldValues extends FieldValues = FieldValues>({
|
|
39
34
|
name,
|
|
40
35
|
control,
|
|
41
36
|
label,
|
|
42
|
-
|
|
37
|
+
rules = {},
|
|
43
38
|
required,
|
|
44
39
|
options = [],
|
|
45
40
|
parseError,
|
|
@@ -47,16 +42,16 @@ export function ToggleButtonGroupElement<TFieldValues extends FieldValues = Fiel
|
|
|
47
42
|
formLabelProps,
|
|
48
43
|
...toggleButtonGroupProps
|
|
49
44
|
}: ToggleButtonGroupElementProps<TFieldValues>) {
|
|
50
|
-
if (required && !
|
|
51
|
-
|
|
45
|
+
if (required && !rules.required) {
|
|
46
|
+
rules.required = 'This field is required'
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
const isRequired = required || !!
|
|
49
|
+
const isRequired = required || !!rules?.required
|
|
55
50
|
return (
|
|
56
51
|
<Controller
|
|
57
52
|
name={name}
|
|
58
53
|
control={control}
|
|
59
|
-
rules={
|
|
54
|
+
rules={rules}
|
|
60
55
|
render={({ field: { value, onChange, onBlur }, fieldState: { invalid, error } }) => {
|
|
61
56
|
const renderHelperText = error
|
|
62
57
|
? typeof parseError === 'function'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/ecommerce-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "5.2.0-canary.
|
|
5
|
+
"version": "5.2.0-canary.3",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,21 +12,21 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphcommerce/graphql": "5.2.0-canary.
|
|
16
|
-
"@graphcommerce/next-ui": "5.2.0-canary.
|
|
17
|
-
"@graphcommerce/react-hook-form": "5.2.0-canary.
|
|
15
|
+
"@graphcommerce/graphql": "5.2.0-canary.3",
|
|
16
|
+
"@graphcommerce/next-ui": "5.2.0-canary.3",
|
|
17
|
+
"@graphcommerce/react-hook-form": "5.2.0-canary.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@graphcommerce/eslint-config-pwa": "5.2.0-canary.
|
|
21
|
-
"@graphcommerce/prettier-config-pwa": "5.2.0-canary.
|
|
22
|
-
"@graphcommerce/typescript-config-pwa": "5.2.0-canary.
|
|
20
|
+
"@graphcommerce/eslint-config-pwa": "5.2.0-canary.3",
|
|
21
|
+
"@graphcommerce/prettier-config-pwa": "5.2.0-canary.3",
|
|
22
|
+
"@graphcommerce/typescript-config-pwa": "5.2.0-canary.3"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@lingui/core": "^3.13.2",
|
|
26
26
|
"@lingui/react": "^3.13.2",
|
|
27
27
|
"@mui/material": "^5.10.16",
|
|
28
28
|
"framer-motion": "^7.0.0",
|
|
29
|
-
"next": "^
|
|
29
|
+
"next": "^13.1.1",
|
|
30
30
|
"react": "^18.2.0",
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
}
|