@graphcommerce/ecommerce-ui 1.5.2 → 1.5.4

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,24 @@
1
1
  # @graphcommerce/ecommerce-ui
2
2
 
3
+ ## 1.5.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1655](https://github.com/graphcommerce-org/graphcommerce/pull/1655) [`3dde492ad`](https://github.com/graphcommerce-org/graphcommerce/commit/3dde492ad3a49d96481eeb7453fb305d0017b1a5) Thanks [@FrankHarland](https://github.com/FrankHarland)! - Added Google Analytics support.
8
+
9
+ - Updated dependencies [[`9e630670f`](https://github.com/graphcommerce-org/graphcommerce/commit/9e630670ff6c952ab7b938d890b5509804985cf3), [`cf3518499`](https://github.com/graphcommerce-org/graphcommerce/commit/cf351849999ad6fe73ce2bb258098a7dd301d517), [`2e9fa5984`](https://github.com/graphcommerce-org/graphcommerce/commit/2e9fa5984a07ff14fc1b3a4f62189a26e8e3ecdd), [`adf13069a`](https://github.com/graphcommerce-org/graphcommerce/commit/adf13069af6460c960276b402237371c12fc6dec), [`1b1504c9b`](https://github.com/graphcommerce-org/graphcommerce/commit/1b1504c9b0e51f2787bce91e1ff1940f540411d6), [`8a34f8081`](https://github.com/graphcommerce-org/graphcommerce/commit/8a34f808186274a6fe1d4f309472f1a9c6d00efd)]:
10
+ - @graphcommerce/next-ui@4.28.1
11
+ - @graphcommerce/graphql@3.5.0
12
+
13
+ ## 1.5.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [#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.
18
+
19
+ - Updated dependencies [[`1f2e14ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/1f2e14ba8b674b87257a123e8cb215157890eb22)]:
20
+ - @graphcommerce/react-hook-form@3.3.5
21
+
3
22
  ## 1.5.2
4
23
 
5
24
  ### Patch Changes
@@ -7,7 +7,8 @@ type ComposedSubmitButtonProps = ComposedSubmitRenderComponentProps &
7
7
 
8
8
  /** Makes a ComposedSubmitRenderComponent rendered as a LinkOrButton */
9
9
  export const ComposedSubmitButton = forwardRef<HTMLButtonElement, ComposedSubmitButtonProps>(
10
- ({ buttonState, submit, error, children, ...otherProps }, ref) => {
10
+ (props, ref) => {
11
+ const { buttonState, submit, error, children, onClick, ...otherProps } = props
11
12
  const loading =
12
13
  buttonState.isSubmitting || (buttonState.isSubmitSuccessful && !error) ? true : undefined
13
14
 
@@ -20,7 +21,10 @@ export const ComposedSubmitButton = forwardRef<HTMLButtonElement, ComposedSubmit
20
21
  type='submit'
21
22
  {...otherProps}
22
23
  loading={loading}
23
- onClick={submit}
24
+ onClick={(e) => {
25
+ onClick?.(e)
26
+ return submit()
27
+ }}
24
28
  >
25
29
  {children}
26
30
  </Button>
@@ -0,0 +1,85 @@
1
+ import { Controller, ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
2
+ import { MenuItem, TextField, TextFieldProps } from '@mui/material'
3
+
4
+ export type SelectElementProps<T extends FieldValues> = Omit<
5
+ TextFieldProps,
6
+ 'name' | 'type' | 'onChange' | 'defaultValue'
7
+ > & {
8
+ validation?: ControllerProps['rules']
9
+ options?: { id: string | number; label: string | number }[] | any[]
10
+ valueKey?: string
11
+ labelKey?: string
12
+ type?: 'string' | 'number'
13
+ objectOnChange?: boolean
14
+ onChange?: (value: any) => void
15
+ } & Pick<ControllerProps<T>, 'control' | 'defaultValue' | 'name'>
16
+
17
+ export function SelectElement<TFieldValues extends FieldValues>({
18
+ name,
19
+ required,
20
+ valueKey = 'id',
21
+ labelKey = 'label',
22
+ options = [],
23
+ type,
24
+ objectOnChange,
25
+ validation = {},
26
+ control,
27
+ defaultValue,
28
+ ...rest
29
+ }: SelectElementProps<TFieldValues>): JSX.Element {
30
+ const isNativeSelect = !!rest.SelectProps?.native
31
+ const ChildComponent = isNativeSelect ? 'option' : MenuItem
32
+
33
+ if (required && !validation.required) {
34
+ validation.required = 'This field is required'
35
+ }
36
+
37
+ return (
38
+ <Controller
39
+ name={name}
40
+ rules={validation}
41
+ control={control}
42
+ defaultValue={defaultValue}
43
+ render={({ field: { onBlur, onChange, value }, fieldState: { invalid, error } }) => {
44
+ // handle shrink on number input fields
45
+ if (type === 'number' && typeof value !== 'undefined') {
46
+ rest.InputLabelProps = rest.InputLabelProps || {}
47
+ rest.InputLabelProps.shrink = true
48
+ }
49
+
50
+ return (
51
+ <TextField
52
+ {...rest}
53
+ name={name}
54
+ value={value ?? ''}
55
+ onBlur={onBlur}
56
+ onChange={(event) => {
57
+ let item: number | string = event.target.value
58
+ if (type === 'number') {
59
+ item = Number(item)
60
+ }
61
+ onChange(item)
62
+ if (typeof rest.onChange === 'function') {
63
+ if (objectOnChange) {
64
+ item = options.find((i) => i[valueKey] === item)
65
+ }
66
+ rest.onChange(item)
67
+ }
68
+ }}
69
+ select
70
+ required={required}
71
+ error={invalid}
72
+ helperText={error ? error.message : rest.helperText}
73
+ >
74
+ {isNativeSelect && <option />}
75
+ {options.map((item: any) => (
76
+ <ChildComponent key={item[valueKey]} value={item[valueKey]}>
77
+ {item[labelKey]}
78
+ </ChildComponent>
79
+ ))}
80
+ </TextField>
81
+ )
82
+ }}
83
+ />
84
+ )
85
+ }
@@ -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'
@@ -2,7 +2,7 @@ import { QueryResult } from '@graphcommerce/graphql'
2
2
  import React, { startTransition, useEffect, useState } from 'react'
3
3
 
4
4
  export type WaitForQueriesProps = {
5
- waitFor: QueryResult<any, any> | QueryResult<any, any>[] | undefined
5
+ waitFor: QueryResult<any, any> | boolean | (QueryResult<any, any> | boolean)[] | undefined
6
6
  children: React.ReactNode
7
7
  fallback?: React.ReactNode
8
8
  }
@@ -17,9 +17,10 @@ export const WaitForQueries = (props: WaitForQueriesProps) => {
17
17
  useEffect(() => startTransition(() => setMounted(true)), [])
18
18
 
19
19
  // We are done when all queries either have data or an error.
20
- const isDone = (Array.isArray(waitFor) ? waitFor : [waitFor]).every(
21
- (res) => (typeof res === 'undefined' || res.data || res.error || !res.loading) && mounted,
22
- )
20
+ const isDone = (Array.isArray(waitFor) ? waitFor : [waitFor]).every((res) => {
21
+ if (typeof res === 'boolean') return res && mounted
22
+ return (typeof res === 'undefined' || res.data || res.error || !res.loading) && mounted
23
+ })
23
24
 
24
25
  return <>{isDone && mounted ? children : fallback}</>
25
26
  }
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.2",
5
+ "version": "1.5.4",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,9 +12,9 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@graphcommerce/graphql": "3.4.8",
16
- "@graphcommerce/next-ui": "4.28.0",
17
- "@graphcommerce/react-hook-form": "3.3.4",
15
+ "@graphcommerce/graphql": "3.5.0",
16
+ "@graphcommerce/next-ui": "4.28.1",
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"