@graphcommerce/ecommerce-ui 9.1.0-canary.18 → 9.1.0-canary.20

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,13 @@
1
1
  # @graphcommerce/ecommerce-ui
2
2
 
3
+ ## 9.1.0-canary.20
4
+
5
+ ## 9.1.0-canary.19
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`7c7d6e4`](https://github.com/graphcommerce-org/graphcommerce/commit/7c7d6e4976d263f4139ce1de2caf47e7f49a2bf8) - Solve issue where an individual item in the ActionCardListForm couldn't be disabed. Resulting in configurable options on the product page to be selectable while they shouldn't be. ([@paales](https://github.com/paales))
10
+
3
11
  ## 9.1.0-canary.18
4
12
 
5
13
  ## 9.1.0-canary.17
@@ -93,7 +93,7 @@ export function ActionCardListForm<
93
93
  value={item.value}
94
94
  selected={onSelect(item.value, value)}
95
95
  onReset={handleReset}
96
- disabled={disabled}
96
+ disabled={disabled || (item as { disabled?: boolean }).disabled}
97
97
  />
98
98
  ))}
99
99
  </ActionCardList>
@@ -8,15 +8,43 @@ import { TextField, useForkRef } from '@mui/material'
8
8
  import React, { useState } from 'react'
9
9
  import type { BaseControllerProps, FieldElementProps } from './types'
10
10
 
11
- type ShowValidProps = { showValid?: boolean }
11
+ type InternalProps = {
12
+ showValid?: boolean
13
+ /** Cast all values as a string instead of a string/number/date depending on the input type. */
14
+ asString?: boolean
15
+ }
12
16
 
13
17
  export type TextFieldElementProps<TFieldValues extends FieldValues = FieldValues> =
14
- FieldElementProps<TFieldValues, TextFieldProps> & ShowValidProps
18
+ FieldElementProps<TFieldValues, TextFieldProps> & InternalProps
15
19
 
16
20
  type TextFieldElementComponent = <TFieldValues extends FieldValues>(
17
21
  props: TextFieldElementProps<TFieldValues>,
18
22
  ) => React.ReactNode
19
23
 
24
+ function toValue(incomingValue: unknown, type: React.HTMLInputTypeAttribute) {
25
+ try {
26
+ let value = incomingValue
27
+ if (!value) return value
28
+
29
+ if (typeof value === 'number') return value.toString()
30
+
31
+ if (type === 'time' || type === 'datetime-local' || type === 'date') {
32
+ if (typeof value === 'string') value = new Date(value)
33
+ if (!(value instanceof Date)) return value
34
+
35
+ const [datePart, timePart] = value.toISOString().replace('Z', '').split('T')
36
+
37
+ if (type === 'time') return timePart
38
+ if (type === 'date') return datePart
39
+ if (type === 'datetime-local') return value.toISOString().replace('Z', '')
40
+ }
41
+ return value
42
+ } catch (e) {
43
+ console.error(e, incomingValue, type)
44
+ return incomingValue
45
+ }
46
+ }
47
+
20
48
  /** @public */
21
49
  function TextFieldElementBase(props: TextFieldElementProps): JSX.Element {
22
50
  const {
@@ -26,11 +54,12 @@ function TextFieldElementBase(props: TextFieldElementProps): JSX.Element {
26
54
  rules = {},
27
55
  shouldUnregister,
28
56
  disabled: disabledField,
29
- type,
57
+ type = 'text',
30
58
  required,
31
59
  showValid,
60
+ asString = false,
32
61
  ...rest
33
- } = props as TextFieldProps & ShowValidProps & BaseControllerProps
62
+ } = props as TextFieldProps & InternalProps & BaseControllerProps
34
63
 
35
64
  if (required && !rules.required) {
36
65
  rules.required = i18n._(/* i18n */ 'This field is required')
@@ -73,10 +102,26 @@ function TextFieldElementBase(props: TextFieldElementProps): JSX.Element {
73
102
  onBlur={onBlur}
74
103
  name={name}
75
104
  disabled={disabled}
76
- value={value}
105
+ value={toValue(value, type)}
77
106
  inputProps={{ ...rest.inputProps, onAnimationStart }}
78
107
  onChange={(ev) => {
79
- onChange(type === 'number' && ev.target.value ? Number(ev.target.value) : ev.target.value)
108
+ let changeValue: string | number | Date = ev.target.value
109
+
110
+ if (ev.target instanceof HTMLInputElement) {
111
+ if (type === 'number' || typeof changeValue === 'number') {
112
+ changeValue = ev.target.valueAsNumber
113
+ } else if (type === 'datetime-local') {
114
+ changeValue = new Date(`${changeValue.replace('T', ' ')}.000Z`)
115
+ } else if (type === 'date') {
116
+ changeValue = ev.target.valueAsDate ?? ''
117
+ } else if (type === 'time') {
118
+ changeValue = new Date(`01-01-1970 ${changeValue}.000Z`)
119
+ }
120
+ }
121
+
122
+ if (asString) changeValue = changeValue.toString()
123
+
124
+ onChange(changeValue)
80
125
  rest.onChange?.(ev)
81
126
  }}
82
127
  inputRef={useForkRef(ref, rest.inputRef)}
@@ -88,7 +133,7 @@ function TextFieldElementBase(props: TextFieldElementProps): JSX.Element {
88
133
  InputProps={{
89
134
  ...rest.InputProps,
90
135
  endAdornment:
91
- showValid && value && !error ? (
136
+ showValid && Boolean(value) && !error ? (
92
137
  <InputCheckmark show={!error} />
93
138
  ) : (
94
139
  rest.InputProps?.endAdornment
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.1.0-canary.18",
5
+ "version": "9.1.0-canary.20",
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.1.0-canary.18",
16
- "@graphcommerce/graphql": "^9.1.0-canary.18",
17
- "@graphcommerce/next-ui": "^9.1.0-canary.18",
18
- "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.18",
19
- "@graphcommerce/react-hook-form": "^9.1.0-canary.18",
20
- "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.18",
15
+ "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.20",
16
+ "@graphcommerce/graphql": "^9.1.0-canary.20",
17
+ "@graphcommerce/next-ui": "^9.1.0-canary.20",
18
+ "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.20",
19
+ "@graphcommerce/react-hook-form": "^9.1.0-canary.20",
20
+ "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.20",
21
21
  "@lingui/core": "^4.2.1",
22
22
  "@lingui/macro": "^4.2.1",
23
23
  "@lingui/react": "^4.2.1",