@graphcommerce/ecommerce-ui 6.2.0-canary.8 → 7.0.0-canary.12
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
|
@@ -2,32 +2,28 @@ import { Controller, ControllerProps, FieldValues } from '@graphcommerce/react-h
|
|
|
2
2
|
import { i18n } from '@lingui/core'
|
|
3
3
|
import { MenuItem, TextField, TextFieldProps } from '@mui/material'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type OptionBase = { id: string | number; label: string | number }
|
|
6
|
+
|
|
7
|
+
export type SelectElementProps<T extends FieldValues, O extends OptionBase> = Omit<
|
|
6
8
|
TextFieldProps,
|
|
7
9
|
'name' | 'type' | 'onChange' | 'defaultValue'
|
|
8
10
|
> & {
|
|
9
11
|
validation?: ControllerProps<T>['rules']
|
|
10
|
-
options?:
|
|
11
|
-
valueKey?: string
|
|
12
|
-
labelKey?: string
|
|
12
|
+
options?: O[]
|
|
13
13
|
type?: 'string' | 'number'
|
|
14
|
-
|
|
15
|
-
onChange?: (value: any) => void
|
|
14
|
+
onChange?: (value: string | number) => void
|
|
16
15
|
} & Omit<ControllerProps<T>, 'render'>
|
|
17
16
|
|
|
18
|
-
export function SelectElement<TFieldValues extends FieldValues>({
|
|
17
|
+
export function SelectElement<TFieldValues extends FieldValues, O extends OptionBase>({
|
|
19
18
|
name,
|
|
20
19
|
required,
|
|
21
|
-
valueKey = 'id',
|
|
22
|
-
labelKey = 'label',
|
|
23
20
|
options = [],
|
|
24
21
|
type,
|
|
25
|
-
objectOnChange,
|
|
26
22
|
validation = {},
|
|
27
23
|
control,
|
|
28
24
|
defaultValue,
|
|
29
25
|
...rest
|
|
30
|
-
}: SelectElementProps<TFieldValues>): JSX.Element {
|
|
26
|
+
}: SelectElementProps<TFieldValues, O>): JSX.Element {
|
|
31
27
|
const isNativeSelect = !!rest.SelectProps?.native
|
|
32
28
|
const ChildComponent = isNativeSelect ? 'option' : MenuItem
|
|
33
29
|
|
|
@@ -55,17 +51,10 @@ export function SelectElement<TFieldValues extends FieldValues>({
|
|
|
55
51
|
value={value ?? ''}
|
|
56
52
|
onBlur={onBlur}
|
|
57
53
|
onChange={(event) => {
|
|
58
|
-
let item: number | string = event.target.value
|
|
59
|
-
if (type === 'number')
|
|
60
|
-
|
|
61
|
-
}
|
|
54
|
+
let item: number | string | O | undefined = event.target.value
|
|
55
|
+
if (type === 'number') item = Number(item)
|
|
56
|
+
rest.onChange?.(item)
|
|
62
57
|
onChange(item)
|
|
63
|
-
if (typeof rest.onChange === 'function') {
|
|
64
|
-
if (objectOnChange) {
|
|
65
|
-
item = options.find((i) => i[valueKey] === item)
|
|
66
|
-
}
|
|
67
|
-
rest.onChange(item)
|
|
68
|
-
}
|
|
69
58
|
}}
|
|
70
59
|
select
|
|
71
60
|
required={required}
|
|
@@ -73,9 +62,9 @@ export function SelectElement<TFieldValues extends FieldValues>({
|
|
|
73
62
|
helperText={error ? error.message : rest.helperText}
|
|
74
63
|
>
|
|
75
64
|
{isNativeSelect && <option />}
|
|
76
|
-
{options.map((item
|
|
77
|
-
<ChildComponent key={item
|
|
78
|
-
{item
|
|
65
|
+
{options.map((item) => (
|
|
66
|
+
<ChildComponent key={item.id} value={item.id}>
|
|
67
|
+
{item.label}
|
|
79
68
|
</ChildComponent>
|
|
80
69
|
))}
|
|
81
70
|
</TextField>
|
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
|
+
"version": "7.0.0-canary.12",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphcommerce/graphql": "
|
|
16
|
-
"@graphcommerce/next-ui": "
|
|
17
|
-
"@graphcommerce/react-hook-form": "
|
|
15
|
+
"@graphcommerce/graphql": "7.0.0-canary.12",
|
|
16
|
+
"@graphcommerce/next-ui": "7.0.0-canary.12",
|
|
17
|
+
"@graphcommerce/react-hook-form": "7.0.0-canary.12"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@graphcommerce/eslint-config-pwa": "
|
|
21
|
-
"@graphcommerce/prettier-config-pwa": "
|
|
22
|
-
"@graphcommerce/typescript-config-pwa": "
|
|
20
|
+
"@graphcommerce/eslint-config-pwa": "7.0.0-canary.12",
|
|
21
|
+
"@graphcommerce/prettier-config-pwa": "7.0.0-canary.12",
|
|
22
|
+
"@graphcommerce/typescript-config-pwa": "7.0.0-canary.12"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@lingui/react": "^3.13.2",
|