@graphcommerce/ecommerce-ui 8.0.3-canary.4 → 8.0.3-canary.6

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
+ ## 8.0.3-canary.6
4
+
5
+ ## 8.0.3-canary.5
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2212](https://github.com/graphcommerce-org/graphcommerce/pull/2212) [`e12d1dc`](https://github.com/graphcommerce-org/graphcommerce/commit/e12d1dc201bf7b23a996bd58a256a117b91a9334) - Rename validation to rules for all Form field components and deprecate validation
10
+ ([@paales](https://github.com/paales))
11
+
3
12
  ## 8.0.3-canary.4
4
13
 
5
14
  ### Patch Changes
@@ -21,6 +21,7 @@ export type CheckboxButtonGroupProps<T extends FieldValues> = {
21
21
  options: { id: string | number; label: string }[] | any[]
22
22
  helperText?: string
23
23
  required?: boolean
24
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
24
25
  parseError?: (error: FieldError) => string
25
26
  label?: string
26
27
  labelKey?: string
@@ -19,6 +19,7 @@ import {
19
19
  } from '@mui/material'
20
20
 
21
21
  export type CheckboxElementProps<T extends FieldValues> = Omit<CheckboxProps, 'name'> & {
22
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
22
23
  parseError?: (error: FieldError) => string
23
24
  label?: FormControlLabelProps['label']
24
25
  helperText?: string
@@ -27,6 +27,7 @@ export type MultiSelectElementProps<T extends FieldValues> = Omit<SelectProps, '
27
27
  itemValue?: string
28
28
  itemLabel?: string
29
29
  required?: boolean
30
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
30
31
  parseError?: (error: FieldError) => string
31
32
  minWidth?: number
32
33
  menuMaxHeight?: number
@@ -14,7 +14,7 @@ export function PasswordRepeatElement<TFieldValues extends FieldValues>({
14
14
  return (
15
15
  <PasswordElement
16
16
  {...rest}
17
- validation={{
17
+ rules={{
18
18
  validate: (value: string) =>
19
19
  value === pwValue || i18n._(/* i18n */ "Passwords don't match"),
20
20
  }}
@@ -20,6 +20,7 @@ export type RadioButtonGroupProps<T extends FieldValues> = {
20
20
  options: { label: string; id: string | number }[] | any[]
21
21
  helperText?: string
22
22
  required?: boolean
23
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
23
24
  parseError?: (error: FieldError) => string
24
25
  label?: string
25
26
  labelKey?: string
@@ -8,6 +8,7 @@ export type SelectElementProps<T extends FieldValues, O extends OptionBase> = Om
8
8
  TextFieldProps,
9
9
  'name' | 'type' | 'onChange' | 'defaultValue'
10
10
  > & {
11
+ /** @deprecated Please use the rules props instead */
11
12
  validation?: ControllerProps<T>['rules']
12
13
  options?: O[]
13
14
  type?: 'string' | 'number'
@@ -19,22 +20,23 @@ export function SelectElement<TFieldValues extends FieldValues, O extends Option
19
20
  required,
20
21
  options = [],
21
22
  type,
22
- validation = {},
23
+ validation,
23
24
  control,
24
25
  defaultValue,
26
+ rules = validation ?? {},
25
27
  ...rest
26
28
  }: SelectElementProps<TFieldValues, O>): JSX.Element {
27
29
  const isNativeSelect = !!rest.SelectProps?.native
28
30
  const ChildComponent = isNativeSelect ? 'option' : MenuItem
29
31
 
30
- if (required && !validation.required) {
31
- validation.required = i18n._(/* i18n */ 'This field is required')
32
+ if (required && !rules.required) {
33
+ rules.required = i18n._(/* i18n */ 'This field is required')
32
34
  }
33
35
 
34
36
  return (
35
37
  <Controller
36
38
  name={name}
37
- rules={validation}
39
+ rules={rules}
38
40
  control={control}
39
41
  defaultValue={defaultValue}
40
42
  render={({ field: { onChange, value, ref, ...field }, fieldState: { invalid, error } }) => {
@@ -16,6 +16,7 @@ import {
16
16
 
17
17
  export type SliderElementProps<T extends FieldValues> = Omit<SliderProps, 'control'> & {
18
18
  label?: string
19
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
19
20
  parseError?: (error: FieldError) => string
20
21
  required?: boolean
21
22
  formControlProps?: FormControlProps
@@ -1,10 +1,5 @@
1
1
  /* eslint-disable no-nested-ternary */
2
- import {
3
- Controller,
4
- FieldError,
5
- FieldValues,
6
- UseControllerProps,
7
- } from '@graphcommerce/react-hook-form'
2
+ import { Controller, FieldValues, UseControllerProps } from '@graphcommerce/react-hook-form'
8
3
  import { i18n } from '@lingui/core'
9
4
  import { TextField, TextFieldProps } from '@mui/material'
10
5
 
@@ -12,8 +7,9 @@ export type TextFieldElementProps<T extends FieldValues = FieldValues> = Omit<
12
7
  TextFieldProps,
13
8
  'name' | 'defaultValue'
14
9
  > & {
10
+ /** @deprecated Please use the rules props instead */
15
11
  validation?: UseControllerProps<T>['rules']
16
- } & Omit<UseControllerProps<T>, 'rules'>
12
+ } & UseControllerProps<T>
17
13
 
18
14
  export function TextFieldElement<TFieldValues extends FieldValues>({
19
15
  validation = {},
@@ -22,14 +18,15 @@ export function TextFieldElement<TFieldValues extends FieldValues>({
22
18
  name,
23
19
  control,
24
20
  defaultValue,
21
+ rules = validation,
25
22
  ...rest
26
23
  }: TextFieldElementProps<TFieldValues>): JSX.Element {
27
- if (required && !validation.required) {
28
- validation.required = i18n._(/* i18n */ 'This field is required')
24
+ if (required && !rules.required) {
25
+ rules.required = i18n._(/* i18n */ 'This field is required')
29
26
  }
30
27
 
31
- if (type === 'email' && !validation.pattern) {
32
- validation.pattern = {
28
+ if (type === 'email' && !rules.pattern) {
29
+ rules.pattern = {
33
30
  // eslint-disable-next-line no-useless-escape
34
31
  value:
35
32
  /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
@@ -41,7 +38,7 @@ export function TextFieldElement<TFieldValues extends FieldValues>({
41
38
  <Controller
42
39
  name={name}
43
40
  control={control}
44
- rules={validation}
41
+ rules={rules}
45
42
  defaultValue={defaultValue}
46
43
  render={({ field: { onChange, ref, ...field }, fieldState: { error } }) => (
47
44
  <TextField
@@ -25,6 +25,7 @@ type SingleToggleButtonProps = Omit<ToggleButtonProps, 'value' | 'children'> & {
25
25
  export type ToggleButtonGroupElementProps<T extends FieldValues> = ToggleButtonGroupProps & {
26
26
  required?: boolean
27
27
  label?: string
28
+ /** @deprecated Form value parsing should happen in the handleSubmit function of the form */
28
29
  parseError?: (error: FieldError) => string
29
30
  options: SingleToggleButtonProps[]
30
31
  formLabelProps?: FormLabelProps
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": "8.0.3-canary.4",
5
+ "version": "8.0.3-canary.6",
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": "^8.0.3-canary.4",
16
- "@graphcommerce/graphql": "^8.0.3-canary.4",
17
- "@graphcommerce/next-ui": "^8.0.3-canary.4",
18
- "@graphcommerce/prettier-config-pwa": "^8.0.3-canary.4",
19
- "@graphcommerce/react-hook-form": "^8.0.3-canary.4",
20
- "@graphcommerce/typescript-config-pwa": "^8.0.3-canary.4",
15
+ "@graphcommerce/eslint-config-pwa": "^8.0.3-canary.6",
16
+ "@graphcommerce/graphql": "^8.0.3-canary.6",
17
+ "@graphcommerce/next-ui": "^8.0.3-canary.6",
18
+ "@graphcommerce/prettier-config-pwa": "^8.0.3-canary.6",
19
+ "@graphcommerce/react-hook-form": "^8.0.3-canary.6",
20
+ "@graphcommerce/typescript-config-pwa": "^8.0.3-canary.6",
21
21
  "@lingui/core": "^4.2.1",
22
22
  "@lingui/macro": "^4.2.1",
23
23
  "@lingui/react": "^4.2.1",