@graphcommerce/ecommerce-ui 8.1.0-canary.9 → 9.0.0-canary.101

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,219 @@
1
1
  # @graphcommerce/ecommerce-ui
2
2
 
3
+ ## 9.0.0-canary.101
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2380](https://github.com/graphcommerce-org/graphcommerce/pull/2380) [`c17e5f1`](https://github.com/graphcommerce-org/graphcommerce/commit/c17e5f1cf9fb291b9bbf1fca0620c2721dceb331) - Solve issue: Warning: Cannot update a component (`FormAutoSubmitBase`) while rendering a different component (`ActionCardListForm`). ([@paales](https://github.com/paales))
8
+
9
+ ## 9.0.0-canary.100
10
+
11
+ ## 9.0.0-canary.99
12
+
13
+ ## 9.0.0-canary.98
14
+
15
+ ## 9.0.0-canary.97
16
+
17
+ ## 9.0.0-canary.96
18
+
19
+ ## 9.0.0-canary.95
20
+
21
+ ## 9.0.0-canary.94
22
+
23
+ ## 9.0.0-canary.93
24
+
25
+ ## 9.0.0-canary.92
26
+
27
+ ## 9.0.0-canary.91
28
+
29
+ ## 9.0.0-canary.90
30
+
31
+ ### Patch Changes
32
+
33
+ - [#2397](https://github.com/graphcommerce-org/graphcommerce/pull/2397) [`d4d5a98`](https://github.com/graphcommerce-org/graphcommerce/commit/d4d5a983dea6d034dcbdeed9cf30fb33133dde39) - Add requireOptionSelection boolean to prevent users from deselecting configurable options ([@carlocarels90](https://github.com/carlocarels90))
34
+
35
+ ## 9.0.0-canary.89
36
+
37
+ ## 9.0.0-canary.88
38
+
39
+ ## 9.0.0-canary.87
40
+
41
+ ## 9.0.0-canary.86
42
+
43
+ ## 9.0.0-canary.85
44
+
45
+ ## 9.0.0-canary.84
46
+
47
+ ## 9.0.0-canary.83
48
+
49
+ ## 9.0.0-canary.82
50
+
51
+ ### Minor Changes
52
+
53
+ - [#2366](https://github.com/graphcommerce-org/graphcommerce/pull/2366) [`3612c99`](https://github.com/graphcommerce-org/graphcommerce/commit/3612c994b80bb3b1bc02de10668f69a332402dc4) - Add `permissions` config so the website or store can be configurated to run in different modes. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
54
+
55
+ ## 9.0.0-canary.81
56
+
57
+ ## 9.0.0-canary.80
58
+
59
+ ### Patch Changes
60
+
61
+ - [#2341](https://github.com/graphcommerce-org/graphcommerce/pull/2341) [`7085b4a`](https://github.com/graphcommerce-org/graphcommerce/commit/7085b4a86088328fe54dc4e82ccd296d6459cae7) - Updated all form FieldElements to also accept defaultValue, shouldUnregister and disabled. Moved AutoCompleteElement, CheckboxElement, MultiSelectElement, SliderElement, SwitchElement, ToggleButtonGroup to useController. Removed all parseError props ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
62
+
63
+ - [#2341](https://github.com/graphcommerce-org/graphcommerce/pull/2341) [`022cbd6`](https://github.com/graphcommerce-org/graphcommerce/commit/022cbd664ea4e8a82997c5edf4451b9182558429) - Moved ActionCardListForm to @graphcommerce/ecommerce-ui to resolve issue with circular dependencies. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
64
+
65
+ ## 9.0.0-canary.79
66
+
67
+ ## 9.0.0-canary.78
68
+
69
+ ## 9.0.0-canary.77
70
+
71
+ ## 9.0.0-canary.76
72
+
73
+ ## 9.0.0-canary.75
74
+
75
+ ## 9.0.0-canary.74
76
+
77
+ ### Patch Changes
78
+
79
+ - [#2349](https://github.com/graphcommerce-org/graphcommerce/pull/2349) [`7c8529e`](https://github.com/graphcommerce-org/graphcommerce/commit/7c8529ea54c0e91f6b0e72129611cd6bf4f85d87) - Fix NumberFieldElement when min = 0 ([@JoshuaS98](https://github.com/JoshuaS98))
80
+
81
+ ## 9.0.0-canary.73
82
+
83
+ ## 9.0.0-canary.72
84
+
85
+ ## 9.0.0-canary.71
86
+
87
+ ## 9.0.0-canary.70
88
+
89
+ ## 9.0.0-canary.69
90
+
91
+ ## 9.0.0-canary.68
92
+
93
+ ## 9.0.0-canary.67
94
+
95
+ ## 9.0.0-canary.66
96
+
97
+ ## 9.0.0-canary.65
98
+
99
+ ## 9.0.0-canary.64
100
+
101
+ ## 9.0.0-canary.63
102
+
103
+ ## 9.0.0-canary.62
104
+
105
+ ## 9.0.0-canary.61
106
+
107
+ ## 9.0.0-canary.60
108
+
109
+ ## 9.0.0-canary.59
110
+
111
+ ## 9.0.0-canary.58
112
+
113
+ ## 9.0.0-canary.57
114
+
115
+ ## 9.0.0-canary.56
116
+
117
+ ## 9.0.0-canary.55
118
+
119
+ ## 9.0.0-canary.54
120
+
121
+ ## 8.1.0-canary.53
122
+
123
+ ## 8.1.0-canary.52
124
+
125
+ ## 8.1.0-canary.51
126
+
127
+ ## 8.1.0-canary.50
128
+
129
+ ## 8.1.0-canary.49
130
+
131
+ ## 8.1.0-canary.48
132
+
133
+ ### Minor Changes
134
+
135
+ - [#2319](https://github.com/graphcommerce-org/graphcommerce/pull/2319) [`a3409e8`](https://github.com/graphcommerce-org/graphcommerce/commit/a3409e8a629ee95413da6547cbdcf48aa2502c23) - Created a new TelephoneElement component to make re-use easier ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
136
+
137
+ ## 8.1.0-canary.47
138
+
139
+ ## 8.1.0-canary.46
140
+
141
+ ## 8.1.0-canary.45
142
+
143
+ ## 8.1.0-canary.44
144
+
145
+ ## 8.1.0-canary.43
146
+
147
+ ## 8.1.0-canary.42
148
+
149
+ ## 8.1.0-canary.41
150
+
151
+ ## 8.1.0-canary.40
152
+
153
+ ## 8.1.0-canary.39
154
+
155
+ ## 8.1.0-canary.38
156
+
157
+ ## 8.1.0-canary.37
158
+
159
+ ## 8.1.0-canary.36
160
+
161
+ ## 8.1.0-canary.35
162
+
163
+ ### Patch Changes
164
+
165
+ - [#2301](https://github.com/graphcommerce-org/graphcommerce/pull/2301) [`13d0649`](https://github.com/graphcommerce-org/graphcommerce/commit/13d06498d121f93b52c25930e50aa3b0bd12a818) - Created a new EmailElement component to make re-use easier ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
166
+
167
+ ## 8.1.0-canary.34
168
+
169
+ ## 8.1.0-canary.33
170
+
171
+ ## 8.1.0-canary.32
172
+
173
+ ## 8.1.0-canary.31
174
+
175
+ ## 8.1.0-canary.30
176
+
177
+ ## 8.1.0-canary.29
178
+
179
+ ## 8.1.0-canary.28
180
+
181
+ ## 8.1.0-canary.27
182
+
183
+ ## 8.1.0-canary.26
184
+
185
+ ## 8.1.0-canary.25
186
+
187
+ ## 8.1.0-canary.24
188
+
189
+ ## 8.1.0-canary.23
190
+
191
+ ## 8.1.0-canary.22
192
+
193
+ ## 8.1.0-canary.21
194
+
195
+ ## 8.1.0-canary.20
196
+
197
+ ## 8.1.0-canary.19
198
+
199
+ ## 8.1.0-canary.18
200
+
201
+ ## 8.1.0-canary.17
202
+
203
+ ## 8.1.0-canary.16
204
+
205
+ ## 8.1.0-canary.15
206
+
207
+ ## 8.1.0-canary.14
208
+
209
+ ## 8.1.0-canary.13
210
+
211
+ ## 8.1.0-canary.12
212
+
213
+ ## 8.1.0-canary.11
214
+
215
+ ## 8.1.0-canary.10
216
+
3
217
  ## 8.1.0-canary.9
4
218
 
5
219
  ## 8.1.0-canary.8
@@ -18,15 +232,11 @@
18
232
 
19
233
  ### Patch Changes
20
234
 
21
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`0767bc4`](https://github.com/graphcommerce-org/graphcommerce/commit/0767bc40f7b596209f24ca4e745ff0441f3275c9) - Upgrade input components to no longer use muiRegister, which improves INP scores
22
- ([@FrankHarland](https://github.com/FrankHarland))
235
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`0767bc4`](https://github.com/graphcommerce-org/graphcommerce/commit/0767bc40f7b596209f24ca4e745ff0441f3275c9) - Upgrade input components to no longer use muiRegister, which improves INP scores ([@FrankHarland](https://github.com/FrankHarland))
23
236
 
24
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Make sure the TextFieldElement doesn’t give a uncontrolled to controlled warning.
25
- Convert SelectElement to useController instead of a separate Controller component.
26
- Make sure the original endAdornment is always shown only until the value is valid ([@FrankHarland](https://github.com/FrankHarland))
237
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Make sure the TextFieldElement doesn’t give a uncontrolled to controlled warning. Convert SelectElement to useController instead of a separate Controller component. Make sure the original endAdornment is always shown only until the value is valid ([@FrankHarland](https://github.com/FrankHarland))
27
238
 
28
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`d4e693d`](https://github.com/graphcommerce-org/graphcommerce/commit/d4e693d553198c9a1ef398d000ca23d209e6c2ba) - The `<WaitForQueries/>` component now uses the useIsSSR hook which prevents loading spinners when navigating on the client, which make all account/cart/checkout pages faster.
29
- ([@FrankHarland](https://github.com/FrankHarland))
239
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`d4e693d`](https://github.com/graphcommerce-org/graphcommerce/commit/d4e693d553198c9a1ef398d000ca23d209e6c2ba) - The `<WaitForQueries/>` component now uses the useIsSSR hook which prevents loading spinners when navigating on the client, which make all account/cart/checkout pages faster. ([@FrankHarland](https://github.com/FrankHarland))
30
240
 
31
241
  ## 8.0.6-canary.1
32
242
 
@@ -66,14 +276,11 @@
66
276
 
67
277
  ### Patch Changes
68
278
 
69
- - [#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
70
- ([@paales](https://github.com/paales))
279
+ - [#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 ([@paales](https://github.com/paales))
71
280
 
72
- - [#2203](https://github.com/graphcommerce-org/graphcommerce/pull/2203) [`7ef7dc7`](https://github.com/graphcommerce-org/graphcommerce/commit/7ef7dc7631f61a2feba67a531a210df9c22fed4b) - CheckboxElement, MultiSelectElement, NumberFieldElement, SelectElement, SliderElement and TextFieldElement have their inputRef passed, allowing focus to be set by the form.
73
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
281
+ - [#2203](https://github.com/graphcommerce-org/graphcommerce/pull/2203) [`7ef7dc7`](https://github.com/graphcommerce-org/graphcommerce/commit/7ef7dc7631f61a2feba67a531a210df9c22fed4b) - CheckboxElement, MultiSelectElement, NumberFieldElement, SelectElement, SliderElement and TextFieldElement have their inputRef passed, allowing focus to be set by the form. ([@Jessevdpoel](https://github.com/Jessevdpoel))
74
282
 
75
- - [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`eb14696`](https://github.com/graphcommerce-org/graphcommerce/commit/eb14696fc65e084a06790c88a8218fb3003f7c2c) - `<WaitForQueries/>` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart
76
- ([@paales](https://github.com/paales))
283
+ - [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`eb14696`](https://github.com/graphcommerce-org/graphcommerce/commit/eb14696fc65e084a06790c88a8218fb3003f7c2c) - `<WaitForQueries/>` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart ([@paales](https://github.com/paales))
77
284
 
78
285
  ## 8.0.3-canary.6
79
286
 
@@ -81,15 +288,13 @@
81
288
 
82
289
  ### Patch Changes
83
290
 
84
- - [#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
85
- ([@paales](https://github.com/paales))
291
+ - [#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 ([@paales](https://github.com/paales))
86
292
 
87
293
  ## 8.0.3-canary.4
88
294
 
89
295
  ### Patch Changes
90
296
 
91
- - [#2203](https://github.com/graphcommerce-org/graphcommerce/pull/2203) [`7ef7dc7`](https://github.com/graphcommerce-org/graphcommerce/commit/7ef7dc7631f61a2feba67a531a210df9c22fed4b) - CheckboxElement, MultiSelectElement, NumberFieldElement, SelectElement, SliderElement and TextFieldElement have their inputRef passed, allowing focus to be set by the form.
92
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
297
+ - [#2203](https://github.com/graphcommerce-org/graphcommerce/pull/2203) [`7ef7dc7`](https://github.com/graphcommerce-org/graphcommerce/commit/7ef7dc7631f61a2feba67a531a210df9c22fed4b) - CheckboxElement, MultiSelectElement, NumberFieldElement, SelectElement, SliderElement and TextFieldElement have their inputRef passed, allowing focus to be set by the form. ([@Jessevdpoel](https://github.com/Jessevdpoel))
93
298
 
94
299
  ## 8.0.3-canary.3
95
300
 
@@ -97,8 +302,7 @@
97
302
 
98
303
  ### Patch Changes
99
304
 
100
- - [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`eb14696`](https://github.com/graphcommerce-org/graphcommerce/commit/eb14696fc65e084a06790c88a8218fb3003f7c2c) - `<WaitForQueries/>` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart
101
- ([@paales](https://github.com/paales))
305
+ - [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`eb14696`](https://github.com/graphcommerce-org/graphcommerce/commit/eb14696fc65e084a06790c88a8218fb3003f7c2c) - `<WaitForQueries/>` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart ([@paales](https://github.com/paales))
102
306
 
103
307
  ## 8.0.3-canary.1
104
308
 
@@ -130,19 +334,15 @@
130
334
 
131
335
  ### Minor Changes
132
336
 
133
- - [#2111](https://github.com/graphcommerce-org/graphcommerce/pull/2111) [`35f3d3e`](https://github.com/graphcommerce-org/graphcommerce/commit/35f3d3eaf46f4b782bb1149e0efb0ec3819442d6) - Only show network errors in development mode.
134
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
337
+ - [#2111](https://github.com/graphcommerce-org/graphcommerce/pull/2111) [`35f3d3e`](https://github.com/graphcommerce-org/graphcommerce/commit/35f3d3eaf46f4b782bb1149e0efb0ec3819442d6) - Only show network errors in development mode. ([@Jessevdpoel](https://github.com/Jessevdpoel))
135
338
 
136
- - [#2048](https://github.com/graphcommerce-org/graphcommerce/pull/2048) [`13e23e4`](https://github.com/graphcommerce-org/graphcommerce/commit/13e23e4265bac70fb4d0830e4661019e71ce299f) - Wishlist will now support configurable products and uses the `<ActionCardLayout/>`
137
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
339
+ - [#2048](https://github.com/graphcommerce-org/graphcommerce/pull/2048) [`13e23e4`](https://github.com/graphcommerce-org/graphcommerce/commit/13e23e4265bac70fb4d0830e4661019e71ce299f) - Wishlist will now support configurable products and uses the `<ActionCardLayout/>` ([@Jessevdpoel](https://github.com/Jessevdpoel))
138
340
 
139
- - [#2018](https://github.com/graphcommerce-org/graphcommerce/pull/2018) [`750aa6a`](https://github.com/graphcommerce-org/graphcommerce/commit/750aa6a72710869d54244467253212e551d335e0) - Changed the layout of the succes page. We are using ActionCards right now to match the design of the cart.
140
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
341
+ - [#2018](https://github.com/graphcommerce-org/graphcommerce/pull/2018) [`750aa6a`](https://github.com/graphcommerce-org/graphcommerce/commit/750aa6a72710869d54244467253212e551d335e0) - Changed the layout of the succes page. We are using ActionCards right now to match the design of the cart. ([@Jessevdpoel](https://github.com/Jessevdpoel))
141
342
 
142
343
  ### Patch Changes
143
344
 
144
- - [`e33660f`](https://github.com/graphcommerce-org/graphcommerce/commit/e33660f172466dcfa0ab7262cee612d9a3e47776) - Accessibility improvements for the frontend: Added skip content link. Removed empty buttons from tab flow. Gave focus to elements (such as the menu) that appear when after clicking a button. Improved aria labels where needed
145
- ([@FrankHarland](https://github.com/FrankHarland))
345
+ - [`e33660f`](https://github.com/graphcommerce-org/graphcommerce/commit/e33660f172466dcfa0ab7262cee612d9a3e47776) - Accessibility improvements for the frontend: Added skip content link. Removed empty buttons from tab flow. Gave focus to elements (such as the menu) that appear when after clicking a button. Improved aria labels where needed ([@FrankHarland](https://github.com/FrankHarland))
146
346
 
147
347
  ## 8.0.0-canary.100
148
348
 
@@ -194,8 +394,7 @@
194
394
 
195
395
  ### Patch Changes
196
396
 
197
- - [`e33660f`](https://github.com/graphcommerce-org/graphcommerce/commit/e33660f172466dcfa0ab7262cee612d9a3e47776) - a11y improvements (see https://github.com/graphcommerce-org/graphcommerce/issues/1995 for more info)
198
- ([@FrankHarland](https://github.com/FrankHarland))
397
+ - [`e33660f`](https://github.com/graphcommerce-org/graphcommerce/commit/e33660f172466dcfa0ab7262cee612d9a3e47776) - a11y improvements (see https://github.com/graphcommerce-org/graphcommerce/issues/1995 for more info) ([@FrankHarland](https://github.com/FrankHarland))
199
398
 
200
399
  ## 8.0.0-canary.76
201
400
 
@@ -1287,31 +1486,31 @@
1287
1486
  All occurences of `<Trans>` and `t` need to be replaced:
1288
1487
 
1289
1488
  ```tsx
1290
- import { Trans, t } from "@lingui/macro";
1489
+ import { Trans, t } from '@lingui/macro'
1291
1490
 
1292
1491
  function MyComponent() {
1293
- const foo = "bar";
1492
+ const foo = 'bar'
1294
1493
  return (
1295
1494
  <div aria-label={t`Account ${foo}`}>
1296
1495
  <Trans>My Translation {foo}</Trans>
1297
1496
  </div>
1298
- );
1497
+ )
1299
1498
  }
1300
1499
  ```
1301
1500
 
1302
1501
  Needs to be replaced with:
1303
1502
 
1304
1503
  ```tsx
1305
- import { Trans } from "@lingui/react";
1306
- import { i18n } from "@lingui/core";
1504
+ import { Trans } from '@lingui/react'
1505
+ import { i18n } from '@lingui/core'
1307
1506
 
1308
1507
  function MyComponent() {
1309
- const foo = "bar";
1508
+ const foo = 'bar'
1310
1509
  return (
1311
1510
  <div aria-label={i18n._(/* i18n */ `Account {foo}`, { foo })}>
1312
- <Trans key="My Translation {foo}" values={{ foo }}></Trans>
1511
+ <Trans key='My Translation {foo}' values={{ foo }}></Trans>
1313
1512
  </div>
1314
- );
1513
+ )
1315
1514
  }
1316
1515
  ```
1317
1516
 
@@ -0,0 +1,29 @@
1
+ enum WebsitePermissions {
2
+ ENABLED
3
+ # CUSTOMER_ONLY will be implemented later
4
+ # DISABLED will be implemented later
5
+ }
6
+
7
+ """
8
+ Permissions input
9
+ """
10
+ input GraphCommercePermissions {
11
+ """
12
+ Allows the option to require login or completely disable the site.
13
+ """
14
+ website: WebsitePermissions
15
+ }
16
+
17
+ extend input GraphCommerceConfig {
18
+ """
19
+ Allows the option to require login or completely disable certain sections of the site, can be overriden per storeview with the storefrontConfig
20
+ """
21
+ permissions: GraphCommercePermissions
22
+ }
23
+
24
+ extend input GraphCommerceStorefrontConfig {
25
+ """
26
+ Allows the option to require login or completely disable certain sections of the site on a per store basis
27
+ """
28
+ permissions: GraphCommercePermissions
29
+ }
@@ -0,0 +1,96 @@
1
+ import { ActionCardList, ActionCardListProps, ActionCardProps } from '@graphcommerce/next-ui'
2
+ import { ControllerProps, FieldValues, useController } from '@graphcommerce/react-hook-form'
3
+ import React, { MouseEventHandler, useCallback } from 'react'
4
+
5
+ export type ActionCardItemBase = Pick<ActionCardProps, 'value'>
6
+
7
+ export type ActionCardRequireOptionSelection = { requireOptionSelection?: boolean }
8
+
9
+ export type ActionCardItemRenderProps<T> = ActionCardProps & {
10
+ onReset: MouseEventHandler<HTMLElement>
11
+ } & T
12
+
13
+ export type ActionCardListFormProps<A, F extends FieldValues = FieldValues> = Omit<
14
+ ActionCardListProps,
15
+ 'value' | 'error' | 'onChange' | 'children'
16
+ > &
17
+ Omit<ControllerProps<F>, 'render'> & {
18
+ items: A[]
19
+ render: React.FC<ActionCardItemRenderProps<A>>
20
+ } & ActionCardRequireOptionSelection
21
+
22
+ export function ActionCardListForm<
23
+ T extends ActionCardItemBase,
24
+ F extends FieldValues = FieldValues,
25
+ >(props: ActionCardListFormProps<T, F>) {
26
+ const {
27
+ required,
28
+ rules,
29
+ items,
30
+ render,
31
+ control,
32
+ name,
33
+ errorMessage,
34
+ defaultValue,
35
+ multiple,
36
+ disabled,
37
+ shouldUnregister,
38
+ requireOptionSelection,
39
+ ...other
40
+ } = props
41
+ const RenderItem = render as React.FC<ActionCardItemRenderProps<ActionCardItemBase>>
42
+
43
+ const onSelect = useCallback(
44
+ (itemValue: unknown, selectValues: unknown) =>
45
+ multiple
46
+ ? Array.isArray(selectValues) &&
47
+ selectValues.some((selectValue) => selectValue === itemValue)
48
+ : selectValues === itemValue,
49
+ [multiple],
50
+ )
51
+
52
+ const {
53
+ field: { onChange, value, ref },
54
+ fieldState,
55
+ formState,
56
+ } = useController({
57
+ ...props,
58
+ control,
59
+ name,
60
+ defaultValue,
61
+ rules: { required, ...rules },
62
+ disabled,
63
+ shouldUnregister,
64
+ })
65
+
66
+ const handleReset = useCallback(
67
+ (e: React.MouseEvent<HTMLElement>) => {
68
+ e.preventDefault()
69
+ if (!requireOptionSelection) onChange(null)
70
+ },
71
+ [onChange, requireOptionSelection],
72
+ )
73
+
74
+ return (
75
+ <ActionCardList
76
+ {...other}
77
+ multiple={multiple}
78
+ required={required}
79
+ value={value}
80
+ ref={ref}
81
+ onChange={(_, incoming) => onChange(incoming)}
82
+ error={formState.isSubmitted && !!fieldState.error}
83
+ errorMessage={fieldState.error?.message}
84
+ >
85
+ {items.map((item) => (
86
+ <RenderItem
87
+ {...item}
88
+ key={`${item.value}`}
89
+ value={item.value}
90
+ selected={onSelect(item.value, value)}
91
+ onReset={handleReset}
92
+ />
93
+ ))}
94
+ </ActionCardList>
95
+ )
96
+ }