@graphcommerce/ecommerce-ui 1.5.2 → 1.5.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
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @graphcommerce/ecommerce-ui
|
|
2
2
|
|
|
3
|
+
## 1.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1665](https://github.com/graphcommerce-org/graphcommerce/pull/1665) [`fc32b9ab3`](https://github.com/graphcommerce-org/graphcommerce/commit/fc32b9ab3818eb99c546a89e7f42045a6fbfba81) Thanks [@paales](https://github.com/paales)! - Checkout page didn’t work, because the SelectElement broke when it received a null value.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`1f2e14ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/1f2e14ba8b674b87257a123e8cb215157890eb22)]:
|
|
10
|
+
- @graphcommerce/react-hook-form@3.3.5
|
|
11
|
+
|
|
3
12
|
## 1.5.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Control,
|
|
3
|
+
Controller,
|
|
4
|
+
ControllerProps,
|
|
5
|
+
Path,
|
|
6
|
+
FieldValues,
|
|
7
|
+
} from '@graphcommerce/react-hook-form'
|
|
8
|
+
import { MenuItem, TextField, TextFieldProps } from '@mui/material'
|
|
9
|
+
|
|
10
|
+
export type SelectElementProps<T extends FieldValues> = Omit<
|
|
11
|
+
TextFieldProps,
|
|
12
|
+
'name' | 'type' | 'onChange'
|
|
13
|
+
> & {
|
|
14
|
+
validation?: ControllerProps['rules']
|
|
15
|
+
name: Path<T>
|
|
16
|
+
options?: { id: string | number; label: string | number }[] | any[]
|
|
17
|
+
valueKey?: string
|
|
18
|
+
labelKey?: string
|
|
19
|
+
type?: 'string' | 'number'
|
|
20
|
+
objectOnChange?: boolean
|
|
21
|
+
onChange?: (value: any) => void
|
|
22
|
+
control?: Control<T>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function SelectElement<TFieldValues extends FieldValues>({
|
|
26
|
+
name,
|
|
27
|
+
required,
|
|
28
|
+
valueKey = 'id',
|
|
29
|
+
labelKey = 'label',
|
|
30
|
+
options = [],
|
|
31
|
+
type,
|
|
32
|
+
objectOnChange,
|
|
33
|
+
validation = {},
|
|
34
|
+
control,
|
|
35
|
+
...rest
|
|
36
|
+
}: SelectElementProps<TFieldValues>): JSX.Element {
|
|
37
|
+
const isNativeSelect = !!rest.SelectProps?.native
|
|
38
|
+
const ChildComponent = isNativeSelect ? 'option' : MenuItem
|
|
39
|
+
|
|
40
|
+
if (required && !validation.required) {
|
|
41
|
+
validation.required = 'This field is required'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Controller
|
|
46
|
+
name={name}
|
|
47
|
+
rules={validation}
|
|
48
|
+
control={control}
|
|
49
|
+
render={({ field: { onBlur, onChange, value }, fieldState: { invalid, error } }) => {
|
|
50
|
+
// handle shrink on number input fields
|
|
51
|
+
if (type === 'number' && typeof value !== 'undefined') {
|
|
52
|
+
rest.InputLabelProps = rest.InputLabelProps || {}
|
|
53
|
+
rest.InputLabelProps.shrink = true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<TextField
|
|
58
|
+
{...rest}
|
|
59
|
+
name={name}
|
|
60
|
+
value={value ?? ''}
|
|
61
|
+
onBlur={onBlur}
|
|
62
|
+
onChange={(event) => {
|
|
63
|
+
let item: number | string = event.target.value
|
|
64
|
+
if (type === 'number') {
|
|
65
|
+
item = Number(item)
|
|
66
|
+
}
|
|
67
|
+
onChange(item)
|
|
68
|
+
if (typeof rest.onChange === 'function') {
|
|
69
|
+
if (objectOnChange) {
|
|
70
|
+
item = options.find((i) => i[valueKey] === item)
|
|
71
|
+
}
|
|
72
|
+
rest.onChange(item)
|
|
73
|
+
}
|
|
74
|
+
}}
|
|
75
|
+
select
|
|
76
|
+
required={required}
|
|
77
|
+
error={invalid}
|
|
78
|
+
helperText={error ? error.message : rest.helperText}
|
|
79
|
+
>
|
|
80
|
+
{isNativeSelect && <option />}
|
|
81
|
+
{options.map((item: any) => (
|
|
82
|
+
<ChildComponent key={item[valueKey]} value={item[valueKey]}>
|
|
83
|
+
{item[labelKey]}
|
|
84
|
+
</ChildComponent>
|
|
85
|
+
))}
|
|
86
|
+
</TextField>
|
|
87
|
+
)
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
@@ -6,7 +6,6 @@ export {
|
|
|
6
6
|
PasswordElement,
|
|
7
7
|
PasswordRepeatElement,
|
|
8
8
|
RadioButtonGroup,
|
|
9
|
-
SelectElement,
|
|
10
9
|
SliderElement,
|
|
11
10
|
SwitchElement,
|
|
12
11
|
ToggleButtonGroupElement,
|
|
@@ -19,11 +18,11 @@ export type {
|
|
|
19
18
|
PasswordElementProps,
|
|
20
19
|
PasswordRepeatElementProps,
|
|
21
20
|
RadioButtonGroupProps,
|
|
22
|
-
SelectElementProps,
|
|
23
21
|
SliderElementProps,
|
|
24
22
|
SwitchElementProps,
|
|
25
23
|
ToggleButtonGroupElementProps,
|
|
26
24
|
} from 'react-hook-form-mui'
|
|
27
25
|
|
|
28
26
|
export * from './TextFieldElement'
|
|
27
|
+
export * from './SelectElement'
|
|
29
28
|
export * from './NumberFieldElement'
|
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": "1.5.
|
|
5
|
+
"version": "1.5.3",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphcommerce/graphql": "3.4.8",
|
|
16
16
|
"@graphcommerce/next-ui": "4.28.0",
|
|
17
|
-
"@graphcommerce/react-hook-form": "3.3.
|
|
17
|
+
"@graphcommerce/react-hook-form": "3.3.5",
|
|
18
18
|
"@mui/icons-material": "^5.10.3",
|
|
19
19
|
"@mui/x-date-pickers": "^5.0.0",
|
|
20
20
|
"react-hook-form-mui": "^5.7.1"
|