@foundrykit/blocks 1.0.24 → 1.0.25

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.
@@ -1,583 +0,0 @@
1
- 'use client';
2
-
3
- import React, { useState, useCallback, useMemo } from 'react';
4
-
5
- export interface Region {
6
- countries: string[];
7
- name: string;
8
- color?: string;
9
- href?: string;
10
- }
11
-
12
- export interface InteractiveRegionsMapProps {
13
- title: string;
14
- content?: string;
15
- regions: Region[];
16
- onRegionClick?: (region: Region) => void;
17
- onRegionHover?: (region: Region | null) => void;
18
- className?: string;
19
- }
20
-
21
- // Country code to name mapping for the SVG paths
22
- const COUNTRY_MAPPING: Record<string, string> = {
23
- us: 'united-states',
24
- ca: 'canada',
25
- mx: 'mexico',
26
- br: 'brazil',
27
- ar: 'argentina',
28
- gb: 'united-kingdom',
29
- fr: 'france',
30
- de: 'germany',
31
- es: 'spain',
32
- it: 'italy',
33
- ru: 'russia',
34
- cn: 'china',
35
- in: 'india',
36
- jp: 'japan',
37
- au: 'australia',
38
- za: 'south-africa',
39
- eg: 'egypt',
40
- ke: 'kenya',
41
- mg: 'madagascar',
42
- iq: 'iraq',
43
- ir: 'iran',
44
- sa: 'saudi-arabia',
45
- };
46
-
47
- // Reverse mapping for lookup
48
- const NAME_TO_CODE = Object.entries(COUNTRY_MAPPING).reduce(
49
- (acc, [code, name]) => ({ ...acc, [name]: code }),
50
- {} as Record<string, string>
51
- );
52
-
53
- export function InteractiveRegionsMap({
54
- title = 'Interactive Regions Map',
55
- content,
56
- regions = [],
57
- onRegionClick,
58
- onRegionHover,
59
- className = '',
60
- }: InteractiveRegionsMapProps) {
61
- const [hoveredRegion, setHoveredRegion] = useState<string | null>(null);
62
- const [isLoading, setIsLoading] = useState(false);
63
-
64
- // Create a map of country codes to regions for efficient lookup
65
- const countryToRegion = useMemo(() => {
66
- const mapping: Record<string, Region> = {};
67
-
68
- regions.forEach(region => {
69
- region.countries.forEach(country => {
70
- const countryCode = NAME_TO_CODE[country.toLowerCase()];
71
- if (countryCode) {
72
- mapping[countryCode] = region;
73
- }
74
- });
75
- });
76
-
77
- return mapping;
78
- }, [regions]);
79
-
80
- // Handle country hover
81
- const handleCountryHover = useCallback(
82
- (countryCode: string | null) => {
83
- if (!countryCode) {
84
- setHoveredRegion(null);
85
- onRegionHover?.(null);
86
- return;
87
- }
88
-
89
- const region = countryToRegion[countryCode];
90
- if (region) {
91
- setHoveredRegion(region.name);
92
- onRegionHover?.(region);
93
- } else {
94
- setHoveredRegion(null);
95
- onRegionHover?.(null);
96
- }
97
- },
98
- [countryToRegion, onRegionHover]
99
- );
100
-
101
- // Handle country click
102
- const handleCountryClick = useCallback(
103
- async (countryCode: string) => {
104
- const region = countryToRegion[countryCode];
105
- if (!region) return;
106
-
107
- setIsLoading(true);
108
-
109
- try {
110
- if (onRegionClick) {
111
- onRegionClick(region);
112
- } else if (region.href) {
113
- // Use standard navigation instead of Next.js router
114
- window.location.href = region.href;
115
- }
116
- } catch (error) {
117
- console.error('Navigation error:', error);
118
- } finally {
119
- setIsLoading(false);
120
- }
121
- },
122
- [countryToRegion, onRegionClick]
123
- );
124
-
125
- // Get country fill color based on region
126
- const getCountryFill = useCallback(
127
- (countryCode: string): string => {
128
- const region = countryToRegion[countryCode];
129
- if (!region) return '#e5e7eb'; // gray-200
130
-
131
- if (hoveredRegion && hoveredRegion !== region.name) {
132
- return region.color ? `${region.color}66` : '#d1d5db'; // semi-transparent or gray-300
133
- }
134
-
135
- return region.color || '#3b82f6'; // blue-500 default
136
- },
137
- [countryToRegion, hoveredRegion]
138
- );
139
-
140
- // Check if country is interactive
141
- const isCountryInteractive = useCallback(
142
- (countryCode: string): boolean => {
143
- return countryCode in countryToRegion;
144
- },
145
- [countryToRegion]
146
- );
147
-
148
- return (
149
- <section className={`mx-auto flex max-w-6xl flex-col p-6 ${className}`}>
150
- {/* Header */}
151
- <div className='mb-8 flex flex-col items-center justify-center text-center'>
152
- <h2 className='mb-2 text-3xl font-bold text-gray-900'>{title}</h2>
153
- {content && (
154
- <p className='max-w-2xl text-lg text-gray-600'>{content}</p>
155
- )}
156
- </div>
157
-
158
- {/* Map Container */}
159
- <div className='relative w-full overflow-hidden rounded-lg bg-gray-50 shadow-lg'>
160
- {isLoading && (
161
- <div className='absolute inset-0 z-10 flex items-center justify-center bg-white bg-opacity-75'>
162
- <div className='h-8 w-8 animate-spin rounded-full border-b-2 border-blue-600'></div>
163
- </div>
164
- )}
165
-
166
- <svg
167
- viewBox='0 0 1000 500'
168
- className='h-auto max-h-96 w-full'
169
- style={{ maxHeight: '500px' }}
170
- >
171
- {/* Simplified world map paths - in production, you'd use a complete world map SVG */}
172
-
173
- {/* United States */}
174
- <path
175
- id='us'
176
- d='M200 200 L350 200 L350 250 L200 250 Z'
177
- fill={getCountryFill('us')}
178
- stroke='#374151'
179
- strokeWidth='0.5'
180
- className={`transition-all duration-200 ${
181
- isCountryInteractive('us')
182
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
183
- : 'cursor-default'
184
- }`}
185
- onMouseEnter={() => handleCountryHover('us')}
186
- onMouseLeave={() => handleCountryHover(null)}
187
- onClick={() => handleCountryClick('us')}
188
- />
189
-
190
- {/* Canada */}
191
- <path
192
- id='ca'
193
- d='M200 150 L350 150 L350 200 L200 200 Z'
194
- fill={getCountryFill('ca')}
195
- stroke='#374151'
196
- strokeWidth='0.5'
197
- className={`transition-all duration-200 ${
198
- isCountryInteractive('ca')
199
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
200
- : 'cursor-default'
201
- }`}
202
- onMouseEnter={() => handleCountryHover('ca')}
203
- onMouseLeave={() => handleCountryHover(null)}
204
- onClick={() => handleCountryClick('ca')}
205
- />
206
-
207
- {/* France */}
208
- <path
209
- id='fr'
210
- d='M450 220 L480 220 L480 250 L450 250 Z'
211
- fill={getCountryFill('fr')}
212
- stroke='#374151'
213
- strokeWidth='0.5'
214
- className={`transition-all duration-200 ${
215
- isCountryInteractive('fr')
216
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
217
- : 'cursor-default'
218
- }`}
219
- onMouseEnter={() => handleCountryHover('fr')}
220
- onMouseLeave={() => handleCountryHover(null)}
221
- onClick={() => handleCountryClick('fr')}
222
- />
223
-
224
- {/* Germany */}
225
- <path
226
- id='de'
227
- d='M480 220 L510 220 L510 250 L480 250 Z'
228
- fill={getCountryFill('de')}
229
- stroke='#374151'
230
- strokeWidth='0.5'
231
- className={`transition-all duration-200 ${
232
- isCountryInteractive('de')
233
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
234
- : 'cursor-default'
235
- }`}
236
- onMouseEnter={() => handleCountryHover('de')}
237
- onMouseLeave={() => handleCountryHover(null)}
238
- onClick={() => handleCountryClick('de')}
239
- />
240
-
241
- {/* Spain */}
242
- <path
243
- id='es'
244
- d='M420 250 L450 250 L450 280 L420 280 Z'
245
- fill={getCountryFill('es')}
246
- stroke='#374151'
247
- strokeWidth='0.5'
248
- className={`transition-all duration-200 ${
249
- isCountryInteractive('es')
250
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
251
- : 'cursor-default'
252
- }`}
253
- onMouseEnter={() => handleCountryHover('es')}
254
- onMouseLeave={() => handleCountryHover(null)}
255
- onClick={() => handleCountryClick('es')}
256
- />
257
-
258
- {/* Iraq */}
259
- <path
260
- id='iq'
261
- d='M550 280 L570 280 L570 300 L550 300 Z'
262
- fill={getCountryFill('iq')}
263
- stroke='#374151'
264
- strokeWidth='0.5'
265
- className={`transition-all duration-200 ${
266
- isCountryInteractive('iq')
267
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
268
- : 'cursor-default'
269
- }`}
270
- onMouseEnter={() => handleCountryHover('iq')}
271
- onMouseLeave={() => handleCountryHover(null)}
272
- onClick={() => handleCountryClick('iq')}
273
- />
274
-
275
- {/* Iran */}
276
- <path
277
- id='ir'
278
- d='M570 280 L600 280 L600 300 L570 300 Z'
279
- fill={getCountryFill('ir')}
280
- stroke='#374151'
281
- strokeWidth='0.5'
282
- className={`transition-all duration-200 ${
283
- isCountryInteractive('ir')
284
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
285
- : 'cursor-default'
286
- }`}
287
- onMouseEnter={() => handleCountryHover('ir')}
288
- onMouseLeave={() => handleCountryHover(null)}
289
- onClick={() => handleCountryClick('ir')}
290
- />
291
-
292
- {/* South Africa */}
293
- <path
294
- id='za'
295
- d='M480 380 L510 380 L510 410 L480 410 Z'
296
- fill={getCountryFill('za')}
297
- stroke='#374151'
298
- strokeWidth='0.5'
299
- className={`transition-all duration-200 ${
300
- isCountryInteractive('za')
301
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
302
- : 'cursor-default'
303
- }`}
304
- onMouseEnter={() => handleCountryHover('za')}
305
- onMouseLeave={() => handleCountryHover(null)}
306
- onClick={() => handleCountryClick('za')}
307
- />
308
-
309
- {/* Kenya */}
310
- <path
311
- id='ke'
312
- d='M520 350 L540 350 L540 370 L520 370 Z'
313
- fill={getCountryFill('ke')}
314
- stroke='#374151'
315
- strokeWidth='0.5'
316
- className={`transition-all duration-200 ${
317
- isCountryInteractive('ke')
318
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
319
- : 'cursor-default'
320
- }`}
321
- onMouseEnter={() => handleCountryHover('ke')}
322
- onMouseLeave={() => handleCountryHover(null)}
323
- onClick={() => handleCountryClick('ke')}
324
- />
325
-
326
- {/* Madagascar */}
327
- <path
328
- id='mg'
329
- d='M540 380 L555 380 L555 400 L540 400 Z'
330
- fill={getCountryFill('mg')}
331
- stroke='#374151'
332
- strokeWidth='0.5'
333
- className={`transition-all duration-200 ${
334
- isCountryInteractive('mg')
335
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
336
- : 'cursor-default'
337
- }`}
338
- onMouseEnter={() => handleCountryHover('mg')}
339
- onMouseLeave={() => handleCountryHover(null)}
340
- onClick={() => handleCountryClick('mg')}
341
- />
342
-
343
- {/* United Kingdom */}
344
- <path
345
- id='gb'
346
- d='M420 200 L440 200 L440 220 L420 220 Z'
347
- fill={getCountryFill('gb')}
348
- stroke='#374151'
349
- strokeWidth='0.5'
350
- className={`transition-all duration-200 ${
351
- isCountryInteractive('gb')
352
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
353
- : 'cursor-default'
354
- }`}
355
- onMouseEnter={() => handleCountryHover('gb')}
356
- onMouseLeave={() => handleCountryHover(null)}
357
- onClick={() => handleCountryClick('gb')}
358
- />
359
-
360
- {/* Italy */}
361
- <path
362
- id='it'
363
- d='M480 250 L500 250 L500 280 L480 280 Z'
364
- fill={getCountryFill('it')}
365
- stroke='#374151'
366
- strokeWidth='0.5'
367
- className={`transition-all duration-200 ${
368
- isCountryInteractive('it')
369
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
370
- : 'cursor-default'
371
- }`}
372
- onMouseEnter={() => handleCountryHover('it')}
373
- onMouseLeave={() => handleCountryHover(null)}
374
- onClick={() => handleCountryClick('it')}
375
- />
376
-
377
- {/* Russia */}
378
- <path
379
- id='ru'
380
- d='M550 150 L650 150 L650 200 L550 200 Z'
381
- fill={getCountryFill('ru')}
382
- stroke='#374151'
383
- strokeWidth='0.5'
384
- className={`transition-all duration-200 ${
385
- isCountryInteractive('ru')
386
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
387
- : 'cursor-default'
388
- }`}
389
- onMouseEnter={() => handleCountryHover('ru')}
390
- onMouseLeave={() => handleCountryHover(null)}
391
- onClick={() => handleCountryClick('ru')}
392
- />
393
-
394
- {/* China */}
395
- <path
396
- id='cn'
397
- d='M700 220 L750 220 L750 270 L700 270 Z'
398
- fill={getCountryFill('cn')}
399
- stroke='#374151'
400
- strokeWidth='0.5'
401
- className={`transition-all duration-200 ${
402
- isCountryInteractive('cn')
403
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
404
- : 'cursor-default'
405
- }`}
406
- onMouseEnter={() => handleCountryHover('cn')}
407
- onMouseLeave={() => handleCountryHover(null)}
408
- onClick={() => handleCountryClick('cn')}
409
- />
410
-
411
- {/* India */}
412
- <path
413
- id='in'
414
- d='M650 280 L700 280 L700 320 L650 320 Z'
415
- fill={getCountryFill('in')}
416
- stroke='#374151'
417
- strokeWidth='0.5'
418
- className={`transition-all duration-200 ${
419
- isCountryInteractive('in')
420
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
421
- : 'cursor-default'
422
- }`}
423
- onMouseEnter={() => handleCountryHover('in')}
424
- onMouseLeave={() => handleCountryHover(null)}
425
- onClick={() => handleCountryClick('in')}
426
- />
427
-
428
- {/* Japan */}
429
- <path
430
- id='jp'
431
- d='M750 240 L770 240 L770 270 L750 270 Z'
432
- fill={getCountryFill('jp')}
433
- stroke='#374151'
434
- strokeWidth='0.5'
435
- className={`transition-all duration-200 ${
436
- isCountryInteractive('jp')
437
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
438
- : 'cursor-default'
439
- }`}
440
- onMouseEnter={() => handleCountryHover('jp')}
441
- onMouseLeave={() => handleCountryHover(null)}
442
- onClick={() => handleCountryClick('jp')}
443
- />
444
-
445
- {/* Australia */}
446
- <path
447
- id='au'
448
- d='M750 380 L800 380 L800 420 L750 420 Z'
449
- fill={getCountryFill('au')}
450
- stroke='#374151'
451
- strokeWidth='0.5'
452
- className={`transition-all duration-200 ${
453
- isCountryInteractive('au')
454
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
455
- : 'cursor-default'
456
- }`}
457
- onMouseEnter={() => handleCountryHover('au')}
458
- onMouseLeave={() => handleCountryHover(null)}
459
- onClick={() => handleCountryClick('au')}
460
- />
461
-
462
- {/* Brazil */}
463
- <path
464
- id='br'
465
- d='M300 320 L380 320 L380 400 L300 400 Z'
466
- fill={getCountryFill('br')}
467
- stroke='#374151'
468
- strokeWidth='0.5'
469
- className={`transition-all duration-200 ${
470
- isCountryInteractive('br')
471
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
472
- : 'cursor-default'
473
- }`}
474
- onMouseEnter={() => handleCountryHover('br')}
475
- onMouseLeave={() => handleCountryHover(null)}
476
- onClick={() => handleCountryClick('br')}
477
- />
478
-
479
- {/* Argentina */}
480
- <path
481
- id='ar'
482
- d='M280 400 L320 400 L320 460 L280 460 Z'
483
- fill={getCountryFill('ar')}
484
- stroke='#374151'
485
- strokeWidth='0.5'
486
- className={`transition-all duration-200 ${
487
- isCountryInteractive('ar')
488
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
489
- : 'cursor-default'
490
- }`}
491
- onMouseEnter={() => handleCountryHover('ar')}
492
- onMouseLeave={() => handleCountryHover(null)}
493
- onClick={() => handleCountryClick('ar')}
494
- />
495
-
496
- {/* Mexico */}
497
- <path
498
- id='mx'
499
- d='M150 280 L250 280 L250 320 L150 320 Z'
500
- fill={getCountryFill('mx')}
501
- stroke='#374151'
502
- strokeWidth='0.5'
503
- className={`transition-all duration-200 ${
504
- isCountryInteractive('mx')
505
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
506
- : 'cursor-default'
507
- }`}
508
- onMouseEnter={() => handleCountryHover('mx')}
509
- onMouseLeave={() => handleCountryHover(null)}
510
- onClick={() => handleCountryClick('mx')}
511
- />
512
-
513
- {/* Egypt */}
514
- <path
515
- id='eg'
516
- d='M500 310 L520 310 L520 330 L500 330 Z'
517
- fill={getCountryFill('eg')}
518
- stroke='#374151'
519
- strokeWidth='0.5'
520
- className={`transition-all duration-200 ${
521
- isCountryInteractive('eg')
522
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
523
- : 'cursor-default'
524
- }`}
525
- onMouseEnter={() => handleCountryHover('eg')}
526
- onMouseLeave={() => handleCountryHover(null)}
527
- onClick={() => handleCountryClick('eg')}
528
- />
529
-
530
- {/* Saudi Arabia */}
531
- <path
532
- id='sa'
533
- d='M530 300 L570 300 L570 330 L530 330 Z'
534
- fill={getCountryFill('sa')}
535
- stroke='#374151'
536
- strokeWidth='0.5'
537
- className={`transition-all duration-200 ${
538
- isCountryInteractive('sa')
539
- ? 'cursor-pointer hover:stroke-gray-700 hover:stroke-2'
540
- : 'cursor-default'
541
- }`}
542
- onMouseEnter={() => handleCountryHover('sa')}
543
- onMouseLeave={() => handleCountryHover(null)}
544
- onClick={() => handleCountryClick('sa')}
545
- />
546
- </svg>
547
- </div>
548
-
549
- {/* Legend */}
550
- {regions.length > 0 && (
551
- <div className='mt-6 flex flex-wrap justify-center gap-4'>
552
- {regions.map((region, index) => (
553
- <div
554
- key={index}
555
- className={`flex items-center gap-2 rounded-lg border px-3 py-2 transition-all duration-200 ${
556
- hoveredRegion === region.name
557
- ? 'border-gray-400 bg-gray-100 shadow-md'
558
- : 'border-gray-200 bg-white'
559
- }`}
560
- >
561
- <div
562
- className='h-4 w-4 rounded border border-gray-300'
563
- style={{
564
- backgroundColor: region.color || '#3b82f6',
565
- }}
566
- />
567
- <span className='text-sm font-medium text-gray-700'>
568
- {region.name}
569
- </span>
570
- </div>
571
- ))}
572
- </div>
573
- )}
574
-
575
- {/* Debug info in development */}
576
- {process.env.NODE_ENV === 'development' && hoveredRegion && (
577
- <div className='mt-4 rounded border border-yellow-200 bg-yellow-50 p-3 text-sm'>
578
- <strong>Debug:</strong> Hovering over region: {hoveredRegion}
579
- </div>
580
- )}
581
- </section>
582
- );
583
- }