@finsweet/webflow-apps-utils 1.0.28 → 1.0.29

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.
@@ -11,6 +11,7 @@ export * from './input';
11
11
  export * from './layout';
12
12
  export * from './modal';
13
13
  export * from './notification';
14
+ export * from './regions';
14
15
  export * from './section';
15
16
  export * from './select';
16
17
  export * from './shared';
@@ -11,6 +11,7 @@ export * from './input';
11
11
  export * from './layout';
12
12
  export * from './modal';
13
13
  export * from './notification';
14
+ export * from './regions';
14
15
  export * from './section';
15
16
  export * from './select';
16
17
  export * from './shared';
@@ -0,0 +1,383 @@
1
+ <script module lang="ts">
2
+ import { defineMeta } from '@storybook/addon-svelte-csf';
3
+ import { fn } from 'storybook/test';
4
+
5
+ import RegionSelector from './RegionSelector.svelte';
6
+ import type { RegionGroup, UsedRegions } from './types.js';
7
+
8
+ // Dummy data that mimics real region structure
9
+ const dummyRegionGroups: RegionGroup[] = [
10
+ {
11
+ key: 'global',
12
+ name: 'Global',
13
+ regions: [
14
+ {
15
+ code: 'Global',
16
+ name: 'Global'
17
+ }
18
+ ],
19
+ total: 1
20
+ },
21
+ {
22
+ key: 'europe',
23
+ name: 'European Union',
24
+ regions: [
25
+ {
26
+ code: 'EU',
27
+ name: 'European Union'
28
+ }
29
+ ],
30
+ total: 1
31
+ },
32
+ {
33
+ key: 'us',
34
+ name: 'United States',
35
+ regions: [
36
+ { code: 'US-AL', name: 'Alabama' },
37
+ { code: 'US-AK', name: 'Alaska' },
38
+ { code: 'US-AZ', name: 'Arizona' },
39
+ { code: 'US-CA', name: 'California' },
40
+ { code: 'US-CO', name: 'Colorado' },
41
+ { code: 'US-CT', name: 'Connecticut' },
42
+ { code: 'US-DE', name: 'Delaware' },
43
+ { code: 'US-FL', name: 'Florida' },
44
+ { code: 'US-GA', name: 'Georgia' },
45
+ { code: 'US-HI', name: 'Hawaii' }
46
+ ],
47
+ total: 10
48
+ },
49
+ {
50
+ key: 'countries',
51
+ name: 'Countries',
52
+ regions: [
53
+ { code: 'CA', name: 'Canada' },
54
+ { code: 'MX', name: 'Mexico' },
55
+ { code: 'BR', name: 'Brazil' },
56
+ { code: 'AR', name: 'Argentina' },
57
+ { code: 'GB', name: 'United Kingdom' },
58
+ { code: 'FR', name: 'France' },
59
+ { code: 'DE', name: 'Germany' },
60
+ { code: 'IT', name: 'Italy' },
61
+ { code: 'ES', name: 'Spain' },
62
+ { code: 'JP', name: 'Japan' },
63
+ { code: 'CN', name: 'China' },
64
+ { code: 'IN', name: 'India' },
65
+ { code: 'AU', name: 'Australia' },
66
+ { code: 'NZ', name: 'New Zealand' }
67
+ ],
68
+ total: 14
69
+ }
70
+ ];
71
+
72
+ const emptyUsedRegions: UsedRegions = {
73
+ regions: new Set(),
74
+ isGlobalUsed: false,
75
+ isEUGroupUsed: false,
76
+ byInstance: new Map()
77
+ };
78
+
79
+ const someUsedRegions: UsedRegions = {
80
+ regions: new Set(['US-CA', 'US-CO', 'CA', 'GB']),
81
+ isGlobalUsed: false,
82
+ isEUGroupUsed: false,
83
+ byInstance: new Map()
84
+ };
85
+
86
+ const globalUsedRegions: UsedRegions = {
87
+ regions: new Set(['Global']),
88
+ isGlobalUsed: true,
89
+ isEUGroupUsed: false,
90
+ byInstance: new Map()
91
+ };
92
+
93
+ const { Story } = defineMeta({
94
+ title: 'UI/RegionSelector',
95
+ component: RegionSelector,
96
+ tags: ['autodocs'],
97
+ argTypes: {
98
+ regionGroups: {
99
+ control: 'object',
100
+ description: 'Array of region groups containing regions'
101
+ },
102
+ selectedRegions: {
103
+ control: 'object',
104
+ description: 'Array of selected region codes'
105
+ },
106
+ onRegionsChange: {
107
+ action: 'onRegionsChange',
108
+ description: 'Callback fired when region selection changes'
109
+ },
110
+ usedRegions: {
111
+ control: 'object',
112
+ description: 'Object containing regions that are already in use'
113
+ },
114
+ isLoading: {
115
+ control: 'boolean',
116
+ description: 'If true, shows loading state'
117
+ },
118
+ error: {
119
+ control: 'text',
120
+ description: 'Error message to display'
121
+ },
122
+ maxVisibleBadges: {
123
+ control: 'number',
124
+ description: 'Maximum number of selected region badges to show before "more" indicator'
125
+ },
126
+ searchPlaceholder: {
127
+ control: 'text',
128
+ description: 'Placeholder text for search input'
129
+ }
130
+ },
131
+ args: {
132
+ onRegionsChange: fn()
133
+ }
134
+ });
135
+ </script>
136
+
137
+ <Story
138
+ name="Default"
139
+ args={{
140
+ regionGroups: dummyRegionGroups,
141
+ selectedRegions: [],
142
+ usedRegions: emptyUsedRegions
143
+ }}
144
+ />
145
+
146
+ <Story
147
+ name="With Pre-selected Regions"
148
+ args={{
149
+ regionGroups: dummyRegionGroups,
150
+ selectedRegions: ['US-CA', 'US-FL', 'CA', 'MX'],
151
+ usedRegions: emptyUsedRegions
152
+ }}
153
+ />
154
+
155
+ <Story
156
+ name="Global Selected"
157
+ args={{
158
+ regionGroups: dummyRegionGroups,
159
+ selectedRegions: ['Global'],
160
+ usedRegions: emptyUsedRegions
161
+ }}
162
+ />
163
+
164
+ <Story
165
+ name="EU Selected"
166
+ args={{
167
+ regionGroups: dummyRegionGroups,
168
+ selectedRegions: ['EU'],
169
+ usedRegions: emptyUsedRegions
170
+ }}
171
+ />
172
+
173
+ <Story
174
+ name="Multiple US States Selected"
175
+ args={{
176
+ regionGroups: dummyRegionGroups,
177
+ selectedRegions: ['US-CA', 'US-CO', 'US-FL', 'US-GA', 'US-HI'],
178
+ usedRegions: emptyUsedRegions
179
+ }}
180
+ />
181
+
182
+ <Story
183
+ name="With Used Regions"
184
+ args={{
185
+ regionGroups: dummyRegionGroups,
186
+ selectedRegions: ['US-FL', 'MX'],
187
+ usedRegions: someUsedRegions
188
+ }}
189
+ parameters={{
190
+ docs: {
191
+ description: {
192
+ story:
193
+ 'Regions marked as "in-use" (California, Colorado, Canada, UK) are disabled and cannot be selected.'
194
+ }
195
+ }
196
+ }}
197
+ />
198
+
199
+ <Story
200
+ name="Global In Use"
201
+ args={{
202
+ regionGroups: dummyRegionGroups,
203
+ selectedRegions: [],
204
+ usedRegions: globalUsedRegions
205
+ }}
206
+ parameters={{
207
+ docs: {
208
+ description: {
209
+ story: 'When Global is in use, the Global option is disabled.'
210
+ }
211
+ }
212
+ }}
213
+ />
214
+
215
+ <Story
216
+ name="Loading State"
217
+ args={{
218
+ regionGroups: [],
219
+ selectedRegions: [],
220
+ usedRegions: emptyUsedRegions,
221
+ isLoading: true
222
+ }}
223
+ />
224
+
225
+ <Story
226
+ name="Error State"
227
+ args={{
228
+ regionGroups: [],
229
+ selectedRegions: [],
230
+ usedRegions: emptyUsedRegions,
231
+ error: 'Failed to load regions. Please try again.'
232
+ }}
233
+ />
234
+
235
+ <Story
236
+ name="Custom Max Visible Badges"
237
+ args={{
238
+ regionGroups: dummyRegionGroups,
239
+ selectedRegions: ['US-CA', 'US-CO', 'US-FL', 'US-GA', 'CA', 'MX', 'BR'],
240
+ usedRegions: emptyUsedRegions,
241
+ maxVisibleBadges: 3
242
+ }}
243
+ parameters={{
244
+ docs: {
245
+ description: {
246
+ story: 'Shows 3 region badges before displaying "+N more" indicator.'
247
+ }
248
+ }
249
+ }}
250
+ />
251
+
252
+ <Story
253
+ name="Custom Search Placeholder"
254
+ args={{
255
+ regionGroups: dummyRegionGroups,
256
+ selectedRegions: [],
257
+ usedRegions: emptyUsedRegions,
258
+ searchPlaceholder: 'Find your region...'
259
+ }}
260
+ />
261
+
262
+ <Story
263
+ name="Interactive - Clear Selections"
264
+ args={{
265
+ regionGroups: dummyRegionGroups,
266
+ selectedRegions: ['US-CA', 'US-FL', 'CA'],
267
+ usedRegions: emptyUsedRegions
268
+ }}
269
+ parameters={{
270
+ docs: {
271
+ description: {
272
+ story:
273
+ 'Test the "Clear all" functionality. Select some regions and click "Clear all" button.'
274
+ }
275
+ }
276
+ }}
277
+ />
278
+
279
+ <Story
280
+ name="Interactive - Search Functionality"
281
+ args={{
282
+ regionGroups: dummyRegionGroups,
283
+ selectedRegions: [],
284
+ usedRegions: emptyUsedRegions
285
+ }}
286
+ parameters={{
287
+ docs: {
288
+ description: {
289
+ story: 'Test search functionality. Try searching for "California", "CA", "United", etc.'
290
+ }
291
+ }
292
+ }}
293
+ />
294
+
295
+ <Story
296
+ name="Interactive - Nested Groups"
297
+ args={{
298
+ regionGroups: dummyRegionGroups,
299
+ selectedRegions: [],
300
+ usedRegions: emptyUsedRegions
301
+ }}
302
+ parameters={{
303
+ docs: {
304
+ description: {
305
+ story:
306
+ 'Test expanding/collapsing groups. Select "Select Countries" to see US States nested inside.'
307
+ }
308
+ }
309
+ }}
310
+ />
311
+
312
+ <Story
313
+ name="Many Selected Regions"
314
+ args={{
315
+ regionGroups: dummyRegionGroups,
316
+ selectedRegions: [
317
+ 'US-CA',
318
+ 'US-CO',
319
+ 'US-FL',
320
+ 'US-GA',
321
+ 'US-HI',
322
+ 'CA',
323
+ 'MX',
324
+ 'BR',
325
+ 'AR',
326
+ 'GB',
327
+ 'FR',
328
+ 'DE'
329
+ ],
330
+ usedRegions: emptyUsedRegions,
331
+ maxVisibleBadges: 2
332
+ }}
333
+ parameters={{
334
+ docs: {
335
+ description: {
336
+ story: 'Shows how the component handles many selected regions with badge overflow.'
337
+ }
338
+ }
339
+ }}
340
+ />
341
+
342
+ <Story
343
+ name="Empty Search Results"
344
+ args={{
345
+ regionGroups: dummyRegionGroups,
346
+ selectedRegions: [],
347
+ usedRegions: emptyUsedRegions
348
+ }}
349
+ parameters={{
350
+ docs: {
351
+ description: {
352
+ story:
353
+ 'Type a search term that yields no results (like "xyz123") to see empty search state.'
354
+ }
355
+ }
356
+ }}
357
+ />
358
+
359
+ <Story
360
+ name="Accessibility Test"
361
+ args={{
362
+ regionGroups: dummyRegionGroups,
363
+ selectedRegions: ['US-CA'],
364
+ usedRegions: emptyUsedRegions
365
+ }}
366
+ parameters={{
367
+ docs: {
368
+ description: {
369
+ story:
370
+ 'Test keyboard navigation: Tab to focus elements, Space/Enter to select, Arrow keys for navigation.'
371
+ }
372
+ },
373
+ a11y: {
374
+ config: {
375
+ rules: [
376
+ { id: 'button-name', enabled: true },
377
+ { id: 'aria-allowed-attr', enabled: true },
378
+ { id: 'aria-valid-attr', enabled: true }
379
+ ]
380
+ }
381
+ }
382
+ }}
383
+ />
@@ -0,0 +1,19 @@
1
+ import RegionSelector from './RegionSelector.svelte';
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports & {
10
+ $set?: any;
11
+ $on?: any;
12
+ };
13
+ z_$$bindings?: Bindings;
14
+ }
15
+ declare const RegionSelector: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
16
+ [evt: string]: CustomEvent<any>;
17
+ }, {}, {}, string>;
18
+ type RegionSelector = InstanceType<typeof RegionSelector>;
19
+ export default RegionSelector;