@graphcommerce/ecommerce-ui 9.0.0-canary.115 → 9.0.0-canary.116

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,7 @@
1
1
  # @graphcommerce/ecommerce-ui
2
2
 
3
+ ## 9.0.0-canary.116
4
+
3
5
  ## 9.0.0-canary.115
4
6
 
5
7
  ## 9.0.0-canary.114
@@ -22,6 +22,7 @@ export type ActionCardListFormProps<A, F extends FieldValues = FieldValues> = Om
22
22
  render: React.FC<ActionCardItemRenderProps<A>>
23
23
  } & ActionCardRequireOptionSelection
24
24
 
25
+ /** @public */
25
26
  export function ActionCardListForm<
26
27
  T extends ActionCardItemBase,
27
28
  F extends FieldValues = FieldValues,
@@ -28,6 +28,7 @@ export type CheckboxButtonGroupProps<T extends FieldValues> = {
28
28
  checkboxColor?: CheckboxProps['color']
29
29
  } & UseControllerProps<T>
30
30
 
31
+ /** @public */
31
32
  export function CheckboxButtonGroup<TFieldValues extends FieldValues>(
32
33
  props: CheckboxButtonGroupProps<TFieldValues>,
33
34
  ): JSX.Element {
@@ -24,6 +24,7 @@ export type CheckboxElementProps<T extends FieldValues> = Omit<CheckboxProps, 'n
24
24
  formControl?: Omit<FormControlProps<'div'>, 'required' | 'error'>
25
25
  } & Omit<ControllerProps<T>, 'render'>
26
26
 
