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

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.117
4
+
3
5
  ## 9.0.0-canary.116
4
6
 
5
7
  ## 9.0.0-canary.115
@@ -0,0 +1,54 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import { FieldValues, UseControllerProps, useController } from '@graphcommerce/react-hook-form'
3
+ import { i18n } from '@lingui/core'
4
+ import { InputBase, InputBaseProps } from '@mui/material'
5
+ import React from 'react'
6
+
7
+ export type InputBaseElementProps<T extends FieldValues = FieldValues> = Omit<
8
+ InputBaseProps,
9
+ 'name' | 'defaultValue'
10
+ > & {
11
+ showValid?: boolean
12
+ } & UseControllerProps<T>
13
+
14
+ type InputBaseElementComponent = <TFieldValues extends FieldValues>(
15
+ props: InputBaseElementProps<TFieldValues> & { ref?: React.Ref<HTMLInputElement> },
16
+ ) => JSX.Element
17
+
18
+ export const InputBaseElement = React.forwardRef<
19
+ HTMLInputElement,
20
+ InputBaseElementProps<FieldValues>
21
+ >((props: InputBaseElementProps<FieldValues>, ref: React.Ref<HTMLInputElement>): JSX.Element => {
22
+ const {
23
+ type,
24
+ required,
25
+ name,
26
+ control,
27
+ defaultValue,
28
+ rules = {},
29
+ shouldUnregister,
30
+ showValid,
31
+ disabled,
32
+ ...rest
33
+ } = props
34
+
35
+ if (required && !rules?.required) {
36
+ rules.required = i18n._(/* i18n */ 'This field is required')
37
+ }
38
+
39
+ const {
40
+ field,
41
+ fieldState: { error },
42
+ } = useController({ name, control, rules, defaultValue, shouldUnregister, disabled })
43
+
44
+ return (
45
+ <InputBase
46
+ {...rest}
47
+ {...field}
48
+ ref={ref}
49
+ required={required}
50
+ type={type}
51
+ error={Boolean(error) || rest.error}
52
+ />
53
+ )
54
+ }) as InputBaseElementComponent
@@ -13,3 +13,4 @@ export * from './SwitchElement'
13
13
  export * from './TelephoneElement'
14
14
  export * from './TextFieldElement'
15
15
  export * from './ToggleButtonGroup'
16
+ export * from './InputBaseElement'
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.116",
5
+ "version": "9.0.0-canary.117",
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.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",
15
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.117",
16
+ "@graphcommerce/graphql": "^9.0.0-canary.117",
17
+ "@graphcommerce/next-ui": "^9.0.0-canary.117",
18
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.117",
19
+ "@graphcommerce/react-hook-form": "^9.0.0-canary.117",
20
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.117",
21
21
  "@lingui/core": "^4.2.1",
22
22
  "@lingui/macro": "^4.2.1",
23
23
  "@lingui/react": "^4.2.1",