@foundrykit/blocks 0.1.1 → 0.2.0

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