27
+ /** @public */
27
28
  export function CheckboxElement<TFieldValues extends FieldValues>(
28
29
  props: CheckboxElementProps<TFieldValues>,
29
30
  ): JSX.Element {
@@ -7,6 +7,7 @@ import { TextFieldElement } from './TextFieldElement'
7
7
 
8
8
  export type EmailElementProps<T extends FieldValues> = TextFieldElementProps<T>
9
9
 
10
+ /** @public */
10
11
  export function EmailElement<TFieldValues extends FieldValues>(
11
12
  props: EmailElementProps<TFieldValues>,
12
13
  ): JSX.Element {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-nested-ternary */
2
- import { IconSvg, iconClose } from '@graphcommerce/next-ui'
2
+ import { iconClose, IconSvg } from '@graphcommerce/next-ui'
3
3
  import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
4
4
  import { useController } from '@graphcommerce/react-hook-form'
5
5
  import { i18n } from '@lingui/core'
@@ -35,6 +35,7 @@ export type MultiSelectElementProps<T extends FieldValues> = Omit<SelectProps, '
35
35
  const ITEM_HEIGHT = 48
36
36
  const ITEM_PADDING_TOP = 8
37
37
 
38
+ /** @public */
38
39
  export function MultiSelectElement<TFieldValues extends FieldValues>(
39
40
  props: MultiSelectElementProps<TFieldValues>,
40
41
  ): JSX.Element {
@@ -28,6 +28,7 @@ const { withState } = extendableComponent<OwnerState, typeof componentName, type
28
28
  parts,
29
29
  )
30
30
 
31
+ /** @public */
31
32
  export function NumberFieldElement<T extends FieldValues>(props: NumberFieldElementProps<T>) {
32
33
  const {
33
34
  DownProps = {},
@@ -1,4 +1,4 @@
1
- import { IconSvg, iconEye, iconEyeCrossed } from '@graphcommerce/next-ui'
1
+ import { iconEye, iconEyeCrossed, IconSvg } from '@graphcommerce/next-ui'
2
2
  import type { FieldValues } from '@graphcommerce/react-hook-form'
3
3
  import type { IconButtonProps } from '@mui/material'
4
4
  import { IconButton, InputAdornment } from '@mui/material'
@@ -11,6 +11,7 @@ export type PasswordElementProps<T extends FieldValues> = TextFieldElementProps<
11
11
  iconColor?: IconButtonProps['color']
12
12
  }
13
13
 
14
+ /** @public */
14
15
  export function PasswordElement<TFieldValues extends FieldValues>(
15
16
  props: PasswordElementProps<TFieldValues>,
16
17
  ): JSX.Element {
@@ -8,6 +8,7 @@ export type PasswordRepeatElementProps<T extends FieldValues> = PasswordElementP
8
8
  passwordFieldName: PasswordElementProps<T>['name']
9
9
  }
10
10
 
11
+ /** @public */
11
12
  export function PasswordRepeatElement<TFieldValues extends FieldValues>({
12
13
  passwordFieldName,
13
14
  ...rest
@@ -28,6 +28,7 @@ export type RadioButtonGroupProps<T extends FieldValues> = {
28
28
  row?: boolean
29
29
  } & UseControllerProps<T>
30
30
 
31
+ /** @public */
31
32
  export function RadioButtonGroup<TFieldValues extends FieldValues>(
32
33
  props: RadioButtonGroupProps<TFieldValues>,
33
34
  ): JSX.Element {
@@ -11,23 +11,21 @@ export type SelectElementProps<T extends FieldValues, O extends OptionBase> = Om
11
11
  TextFieldProps,
12
12
  'name' | 'type' | 'onChange' | 'defaultValue'
13
13
  > & {
14
- /** @deprecated Please use the rules props instead */
15
- validation?: ControllerProps<T>['rules']
16
14
  options?: O[]
17
15
  type?: 'string' | 'number'
18
16
  onChange?: (value: string | number) => void
19
17
  showValid?: boolean
20
18
  } & Omit<ControllerProps<T>, 'render'>
21
19
 
20
+ /** @public */
22
21
  export function SelectElement<TFieldValues extends FieldValues, O extends OptionBase>({
23
22
  name,
24
23
  required,
25
24
  options = [],
26
25
  type,
27
- validation,
28
26
  control,
29
27
  defaultValue,
30
- rules = validation ?? {},
28
+ rules = {},
31
29
  showValid,
32
30
  disabled,
33
31
  shouldUnregister,
@@ -10,6 +10,7 @@ export type SliderElementProps<T extends FieldValues> = Omit<SliderProps, 'contr
10
10
  formControlProps?: FormControlProps
11
11
  } & Omit<ControllerProps<T>, 'render'>
12
12
 
13
+ /** @public */
13
14
  export function SliderElement<TFieldValues extends FieldValues>({
14
15
  name,
15
16
  control,
@@ -7,6 +7,7 @@ type IProps = Omit<FormControlLabelProps, 'control'>
7
7
 
8
8
  export type SwitchElementProps<T extends FieldValues> = IProps & Omit<ControllerProps<T>, 'render'>
9
9
 
10
+ /** @public */
10
11
  export function SwitchElement<TFieldValues extends FieldValues>({
11
12
  name,
12
13
  control,
@@ -1,11 +1,12 @@
1
1
  import type { FieldValues } from '@graphcommerce/react-hook-form'
2
2
  import { phonePattern } from '@graphcommerce/react-hook-form'
3
- import { Trans, t } from '@lingui/macro'
3
+ import { t, Trans } from '@lingui/macro'
4
4
  import type { TextFieldElementProps } from './TextFieldElement'
5
5
  import { TextFieldElement } from './TextFieldElement'
6
6
 
7
7
  export type TelephoneElementProps<T extends FieldValues> = TextFieldElementProps<T>
8
8
 
9
+ /** @public */
9
10
  export function TelephoneElement<TFieldValues extends FieldValues>(
10
11
  props: TelephoneElementProps<TFieldValues>,
11
12
  ): JSX.Element {
@@ -11,20 +11,17 @@ export type TextFieldElementProps<T extends FieldValues = FieldValues> = Omit<
11
11
  TextFieldProps,
12
12
  'name' | 'defaultValue'
13
13
  > & {
14
- /** @deprecated Please use the rules props instead */
15
- validation?: UseControllerProps<T>['rules']
16
-
17
14
  showValid?: boolean
18
15
  } & UseControllerProps<T>
19
16
 
17
+ /** @public */
20
18
  export function TextFieldElement<TFieldValues extends FieldValues>({
21
- validation = {},
22
19
  type,
23
20
  required,
24
21
  name,
25
22
  control,
26
23
  defaultValue,
27
- rules = validation,
24
+ rules = {},
28
25
  shouldUnregister,
29
26
  showValid,
30
27
  disabled,
@@ -24,6 +24,7 @@ export type ToggleButtonGroupElementProps<T extends FieldValues> = ToggleButtonG
24
24
  helperText?: string
25
25
  } & Omit<ControllerProps<T>, 'render'>
26
26
 
27
+ /** @public */
27
28
  export function ToggleButtonGroupElement<TFieldValues extends FieldValues = FieldValues>({
28
29
  name,
29
30
  control,
@@ -1,5 +1,4 @@
1
1
  export * from './ActionCardListForm'
2
- export * from './AutoCompleteElement'
3
2
  export * from './CheckboxButtonGroup'
4
3
  export * from './CheckboxElement'
5
4
  export * from './EmailElement'
@@ -1,12 +1,12 @@
1
1
  import type { PreviewData } from '@graphcommerce/graphql'
2
2
  import {
3
- IconSvg,
4
- MessageSnackbar,
5
3
  iconChevronRight,
6
4
  iconClose,
7
5
  iconContrast,
8
6
  iconInfo,
9
7
  iconRefresh,
8
+ IconSvg,
9
+ MessageSnackbar,
10
10
  } from '@graphcommerce/next-ui'
11
11
  import { FormAutoSubmit, FormPersist, FormProvider, useForm } from '@graphcommerce/react-hook-form'
12
12
  import { Box, IconButton } from '@mui/material'
@@ -16,7 +16,7 @@ import { LightTooltip } from './LightTooltip'
16
16
  import { PreviewModeActions } from './PreviewModeActions'
17
17
  import { PreviewModeToolbar } from './PreviewModeToolbar'
18
18
 
19
- export function getPreviewUrl() {
19
+ function getPreviewUrl() {
20
20
  const url = new URL(window.location.href)
21
21
  url.pathname = '/api/preview'
22
22
  ;[...url.searchParams.entries()].forEach(([key]) => url.searchParams.delete(key))
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": "9.0.0-canary.115",
5
+ "version": "9.0.0-canary.116",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,12 +12,12 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.115",
16
- "@graphcommerce/graphql": "^9.0.0-canary.115",
17
- "@graphcommerce/next-ui": "^9.0.0-canary.115",
18
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.115",
19
- "@graphcommerce/react-hook-form": "^9.0.0-canary.115",
20
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.115",
15
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.116",
16
+ "@graphcommerce/graphql": "^9.0.0-canary.116",
17
+ "@graphcommerce/next-ui": "^9.0.0-canary.116",
18
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.116",
19
+ "@graphcommerce/react-hook-form": "^9.0.0-canary.116",
20
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.116",
21
21
  "@lingui/core": "^4.2.1",
22
22
  "@lingui/macro": "^4.2.1",
23
23
  "@lingui/react": "^4.2.1",
@@ -1,162 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-restricted-imports */
2
- import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
3
- import { useController } from '@graphcommerce/react-hook-form'
4
- import { i18n } from '@lingui/core'
5
- import type { AutocompleteProps, TextFieldProps } from '@mui/material'
6
- import { Autocomplete, Checkbox, CircularProgress, TextField } from '@mui/material'
7
-
8
- export type AutocompleteElementProps<
9
- F extends FieldValues,
10
- T,
11
- M extends boolean | undefined,
12
- D extends boolean | undefined,
13
- > = {
14
- options: T[]
15
- loading?: boolean
16
- multiple?: M
17
- matchId?: boolean
18
- required?: boolean
19
- label?: TextFieldProps['label']
20
- showCheckbox?: boolean
21
- autocompleteProps?: Omit<
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- AutocompleteProps<T, M, D, any>,
24
- 'name' | 'options' | 'loading' | 'renderInput'
25
- >
26
- textFieldProps?: Omit<TextFieldProps, 'name' | 'required' | 'label'>
27
- } & ControllerProps<F>
28
-
29
- type AutoDefault = {
30
- id: string | number // must keep id in case of keepObject
31
- label: string
32
- }
33
-
34
- export function AutocompleteElement<TFieldValues extends FieldValues>({
35
- textFieldProps,
36
- autocompleteProps,
37
- name,
38
- control,
39
- options,
40
- loading,
41
- showCheckbox,
42
- rules,
43
- required,
44
- multiple,
45
- matchId,
46
- label,
47
- disabled,
48
- defaultValue,
49
- shouldUnregister,
50
- }: AutocompleteElementProps<
51
- TFieldValues,
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- AutoDefault | string | any,
54
- boolean | undefined,
55
- boolean | undefined
56
- >) {
57
- const validationRules: ControllerProps<TFieldValues>['rules'] = {
58
- ...rules,
59
- ...(required && {
60
- required: rules?.required || i18n._(/* i18n */ 'This field is required'),
61
- }),
62
- }
63
-
64
- const {
65
- field: { onChange, onBlur, value, ...fieldRest },
66
- fieldState: { error },
67
- } = useController({
68
- name,
69
- control,
70
- rules: validationRules,
71
- defaultValue,
72
- disabled,
73
- shouldUnregister,
74
- })
75
-
76
- const values = Array.isArray(value) ? (value as (typeof value)[]) : [value]
77
- let currentValue = multiple ? value || [] : value || null
78
- if (matchId) {
79
- currentValue = multiple
80
- ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- values.map((i: any) => options.find((j) => (j.id || j) === i))
82
- : options.find((i) => (i.id || i) === value) || null
83
- }
84
-
85
- return (
86
- <Autocomplete
87
- {...autocompleteProps}
88
- value={currentValue}
89
- loading={loading}
90
- multiple={multiple}
91
- options={options}
92
- disableCloseOnSelect={
93
- typeof autocompleteProps?.disableCloseOnSelect === 'boolean'
94
- ? autocompleteProps.disableCloseOnSelect
95
- : !!multiple
96
- }
97
- isOptionEqualToValue={
98
- autocompleteProps?.isOptionEqualToValue
99
- ? autocompleteProps.isOptionEqualToValue
100
- : (option, v) => (v ? option.id === (v?.id || v) : false)
101
- }
102
- getOptionLabel={
103
- autocompleteProps?.getOptionLabel
104
- ? autocompleteProps.getOptionLabel
105
- : (option) => `${option?.label || option}`
106
- }
107
- onChange={(event, value, reason, details) => {
108
- let changedVal = value
109
- if (matchId) {
110
- changedVal = Array.isArray(value) ? value.map((i: any) => i?.id || i) : value?.id || value
111
- }
112
- onChange(changedVal)
113
- if (autocompleteProps?.onChange) {
114
- autocompleteProps.onChange(event, value, reason, details)
115
- }
116
- }}
117
- renderOption={
118
- autocompleteProps?.renderOption ??
119
- (showCheckbox
120
- ? (props, option, { selected }) => (
121
- <li {...props}>
122
- <Checkbox sx={{ marginRight: 1 }} checked={selected} />
123
- {autocompleteProps?.getOptionLabel?.(option) || option.label || option}
124
- </li>
125
- )
126
- : undefined)
127
- }
128
- onBlur={(event) => {
129
- onBlur()
130
- if (typeof autocompleteProps?.onBlur === 'function') {
131
- autocompleteProps.onBlur(event)
132
- }
133
- }}
134
- renderInput={(params) => (
135
- <TextField
136
- name={name}
137
- required={rules?.required ? true : required}
138
- label={label}
139
- {...textFieldProps}
140
- {...params}
141
- error={!!error}
142
- InputProps={{
143
- ...params.InputProps,
144
- endAdornment: (
145
- <>
146
- {loading ? <CircularProgress color='inherit' size={20} /> : null}
147
- {params.InputProps.endAdornment}
148
- </>
149
- ),
150
- ...textFieldProps?.InputProps,
151
- }}
152
- inputProps={{
153
- ...params.inputProps,
154
- ...textFieldProps?.inputProps,
155
- }}
156
- helperText={error ? error.message : textFieldProps?.helperText}
157
- />
158
- )}
159
- {...fieldRest}
160
- />
161
- )
162
- }