@graphcommerce/ecommerce-ui 9.0.0-canary.100 → 9.0.0-canary.103
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 +34 -1001
- package/Config.graphqls +6 -0
- package/components/ApolloError/ApolloErrorAlert.tsx +3 -3
- package/components/ApolloError/ApolloErrorFullPage.tsx +4 -3
- package/components/ApolloError/ApolloErrorSnackbar.tsx +3 -2
- package/components/ApolloError/maskNetworkError.tsx +1 -1
- package/components/ComposedSubmitButton/ComposedSubmitButton.tsx +3 -2
- package/components/ComposedSubmitButton/ComposedSubmitLinkOrButton.tsx +3 -2
- package/components/FormComponents/ActionCardListForm.tsx +24 -13
- package/components/FormComponents/AutoCompleteElement.tsx +8 -15
- package/components/FormComponents/CheckboxButtonGroup.tsx +11 -3
- package/components/FormComponents/CheckboxElement.tsx +4 -7
- package/components/FormComponents/EmailElement.tsx +4 -2
- package/components/FormComponents/MultiSelectElement.tsx +6 -3
- package/components/FormComponents/NumberFieldElement.tsx +7 -9
- package/components/FormComponents/PasswordElement.tsx +7 -4
- package/components/FormComponents/PasswordRepeatElement.tsx +4 -2
- package/components/FormComponents/RadioButtonGroup.tsx +6 -3
- package/components/FormComponents/SelectElement.tsx +5 -7
- package/components/FormComponents/SliderElement.tsx +4 -14
- package/components/FormComponents/SwitchElement.tsx +4 -2
- package/components/FormComponents/TelephoneElement.tsx +4 -2
- package/components/FormComponents/TextFieldElement.tsx +19 -7
- package/components/FormComponents/ToggleButtonGroup.tsx +6 -12
- package/components/PreviewMode/PreviewMode.tsx +11 -7
- package/components/PreviewMode/PreviewModeActions.tsx +2 -2
- package/components/PreviewMode/PreviewModeToolbar.tsx +1 -1
- package/components/PreviewMode/previewModeDefaults.ts +1 -1
- package/components/PreviewMode/usePreviewModeForm.ts +1 -1
- package/components/WaitForQueries/WaitForQueries.tsx +3 -6
- package/package.json +8 -8
- package/route/preview.ts +2 -2
package/Config.graphqls
CHANGED
|
@@ -4,7 +4,13 @@ enum WebsitePermissions {
|
|
|
4
4
|
# DISABLED will be implemented later
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
"""
|
|
8
|
+
Permissions input
|
|
9
|
+
"""
|
|
7
10
|
input GraphCommercePermissions {
|
|
11
|
+
"""
|
|
12
|
+
Allows the option to require login or completely disable the site.
|
|
13
|
+
"""
|
|
8
14
|
website: WebsitePermissions
|
|
9
15
|
}
|
|
10
16
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApolloError } from '@graphcommerce/graphql'
|
|
1
|
+
import type { ApolloError } from '@graphcommerce/graphql'
|
|
2
2
|
import { extendableComponent } from '@graphcommerce/next-ui/Styles/extendableComponent'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { AlertProps, SxProps, Theme } from '@mui/material'
|
|
4
|
+
import { Alert, Box } from '@mui/material'
|
|
5
5
|
import { maskNetworkError } from './maskNetworkError'
|
|
6
6
|
|
|
7
7
|
const { classes, selectors } = extendableComponent('ApolloErrorAlert', ['root', 'alert'] as const)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
1
|
+
import type { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
+
import type { FullPageMessageProps } from '@graphcommerce/next-ui'
|
|
3
|
+
import { FullPageMessage } from '@graphcommerce/next-ui'
|
|
3
4
|
import { Trans } from '@lingui/react'
|
|
4
|
-
import { AlertProps } from '@mui/material'
|
|
5
|
+
import type { AlertProps } from '@mui/material'
|
|
5
6
|
import { ApolloErrorAlert } from './ApolloErrorAlert'
|
|
6
7
|
import { maskNetworkError } from './maskNetworkError'
|
|
7
8
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
1
|
+
import type { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
+
import type { ErrorSnackbarProps } from '@graphcommerce/next-ui'
|
|
3
|
+
import { ErrorSnackbar } from '@graphcommerce/next-ui'
|
|
3
4
|
import { maskNetworkError } from './maskNetworkError'
|
|
4
5
|
|
|
5
6
|
export type ApolloErrorSnackbarProps = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerError, ServerParseError } from '@graphcommerce/graphql'
|
|
1
|
+
import type { ServerError, ServerParseError } from '@graphcommerce/graphql'
|
|
2
2
|
import { Trans } from '@lingui/react'
|
|
3
3
|
|
|
4
4
|
function isServerError(error: Error | ServerParseError | ServerError | null): error is ServerError {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ButtonProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { iconChevronRight, IconSvg, Button } from '@graphcommerce/next-ui'
|
|
3
|
+
import type { ComposedSubmitRenderComponentProps } from '@graphcommerce/react-hook-form'
|
|
3
4
|
import { forwardRef } from 'react'
|
|
4
5
|
|
|
5
6
|
type ComposedSubmitButtonProps = ComposedSubmitRenderComponentProps &
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { LinkOrButtonProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { iconChevronRight, LinkOrButton, IconSvg } from '@graphcommerce/next-ui'
|
|
3
|
+
import type { ComposedSubmitRenderComponentProps } from '@graphcommerce/react-hook-form'
|
|
3
4
|
import { forwardRef } from 'react'
|
|
4
5
|
|
|
5
6
|
type ComposedLinkOrButtonProps = ComposedSubmitRenderComponentProps &
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { ActionCardListProps, ActionCardProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { ActionCardList } from '@graphcommerce/next-ui'
|
|
3
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
4
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
5
|
+
import type { MouseEventHandler } from 'react'
|
|
6
|
+
import React, { useCallback } from 'react'
|
|
4
7
|
|
|
5
8
|
export type ActionCardItemBase = Pick<ActionCardProps, 'value'>
|
|
6
9
|
|
|
@@ -40,11 +43,14 @@ export function ActionCardListForm<
|
|
|
40
43
|
} = props
|
|
41
44
|
const RenderItem = render as React.FC<ActionCardItemRenderProps<ActionCardItemBase>>
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const onSelect = useCallback(
|
|
47
|
+
(itemValue: unknown, selectValues: unknown) =>
|
|
48
|
+
multiple
|
|
49
|
+
? Array.isArray(selectValues) &&
|
|
50
|
+
selectValues.some((selectValue) => selectValue === itemValue)
|
|
51
|
+
: selectValues === itemValue,
|
|
52
|
+
[multiple],
|
|
53
|
+
)
|
|
48
54
|
|
|
49
55
|
const {
|
|
50
56
|
field: { onChange, value, ref },
|
|
@@ -60,6 +66,14 @@ export function ActionCardListForm<
|
|
|
60
66
|
shouldUnregister,
|
|
61
67
|
})
|
|
62
68
|
|
|
69
|
+
const handleReset = useCallback(
|
|
70
|
+
(e: React.MouseEvent<HTMLElement>) => {
|
|
71
|
+
e.preventDefault()
|
|
72
|
+
if (!requireOptionSelection) onChange(null)
|
|
73
|
+
},
|
|
74
|
+
[onChange, requireOptionSelection],
|
|
75
|
+
)
|
|
76
|
+
|
|
63
77
|
return (
|
|
64
78
|
<ActionCardList
|
|
65
79
|
{...other}
|
|
@@ -67,7 +81,7 @@ export function ActionCardListForm<
|
|
|
67
81
|
required={required}
|
|
68
82
|
value={value}
|
|
69
83
|
ref={ref}
|
|
70
|
-
onChange={(_,
|
|
84
|
+
onChange={(_, incoming) => onChange(incoming)}
|
|
71
85
|
error={formState.isSubmitted && !!fieldState.error}
|
|
72
86
|
errorMessage={fieldState.error?.message}
|
|
73
87
|
>
|
|
@@ -77,10 +91,7 @@ export function ActionCardListForm<
|
|
|
77
91
|
key={`${item.value}`}
|
|
78
92
|
value={item.value}
|
|
79
93
|
selected={onSelect(item.value, value)}
|
|
80
|
-
onReset={
|
|
81
|
-
e.preventDefault()
|
|
82
|
-
if (!requireOptionSelection) onChange(null)
|
|
83
|
-
}}
|
|
94
|
+
onReset={handleReset}
|
|
84
95
|
/>
|
|
85
96
|
))}
|
|
86
97
|
</ActionCardList>
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-restricted-imports */
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ControllerProps,
|
|
5
|
-
FieldValues,
|
|
6
|
-
useController,
|
|
7
|
-
} from '@graphcommerce/react-hook-form'
|
|
2
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
3
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
8
4
|
import { i18n } from '@lingui/core'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
AutocompleteProps,
|
|
12
|
-
Checkbox,
|
|
13
|
-
TextField,
|
|
14
|
-
TextFieldProps,
|
|
15
|
-
CircularProgress,
|
|
16
|
-
} from '@mui/material'
|
|
5
|
+
import type { AutocompleteProps, TextFieldProps } from '@mui/material'
|
|
6
|
+
import { Autocomplete, Checkbox, TextField, CircularProgress } from '@mui/material'
|
|
17
7
|
|
|
18
8
|
export type AutocompleteElementProps<
|
|
19
9
|
F extends FieldValues,
|
|
@@ -29,6 +19,7 @@ export type AutocompleteElementProps<
|
|
|
29
19
|
label?: TextFieldProps['label']
|
|
30
20
|
showCheckbox?: boolean
|
|
31
21
|
autocompleteProps?: Omit<
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
23
|
AutocompleteProps<T, M, D, any>,
|
|
33
24
|
'name' | 'options' | 'loading' | 'renderInput'
|
|
34
25
|
>
|
|
@@ -58,6 +49,7 @@ export function AutocompleteElement<TFieldValues extends FieldValues>({
|
|
|
58
49
|
shouldUnregister,
|
|
59
50
|
}: AutocompleteElementProps<
|
|
60
51
|
TFieldValues,
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
53
|
AutoDefault | string | any,
|
|
62
54
|
boolean | undefined,
|
|
63
55
|
boolean | undefined
|
|
@@ -85,7 +77,8 @@ export function AutocompleteElement<TFieldValues extends FieldValues>({
|
|
|
85
77
|
let currentValue = multiple ? value || [] : value || null
|
|
86
78
|
if (matchId) {
|
|
87
79
|
currentValue = multiple
|
|
88
|
-
?
|
|
80
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
values.map((i: any) => options.find((j) => (j.id || j) === i))
|
|
89
82
|
: options.find((i) => (i.id || i) === value) || null
|
|
90
83
|
}
|
|
91
84
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FieldValues, UseControllerProps } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { i18n } from '@lingui/core'
|
|
4
|
+
import type { CheckboxProps } from '@mui/material'
|
|
3
5
|
import {
|
|
4
6
|
Checkbox,
|
|
5
|
-
CheckboxProps,
|
|
6
7
|
FormControl,
|
|
7
8
|
FormControlLabel,
|
|
8
9
|
FormGroup,
|
|
@@ -12,12 +13,14 @@ import {
|
|
|
12
13
|
} from '@mui/material'
|
|
13
14
|
|
|
14
15
|
export type CheckboxButtonGroupProps<T extends FieldValues> = {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
17
|
options: { id: string | number; label: string }[] | any[]
|
|
16
18
|
helperText?: string
|
|
17
19
|
required?: boolean
|
|
18
20
|
label?: string
|
|
19
21
|
labelKey?: string
|
|
20
22
|
valueKey?: string
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
21
24
|
onChange?: Function
|
|
22
25
|
returnObject?: boolean
|
|
23
26
|
disabled?: boolean
|
|
@@ -62,13 +65,17 @@ export function CheckboxButtonGroup<TFieldValues extends FieldValues>(
|
|
|
62
65
|
const parsedHelperText = error ? error.message : helperText
|
|
63
66
|
|
|
64
67
|
const handleChange = (index: number | string) => {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
69
|
const newArray: (string | number)[] | any[] = [...value]
|
|
66
70
|
const exists =
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
72
|
value.findIndex((i: any) => (returnObject ? i[valueKey] === index : i === index)) === -1
|
|
68
73
|
if (exists) {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
69
75
|
newArray.push(returnObject ? options.find((i) => i[valueKey] === index) : index)
|
|
70
76
|
} else {
|
|
71
77
|
newArray.splice(
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
79
|
value.findIndex((i: any) => (returnObject ? i[valueKey] === index : i === index)),
|
|
73
80
|
1,
|
|
74
81
|
)
|
|
@@ -93,7 +100,7 @@ export function CheckboxButtonGroup<TFieldValues extends FieldValues>(
|
|
|
93
100
|
)
|
|
94
101
|
}
|
|
95
102
|
const isChecked =
|
|
96
|
-
value.findIndex((item
|
|
103
|
+
value.findIndex((item) =>
|
|
97
104
|
returnObject ? item[valueKey] === optionKey : item === optionKey,
|
|
98
105
|
) !== -1
|
|
99
106
|
return (
|
|
@@ -107,6 +114,7 @@ export function CheckboxButtonGroup<TFieldValues extends FieldValues>(
|
|
|
107
114
|
value={optionKey}
|
|
108
115
|
checked={isChecked}
|
|
109
116
|
disabled={disabled}
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
110
118
|
onChange={() => handleChange(optionKey)}
|
|
111
119
|
/>
|
|
112
120
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { ControllerProps, FieldValues
|
|
1
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { i18n } from '@lingui/core'
|
|
3
|
-
import {
|
|
4
|
-
Checkbox,
|
|
4
|
+
import type {
|
|
5
5
|
CheckboxProps,
|
|
6
|
-
FormControl,
|
|
7
|
-
FormControlLabel,
|
|
8
6
|
FormControlLabelProps,
|
|
9
7
|
FormControlProps,
|
|
10
|
-
FormGroup,
|
|
11
|
-
FormHelperText,
|
|
12
8
|
SxProps,
|
|
13
9
|
Theme,
|
|
14
10
|
} from '@mui/material'
|
|
11
|
+
import { Checkbox, FormControl, FormControlLabel, FormGroup, FormHelperText } from '@mui/material'
|
|
15
12
|
|
|
16
13
|
export type CheckboxElementProps<T extends FieldValues> = Omit<CheckboxProps, 'name'> & {
|
|
17
14
|
label?: FormControlLabelProps['label']
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { emailPattern } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { i18n } from '@lingui/core'
|
|
3
4
|
import { Trans } from '@lingui/react'
|
|
4
|
-
import {
|
|
5
|
+
import type { TextFieldElementProps } from './TextFieldElement'
|
|
6
|
+
import { TextFieldElement } from './TextFieldElement'
|
|
5
7
|
|
|
6
8
|
export type EmailElementProps<T extends FieldValues> = TextFieldElementProps<T>
|
|
7
9
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
2
|
import { IconSvg, iconClose } from '@graphcommerce/next-ui'
|
|
3
|
-
import { FieldValues, ControllerProps
|
|
3
|
+
import type { FieldValues, ControllerProps } from '@graphcommerce/react-hook-form'
|
|
4
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
4
5
|
import { i18n } from '@lingui/core'
|
|
6
|
+
import type { FormControlProps, SelectProps } from '@mui/material'
|
|
5
7
|
import {
|
|
6
8
|
Checkbox,
|
|
7
9
|
Chip,
|
|
8
10
|
FormControl,
|
|
9
|
-
FormControlProps,
|
|
10
11
|
FormHelperText,
|
|
11
12
|
InputLabel,
|
|
12
13
|
ListItemText,
|
|
13
14
|
MenuItem,
|
|
14
15
|
Select,
|
|
15
|
-
SelectProps,
|
|
16
16
|
} from '@mui/material'
|
|
17
17
|
|
|
18
18
|
export type MultiSelectElementProps<T extends FieldValues> = Omit<SelectProps, 'value'> & {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
20
|
options: { id: string | number; label: string }[] | any[]
|
|
20
21
|
label?: string
|
|
21
22
|
itemKey?: string
|
|
@@ -127,12 +128,14 @@ export function MultiSelectElement<TFieldValues extends FieldValues>(
|
|
|
127
128
|
: showChips
|
|
128
129
|
? (selected) => (
|
|
129
130
|
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
|
|
131
|
+
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
|
130
132
|
{((selected as any[]) || []).map((selectedValue) => (
|
|
131
133
|
<Chip
|
|
132
134
|
key={selectedValue}
|
|
133
135
|
label={selectedValue}
|
|
134
136
|
style={{ display: 'flex', flexWrap: 'wrap' }}
|
|
135
137
|
onDelete={() => {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
139
|
onChange(value.filter((i: any) => i !== selectedValue))
|
|
137
140
|
// setValue(name, formValue.filter((i: any) => i !== value), { shouldValidate: true })
|
|
138
141
|
}}
|
|
@@ -5,14 +5,11 @@ import {
|
|
|
5
5
|
IconSvg,
|
|
6
6
|
responsiveVal,
|
|
7
7
|
} from '@graphcommerce/next-ui'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
ControllerProps,
|
|
11
|
-
FieldValues,
|
|
12
|
-
useController,
|
|
13
|
-
} from '@graphcommerce/react-hook-form'
|
|
8
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
9
|
+
import { Controller, useController } from '@graphcommerce/react-hook-form'
|
|
14
10
|
import { i18n } from '@lingui/core'
|
|
15
|
-
import { IconButtonProps, SxProps, Theme,
|
|
11
|
+
import type { IconButtonProps, SxProps, Theme, TextFieldProps } from '@mui/material'
|
|
12
|
+
import { TextField, Fab } from '@mui/material'
|
|
16
13
|
|
|
17
14
|
export type NumberFieldElementProps<T extends FieldValues = FieldValues> = Omit<
|
|
18
15
|
TextFieldProps,
|
|
@@ -24,7 +21,7 @@ export type NumberFieldElementProps<T extends FieldValues = FieldValues> = Omit<
|
|
|
24
21
|
} & Omit<ControllerProps<T>, 'render'>
|
|
25
22
|
|
|
26
23
|
type OwnerState = { size?: 'small' | 'medium' }
|
|
27
|
-
const componentName = 'TextInputNumber'
|
|
24
|
+
const componentName = 'TextInputNumber'
|
|
28
25
|
const parts = ['quantity', 'quantityInput', 'button'] as const
|
|
29
26
|
const { withState } = extendableComponent<OwnerState, typeof componentName, typeof parts>(
|
|
30
27
|
componentName,
|
|
@@ -36,6 +33,7 @@ export function NumberFieldElement<T extends FieldValues>(props: NumberFieldElem
|
|
|
36
33
|
DownProps = {},
|
|
37
34
|
UpProps = {},
|
|
38
35
|
inputProps = {},
|
|
36
|
+
InputProps = {},
|
|
39
37
|
sx = [],
|
|
40
38
|
size = 'medium',
|
|
41
39
|
control,
|
|
@@ -113,7 +111,7 @@ export function NumberFieldElement<T extends FieldValues>(props: NumberFieldElem
|
|
|
113
111
|
]}
|
|
114
112
|
autoComplete='off'
|
|
115
113
|
InputProps={{
|
|
116
|
-
...
|
|
114
|
+
...InputProps,
|
|
117
115
|
startAdornment: (
|
|
118
116
|
<Fab
|
|
119
117
|
aria-label={i18n._(/* i18n */ 'Decrease')}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { iconEye, iconEyeCrossed, IconSvg } from '@graphcommerce/next-ui'
|
|
2
|
-
import { FieldValues } from '@graphcommerce/react-hook-form'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import type { FieldValues } from '@graphcommerce/react-hook-form'
|
|
3
|
+
import type { IconButtonProps } from '@mui/material'
|
|
4
|
+
import { IconButton, InputAdornment } from '@mui/material'
|
|
5
|
+
import type { MouseEvent } from 'react'
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
import type { TextFieldElementProps } from './TextFieldElement'
|
|
8
|
+
import { TextFieldElement } from './TextFieldElement'
|
|
6
9
|
|
|
7
10
|
export type PasswordElementProps<T extends FieldValues> = TextFieldElementProps<T> & {
|
|
8
11
|
iconColor?: IconButtonProps['color']
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useWatch } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { i18n } from '@lingui/core'
|
|
3
|
-
import {
|
|
4
|
+
import type { PasswordElementProps } from './PasswordElement'
|
|
5
|
+
import { PasswordElement } from './PasswordElement'
|
|
4
6
|
|
|
5
7
|
export type PasswordRepeatElementProps<T extends FieldValues> = PasswordElementProps<T> & {
|
|
6
8
|
passwordFieldName: PasswordElementProps<T>['name']
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FieldValues, UseControllerProps } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { i18n } from '@lingui/core'
|
|
3
4
|
import {
|
|
4
5
|
FormControl,
|
|
@@ -9,9 +10,10 @@ import {
|
|
|
9
10
|
RadioGroup,
|
|
10
11
|
useTheme,
|
|
11
12
|
} from '@mui/material'
|
|
12
|
-
import { ChangeEvent } from 'react'
|
|
13
|
+
import type { ChangeEvent } from 'react'
|
|
13
14
|
|
|
14
15
|
export type RadioButtonGroupProps<T extends FieldValues> = {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
17
|
options: { label: string; id: string | number }[] | any[]
|
|
16
18
|
helperText?: string
|
|
17
19
|
required?: boolean
|
|
@@ -20,6 +22,7 @@ export type RadioButtonGroupProps<T extends FieldValues> = {
|
|
|
20
22
|
valueKey?: string
|
|
21
23
|
type?: 'number' | 'string'
|
|
22
24
|
emptyOptionLabel?: 'string'
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
26
|
onChange?: (value: any) => void
|
|
24
27
|
returnObject?: boolean
|
|
25
28
|
row?: boolean
|
|
@@ -95,7 +98,7 @@ export function RadioButtonGroup<TFieldValues extends FieldValues>(
|
|
|
95
98
|
value=''
|
|
96
99
|
/>
|
|
97
100
|
)}
|
|
98
|
-
{options.map((option
|
|
101
|
+
{options.map((option) => {
|
|
99
102
|
const optionKey = option[valueKey]
|
|
100
103
|
if (!optionKey) {
|
|
101
104
|
console.error(
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { InputCheckmark } from '@graphcommerce/next-ui'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ControllerProps,
|
|
5
|
-
FieldValues,
|
|
6
|
-
useController,
|
|
7
|
-
} from '@graphcommerce/react-hook-form'
|
|
2
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
3
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
8
4
|
import { i18n } from '@lingui/core'
|
|
9
|
-
import {
|
|
5
|
+
import type { TextFieldProps } from '@mui/material'
|
|
6
|
+
import { MenuItem, TextField } from '@mui/material'
|
|
10
7
|
|
|
11
8
|
type OptionBase = { id: string | number; label: string | number }
|
|
12
9
|
|
|
@@ -87,6 +84,7 @@ export function SelectElement<TFieldValues extends FieldValues, O extends Option
|
|
|
87
84
|
),
|
|
88
85
|
}}
|
|
89
86
|
>
|
|
87
|
+
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
|
|
90
88
|
{isNativeSelect && <option />}
|
|
91
89
|
{options.map((item) => (
|
|
92
90
|
<ChildComponent key={item.id} value={item.id}>
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
FieldError,
|
|
4
|
-
FieldValues,
|
|
5
|
-
useController,
|
|
6
|
-
} from '@graphcommerce/react-hook-form'
|
|
1
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
7
3
|
import { i18n } from '@lingui/core'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
FormControlProps,
|
|
11
|
-
FormHelperText,
|
|
12
|
-
FormLabel,
|
|
13
|
-
Slider,
|
|
14
|
-
SliderProps,
|
|
15
|
-
} from '@mui/material'
|
|
4
|
+
import type { FormControlProps, SliderProps } from '@mui/material'
|
|
5
|
+
import { FormControl, FormHelperText, FormLabel, Slider } from '@mui/material'
|
|
16
6
|
|
|
17
7
|
export type SliderElementProps<T extends FieldValues> = Omit<SliderProps, 'control'> & {
|
|
18
8
|
label?: string
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { FieldValues, ControllerProps
|
|
2
|
-
import {
|
|
1
|
+
import type { FieldValues, ControllerProps } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
3
|
+
import type { FormControlLabelProps } from '@mui/material'
|
|
4
|
+
import { FormControlLabel, Switch } from '@mui/material'
|
|
3
5
|
|
|
4
6
|
type IProps = Omit<FormControlLabelProps, 'control'>
|
|
5
7
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { FieldValues
|
|
1
|
+
import type { FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { phonePattern } from '@graphcommerce/react-hook-form'
|
|
2
3
|
import { Trans, t } from '@lingui/macro'
|
|
3
|
-
import {
|
|
4
|
+
import type { TextFieldElementProps } from './TextFieldElement'
|
|
5
|
+
import { TextFieldElement } from './TextFieldElement'
|
|
4
6
|
|
|
5
7
|
export type TelephoneElementProps<T extends FieldValues> = TextFieldElementProps<T>
|
|
6
8
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
2
|
import { InputCheckmark } from '@graphcommerce/next-ui'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
UseControllerProps,
|
|
6
|
-
emailPattern,
|
|
7
|
-
useController,
|
|
8
|
-
} from '@graphcommerce/react-hook-form'
|
|
3
|
+
import type { FieldValues, UseControllerProps } from '@graphcommerce/react-hook-form'
|
|
4
|
+
import { emailPattern, useController } from '@graphcommerce/react-hook-form'
|
|
9
5
|
import { i18n } from '@lingui/core'
|
|
10
|
-
import {
|
|
6
|
+
import type { TextFieldProps } from '@mui/material'
|
|
7
|
+
import { TextField } from '@mui/material'
|
|
8
|
+
import React, { useState } from 'react'
|
|
11
9
|
|
|
12
10
|
export type TextFieldElementProps<T extends FieldValues = FieldValues> = Omit<
|
|
13
11
|
TextFieldProps,
|
|
@@ -48,11 +46,24 @@ export function TextFieldElement<TFieldValues extends FieldValues>({
|
|
|
48
46
|
fieldState: { error },
|
|
49
47
|
} = useController({ name, control, rules, defaultValue, shouldUnregister, disabled })
|
|
50
48
|
|
|
49
|
+
// https://stackoverflow.com/questions/76830737/chrome-autofill-causes-textbox-collision-for-textfield-label-and-value
|
|
50
|
+
const [hasAutofill, setHasAutofill] = useState(false)
|
|
51
|
+
const shrink = hasAutofill || rest.InputLabelProps?.shrink || Boolean(value)
|
|
52
|
+
const onAnimationStart = (e: React.AnimationEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
53
|
+
if (e.target instanceof HTMLElement) {
|
|
54
|
+
const autofilled = !!e.target.matches('*:-webkit-autofill')
|
|
55
|
+
if (e.animationName === 'mui-auto-fill') setHasAutofill(autofilled)
|
|
56
|
+
if (e.animationName === 'mui-auto-fill-cancel') setHasAutofill(autofilled)
|
|
57
|
+
}
|
|
58
|
+
return rest.inputProps?.onAnimationStart?.(e)
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
return (
|
|
52
62
|
<TextField
|
|
53
63
|
{...rest}
|
|
54
64
|
{...field}
|
|
55
65
|
value={value}
|
|
66
|
+
inputProps={{ ...rest.inputProps, onAnimationStart }}
|
|
56
67
|
onChange={(ev) => {
|
|
57
68
|
onChange(type === 'number' && ev.target.value ? Number(ev.target.value) : ev.target.value)
|
|
58
69
|
rest.onChange?.(ev)
|
|
@@ -62,6 +73,7 @@ export function TextFieldElement<TFieldValues extends FieldValues>({
|
|
|
62
73
|
type={type}
|
|
63
74
|
error={Boolean(error) || rest.error}
|
|
64
75
|
helperText={error ? error.message : rest.helperText}
|
|
76
|
+
InputLabelProps={{ ...rest.InputLabelProps, shrink }}
|
|
65
77
|
InputProps={{
|
|
66
78
|
...rest.InputProps,
|
|
67
79
|
endAdornment:
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
FieldError,
|
|
4
|
-
FieldValues,
|
|
5
|
-
useController,
|
|
6
|
-
} from '@graphcommerce/react-hook-form'
|
|
1
|
+
import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
|
|
2
|
+
import { useController } from '@graphcommerce/react-hook-form'
|
|
7
3
|
import { i18n } from '@lingui/core'
|
|
4
|
+
import type { FormLabelProps, ToggleButtonGroupProps, ToggleButtonProps } from '@mui/material'
|
|
8
5
|
import {
|
|
9
6
|
FormControl,
|
|
10
7
|
FormHelperText,
|
|
11
8
|
FormLabel,
|
|
12
|
-
FormLabelProps,
|
|
13
9
|
ToggleButton,
|
|
14
10
|
ToggleButtonGroup,
|
|
15
|
-
ToggleButtonGroupProps,
|
|
16
|
-
ToggleButtonProps,
|
|
17
11
|
} from '@mui/material'
|
|
18
|
-
import { ReactNode } from 'react'
|
|
12
|
+
import type { ReactNode } from 'react'
|
|
19
13
|
|
|
20
14
|
type SingleToggleButtonProps = Omit<ToggleButtonProps, 'value' | 'children'> & {
|
|
21
15
|
id: number | string
|
|
@@ -87,9 +81,9 @@ export function ToggleButtonGroupElement<TFieldValues extends FieldValues = Fiel
|
|
|
87
81
|
}
|
|
88
82
|
}}
|
|
89
83
|
>
|
|
90
|
-
{options.map(({ label, id, ...toggleProps }) => (
|
|
84
|
+
{options.map(({ label: labelVal, id, ...toggleProps }) => (
|
|
91
85
|
<ToggleButton value={id} {...toggleProps} key={id}>
|
|
92
|
-
{
|
|
86
|
+
{labelVal}
|
|
93
87
|
</ToggleButton>
|
|
94
88
|
))}
|
|
95
89
|
</ToggleButtonGroup>
|