@babelize/elements 1.1.2 → 1.1.4

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/dist/index.js CHANGED
@@ -1,21 +1,26 @@
1
- import { clsx } from 'clsx';
2
- import { twMerge } from 'tailwind-merge';
3
- import * as React3 from 'react';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ "use client";
5
2
 
6
3
  // src/lib/utils.ts
4
+ import { clsx } from "clsx";
5
+ import { twMerge } from "tailwind-merge";
7
6
  function cn(...inputs) {
8
7
  return twMerge(clsx(inputs));
9
8
  }
9
+
10
+ // src/registry/components/language-switcher.tsx
11
+ import * as React2 from "react";
12
+
13
+ // src/lib/use-controllable-state.ts
14
+ import * as React from "react";
10
15
  function useControllableState(value, defaultValue, onChange) {
11
16
  const isControlled = value !== void 0;
12
- const [uncontrolled, setUncontrolled] = React3.useState(defaultValue);
13
- const onChangeRef = React3.useRef(onChange);
14
- React3.useEffect(() => {
17
+ const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
18
+ const onChangeRef = React.useRef(onChange);
19
+ React.useEffect(() => {
15
20
  onChangeRef.current = onChange;
16
21
  }, [onChange]);
17
22
  const current = isControlled ? value : uncontrolled;
18
- const setValue = React3.useCallback(
23
+ const setValue = React.useCallback(
19
24
  (next) => {
20
25
  var _a;
21
26
  if (!isControlled) setUncontrolled(next);
@@ -25,6 +30,9 @@ function useControllableState(value, defaultValue, onChange) {
25
30
  );
26
31
  return [current, setValue];
27
32
  }
33
+
34
+ // src/registry/components/language-switcher.tsx
35
+ import { jsx, jsxs } from "react/jsx-runtime";
28
36
  var RTL_LOCALES = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "ps", "sd", "yi"]);
29
37
  function isRtl(code) {
30
38
  const lang = code.split("-")[0].toLowerCase();
@@ -225,7 +233,7 @@ function getLabel(code, mode) {
225
233
  if (!names) return code;
226
234
  return mode === "native" ? names[0] : names[1];
227
235
  }
228
- var LanguageSwitcher = React3.forwardRef(
236
+ var LanguageSwitcher = React2.forwardRef(
229
237
  function LanguageSwitcher2({
230
238
  locales,
231
239
  value,
@@ -242,11 +250,11 @@ var LanguageSwitcher = React3.forwardRef(
242
250
  (_b = defaultValue != null ? defaultValue : (_a = locales[0]) == null ? void 0 : _a.code) != null ? _b : "",
243
251
  onValueChange
244
252
  );
245
- const [open, setOpen] = React3.useState(false);
246
- const [search, setSearch] = React3.useState("");
247
- const ref = React3.useRef(null);
248
- const inputRef = React3.useRef(null);
249
- React3.useImperativeHandle(forwardedRef, () => ref.current);
253
+ const [open, setOpen] = React2.useState(false);
254
+ const [search, setSearch] = React2.useState("");
255
+ const ref = React2.useRef(null);
256
+ const inputRef = React2.useRef(null);
257
+ React2.useImperativeHandle(forwardedRef, () => ref.current);
250
258
  const resolveLabel = (l) => {
251
259
  var _a2;
252
260
  return (_a2 = l.label) != null ? _a2 : getLabel(l.code, labelMode);
@@ -256,7 +264,7 @@ var LanguageSwitcher = React3.forwardRef(
256
264
  (l) => resolveLabel(l).toLowerCase().includes(search.toLowerCase()) || l.code.toLowerCase().includes(search.toLowerCase())
257
265
  );
258
266
  const dir = isRtl(locale) ? "rtl" : "ltr";
259
- React3.useEffect(() => {
267
+ React2.useEffect(() => {
260
268
  function handleClickOutside(e) {
261
269
  if (ref.current && !ref.current.contains(e.target)) {
262
270
  setOpen(false);
@@ -266,11 +274,11 @@ var LanguageSwitcher = React3.forwardRef(
266
274
  document.addEventListener("mousedown", handleClickOutside);
267
275
  return () => document.removeEventListener("mousedown", handleClickOutside);
268
276
  }, []);
269
- React3.useEffect(() => {
277
+ React2.useEffect(() => {
270
278
  var _a2;
271
279
  if (open) (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
272
280
  }, [open]);
273
- React3.useEffect(() => {
281
+ React2.useEffect(() => {
274
282
  function handleKeyDown(e) {
275
283
  if (e.key === "Escape") {
276
284
  setOpen(false);
@@ -282,106 +290,118 @@ var LanguageSwitcher = React3.forwardRef(
282
290
  return () => document.removeEventListener("keydown", handleKeyDown);
283
291
  }
284
292
  }, [open]);
285
- return /* @__PURE__ */ jsxs("div", { ref, className: cn("relative inline-block text-sm z-50", className), ...rest, children: [
286
- /* @__PURE__ */ jsxs(
287
- "button",
288
- {
289
- type: "button",
290
- onClick: () => setOpen(!open),
291
- className: cn(
292
- "inline-flex items-center gap-2 rounded-lg border border-zinc-200 bg-zinc-100 px-3 py-2 text-sm font-medium text-zinc-900 transition-colors hover:bg-zinc-100 hover:text-zinc-900 focus:outline-none focus:ring-2 focus:ring-emerald-500/50 dark:border-zinc-800 dark:bg-zinc-800 dark:text-zinc-100 dark:hover:bg-zinc-700 dark:hover:text-zinc-50",
293
- dir === "rtl" && "flex-row-reverse"
294
- ),
295
- "aria-expanded": open,
296
- "aria-haspopup": "listbox",
297
- "aria-label": `Current language: ${activeLocale ? resolveLabel(activeLocale) : locale}`,
298
- children: [
299
- showFlags && /* @__PURE__ */ jsx("span", { className: "text-base", children: (_c = activeLocale == null ? void 0 : activeLocale.flag) != null ? _c : getFlag(locale) }),
300
- /* @__PURE__ */ jsx("span", { children: activeLocale ? resolveLabel(activeLocale) : locale }),
301
- /* @__PURE__ */ jsx(
302
- "svg",
303
- {
304
- className: cn(
305
- "size-4 text-zinc-500 transition-transform dark:text-zinc-400",
306
- open && "rotate-180"
307
- ),
308
- fill: "none",
309
- viewBox: "0 0 24 24",
310
- stroke: "currentColor",
311
- strokeWidth: 2,
312
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
313
- }
314
- )
315
- ]
316
- }
317
- ),
318
- open && /* @__PURE__ */ jsxs(
319
- "div",
320
- {
321
- className: "absolute z-50 mt-1 min-w-[200px] overflow-hidden rounded-xl border border-zinc-200 bg-white shadow-xl dark:border-zinc-800 dark:bg-zinc-950",
322
- role: "listbox",
323
- "aria-label": "Select language",
324
- children: [
325
- /* @__PURE__ */ jsx("div", { className: "border-b border-zinc-200 p-2 dark:border-zinc-800", children: /* @__PURE__ */ jsx(
326
- "input",
327
- {
328
- ref: inputRef,
329
- type: "text",
330
- placeholder: "Search...",
331
- value: search,
332
- onChange: (e) => setSearch(e.target.value),
333
- className: "w-full rounded-lg bg-zinc-100 px-3 py-1.5 text-sm text-zinc-900 outline-none placeholder:text-zinc-400 focus:ring-1 focus:ring-emerald-500/50 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder:text-zinc-500"
334
- }
335
- ) }),
336
- /* @__PURE__ */ jsxs("div", { className: "max-h-60 overflow-y-auto p-1", children: [
337
- filtered.map((l) => {
338
- var _a2;
339
- const isActive = l.code === locale;
340
- const itemDir = l.rtl || isRtl(l.code) ? "rtl" : "ltr";
341
- return /* @__PURE__ */ jsxs(
342
- "button",
293
+ return /* @__PURE__ */ jsxs(
294
+ "div",
295
+ {
296
+ ref,
297
+ dir,
298
+ className: cn("relative inline-block text-sm z-50", className),
299
+ ...rest,
300
+ children: [
301
+ /* @__PURE__ */ jsxs(
302
+ "button",
303
+ {
304
+ type: "button",
305
+ onClick: () => setOpen(!open),
306
+ className: cn(
307
+ "inline-flex items-center gap-2 rounded-lg border border-zinc-200 bg-zinc-100 px-3 py-2 text-sm font-medium text-zinc-900 transition-colors hover:bg-zinc-100 hover:text-zinc-900 focus:outline-none focus:ring-2 focus:ring-emerald-500/50 dark:border-zinc-800 dark:bg-zinc-800 dark:text-zinc-100 dark:hover:bg-zinc-700 dark:hover:text-zinc-50"
308
+ ),
309
+ "aria-expanded": open,
310
+ "aria-haspopup": "listbox",
311
+ "aria-label": `Current language: ${activeLocale ? resolveLabel(activeLocale) : locale}`,
312
+ children: [
313
+ showFlags && /* @__PURE__ */ jsx("span", { className: "text-base", children: (_c = activeLocale == null ? void 0 : activeLocale.flag) != null ? _c : getFlag(locale) }),
314
+ /* @__PURE__ */ jsx("span", { children: activeLocale ? resolveLabel(activeLocale) : locale }),
315
+ /* @__PURE__ */ jsx(
316
+ "svg",
343
317
  {
344
- type: "button",
345
- role: "option",
346
- "aria-selected": isActive,
347
- dir: itemDir,
348
- onClick: () => {
349
- setLocale(l.code);
350
- setOpen(false);
351
- setSearch("");
352
- },
353
318
  className: cn(
354
- "flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors",
355
- itemDir === "rtl" && "flex-row-reverse text-right",
356
- isActive ? "bg-emerald-500/10 text-emerald-600 font-medium dark:text-emerald-400" : "text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100"
319
+ "size-4 text-zinc-500 transition-transform dark:text-zinc-400",
320
+ open && "rotate-180"
357
321
  ),
358
- children: [
359
- showFlags && /* @__PURE__ */ jsx("span", { className: "text-base", children: (_a2 = l.flag) != null ? _a2 : getFlag(l.code) }),
360
- /* @__PURE__ */ jsx("span", { className: "flex-1", children: resolveLabel(l) }),
361
- isActive && /* @__PURE__ */ jsx(
362
- "svg",
363
- {
364
- className: "size-4 text-emerald-600 dark:text-emerald-400",
365
- fill: "none",
366
- viewBox: "0 0 24 24",
367
- stroke: "currentColor",
368
- strokeWidth: 2,
369
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
370
- }
371
- )
372
- ]
373
- },
374
- l.code
375
- );
376
- }),
377
- filtered.length === 0 && /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-zinc-500 dark:text-zinc-400", children: "No results" })
378
- ] })
379
- ]
380
- }
381
- )
382
- ] });
322
+ fill: "none",
323
+ viewBox: "0 0 24 24",
324
+ stroke: "currentColor",
325
+ strokeWidth: 2,
326
+ children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
327
+ }
328
+ )
329
+ ]
330
+ }
331
+ ),
332
+ open && /* @__PURE__ */ jsxs(
333
+ "div",
334
+ {
335
+ className: "absolute z-50 mt-1 min-w-[200px] overflow-hidden rounded-xl border border-zinc-200 bg-white shadow-xl dark:border-zinc-800 dark:bg-zinc-950",
336
+ role: "listbox",
337
+ "aria-label": "Select language",
338
+ children: [
339
+ /* @__PURE__ */ jsx("div", { className: "border-b border-zinc-200 p-2 dark:border-zinc-800", children: /* @__PURE__ */ jsx(
340
+ "input",
341
+ {
342
+ ref: inputRef,
343
+ type: "text",
344
+ placeholder: "Search...",
345
+ "aria-label": "Search languages",
346
+ value: search,
347
+ onChange: (e) => setSearch(e.target.value),
348
+ className: "w-full rounded-lg bg-zinc-100 px-3 py-1.5 text-sm text-zinc-900 outline-none placeholder:text-zinc-400 focus:ring-1 focus:ring-emerald-500/50 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder:text-zinc-500"
349
+ }
350
+ ) }),
351
+ /* @__PURE__ */ jsxs("div", { className: "max-h-60 overflow-y-auto p-1", children: [
352
+ filtered.map((l) => {
353
+ var _a2;
354
+ const isActive = l.code === locale;
355
+ const itemDir = l.rtl || isRtl(l.code) ? "rtl" : "ltr";
356
+ return /* @__PURE__ */ jsxs(
357
+ "button",
358
+ {
359
+ type: "button",
360
+ role: "option",
361
+ "aria-selected": isActive,
362
+ dir: itemDir,
363
+ onClick: () => {
364
+ setLocale(l.code);
365
+ setOpen(false);
366
+ setSearch("");
367
+ },
368
+ className: cn(
369
+ "flex w-full items-center gap-2 rounded-lg px-3 py-2 text-start text-sm transition-colors",
370
+ isActive ? "bg-emerald-500/10 text-emerald-600 font-medium dark:text-emerald-400" : "text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100"
371
+ ),
372
+ children: [
373
+ showFlags && /* @__PURE__ */ jsx("span", { className: "text-base", children: (_a2 = l.flag) != null ? _a2 : getFlag(l.code) }),
374
+ /* @__PURE__ */ jsx("span", { className: "flex-1", children: resolveLabel(l) }),
375
+ isActive && /* @__PURE__ */ jsx(
376
+ "svg",
377
+ {
378
+ className: "size-4 text-emerald-600 dark:text-emerald-400",
379
+ fill: "none",
380
+ viewBox: "0 0 24 24",
381
+ stroke: "currentColor",
382
+ strokeWidth: 2,
383
+ children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
384
+ }
385
+ )
386
+ ]
387
+ },
388
+ l.code
389
+ );
390
+ }),
391
+ filtered.length === 0 && /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-zinc-500 dark:text-zinc-400", children: "No results" })
392
+ ] })
393
+ ]
394
+ }
395
+ )
396
+ ]
397
+ }
398
+ );
383
399
  }
384
400
  );
401
+
402
+ // src/registry/components/phone-input.tsx
403
+ import * as React3 from "react";
404
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
385
405
  var COUNTRIES = [
386
406
  { code: "US", dialCode: "+1", name: "United States", flag: "\u{1F1FA}\u{1F1F8}" },
387
407
  { code: "GB", dialCode: "+44", name: "United Kingdom", flag: "\u{1F1EC}\u{1F1E7}" },
@@ -441,30 +461,26 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
441
461
  value,
442
462
  defaultValue,
443
463
  onValueChange,
444
- onChange,
445
464
  defaultCountry = "US",
446
465
  placeholder = "Phone number",
447
466
  disabled = false,
448
467
  className,
449
- showFlags,
450
- showFlag,
468
+ showFlags = true,
451
469
  label = "Phone number",
452
470
  ...rest
453
471
  }, forwardedRef) {
454
- var _a;
455
- const flagsVisible = (_a = showFlags != null ? showFlags : showFlag) != null ? _a : true;
456
472
  const [selectedCountry, setSelectedCountry] = React3.useState(
457
473
  () => {
458
- var _a2;
459
- return (_a2 = getCountryByCode(defaultCountry)) != null ? _a2 : COUNTRIES[0];
474
+ var _a;
475
+ return (_a = getCountryByCode(defaultCountry)) != null ? _a : COUNTRIES[0];
460
476
  }
461
477
  );
462
- const notify = onValueChange != null ? onValueChange : onChange;
463
478
  const [inputValue, setInputValue] = useControllableState(value, defaultValue != null ? defaultValue : "", void 0);
464
479
  const [open, setOpen] = React3.useState(false);
465
480
  const [search, setSearch] = React3.useState("");
466
481
  const ref = React3.useRef(null);
467
482
  const inputRef = React3.useRef(null);
483
+ const searchRef = React3.useRef(null);
468
484
  React3.useImperativeHandle(forwardedRef, () => inputRef.current);
469
485
  const filtered = COUNTRIES.filter(
470
486
  (c) => c.name.toLowerCase().includes(search.toLowerCase()) || c.dialCode.includes(search) || c.code.toLowerCase().includes(search.toLowerCase())
@@ -480,8 +496,8 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
480
496
  return () => document.removeEventListener("mousedown", handleClickOutside);
481
497
  }, []);
482
498
  React3.useEffect(() => {
483
- var _a2;
484
- if (open) (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
499
+ var _a;
500
+ if (open) (_a = searchRef.current) == null ? void 0 : _a.focus();
485
501
  }, [open]);
486
502
  React3.useEffect(() => {
487
503
  function handleKeyDown(e) {
@@ -496,20 +512,20 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
496
512
  }
497
513
  }, [open]);
498
514
  const handleCountrySelect = (country) => {
499
- var _a2;
515
+ var _a;
500
516
  setSelectedCountry(country);
501
517
  setOpen(false);
502
518
  setSearch("");
503
- notify == null ? void 0 : notify(inputValue, country);
504
- (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
519
+ onValueChange == null ? void 0 : onValueChange(inputValue, country);
520
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
505
521
  };
506
522
  const handleInputChange = (e) => {
507
523
  const newValue = e.target.value;
508
524
  setInputValue(newValue);
509
- notify == null ? void 0 : notify(newValue, selectedCountry);
525
+ onValueChange == null ? void 0 : onValueChange(newValue, selectedCountry);
510
526
  };
511
- return /* @__PURE__ */ jsxs("div", { ref, className: cn("relative inline-block text-sm", className), children: [
512
- /* @__PURE__ */ jsxs(
527
+ return /* @__PURE__ */ jsxs2("div", { ref, className: cn("relative inline-block text-sm", className), children: [
528
+ /* @__PURE__ */ jsxs2(
513
529
  "div",
514
530
  {
515
531
  className: cn(
@@ -518,7 +534,7 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
518
534
  disabled && "opacity-50 cursor-not-allowed"
519
535
  ),
520
536
  children: [
521
- /* @__PURE__ */ jsxs(
537
+ /* @__PURE__ */ jsxs2(
522
538
  "button",
523
539
  {
524
540
  type: "button",
@@ -533,9 +549,9 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
533
549
  "aria-expanded": open,
534
550
  "aria-haspopup": "listbox",
535
551
  children: [
536
- flagsVisible && /* @__PURE__ */ jsx("span", { className: "text-base leading-none", children: selectedCountry.flag }),
537
- /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: selectedCountry.dialCode }),
538
- /* @__PURE__ */ jsx(
552
+ showFlags && /* @__PURE__ */ jsx2("span", { className: "text-base leading-none", children: selectedCountry.flag }),
553
+ /* @__PURE__ */ jsx2("span", { className: "font-mono text-xs", children: selectedCountry.dialCode }),
554
+ /* @__PURE__ */ jsx2(
539
555
  "svg",
540
556
  {
541
557
  className: cn(
@@ -546,13 +562,13 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
546
562
  viewBox: "0 0 24 24",
547
563
  stroke: "currentColor",
548
564
  strokeWidth: 2,
549
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
565
+ children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
550
566
  }
551
567
  )
552
568
  ]
553
569
  }
554
570
  ),
555
- /* @__PURE__ */ jsx(
571
+ /* @__PURE__ */ jsx2(
556
572
  "input",
557
573
  {
558
574
  ref: inputRef,
@@ -574,28 +590,29 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
574
590
  ]
575
591
  }
576
592
  ),
577
- open && /* @__PURE__ */ jsxs(
593
+ open && /* @__PURE__ */ jsxs2(
578
594
  "div",
579
595
  {
580
596
  className: "absolute z-50 mt-1 min-w-[280px] overflow-hidden rounded-xl border border-zinc-200 bg-white shadow-xl dark:border-zinc-800 dark:bg-zinc-950",
581
597
  role: "listbox",
582
598
  "aria-label": "Select country",
583
599
  children: [
584
- /* @__PURE__ */ jsx("div", { className: "border-b border-zinc-200 p-2 dark:border-zinc-800", children: /* @__PURE__ */ jsx(
600
+ /* @__PURE__ */ jsx2("div", { className: "border-b border-zinc-200 p-2 dark:border-zinc-800", children: /* @__PURE__ */ jsx2(
585
601
  "input",
586
602
  {
587
- ref: inputRef,
603
+ ref: searchRef,
588
604
  type: "text",
589
605
  placeholder: "Search countries...",
606
+ "aria-label": "Search countries",
590
607
  value: search,
591
608
  onChange: (e) => setSearch(e.target.value),
592
609
  className: "w-full rounded-lg bg-zinc-100 px-3 py-1.5 text-sm text-zinc-900 outline-none placeholder:text-zinc-400 focus:ring-1 focus:ring-emerald-500/50 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder:text-zinc-500"
593
610
  }
594
611
  ) }),
595
- /* @__PURE__ */ jsxs("div", { className: "max-h-60 overflow-y-auto p-1", children: [
612
+ /* @__PURE__ */ jsxs2("div", { className: "max-h-60 overflow-y-auto p-1", children: [
596
613
  filtered.map((country) => {
597
614
  const isActive = country.code === selectedCountry.code;
598
- return /* @__PURE__ */ jsxs(
615
+ return /* @__PURE__ */ jsxs2(
599
616
  "button",
600
617
  {
601
618
  type: "button",
@@ -607,10 +624,10 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
607
624
  isActive ? "bg-emerald-500/10 text-emerald-600 font-medium dark:text-emerald-400" : "text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100"
608
625
  ),
609
626
  children: [
610
- /* @__PURE__ */ jsx("span", { className: "text-base leading-none", children: country.flag }),
611
- /* @__PURE__ */ jsx("span", { className: "flex-1", children: country.name }),
612
- /* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-zinc-500 dark:text-zinc-400", children: country.dialCode }),
613
- isActive && /* @__PURE__ */ jsx(
627
+ /* @__PURE__ */ jsx2("span", { className: "text-base leading-none", children: country.flag }),
628
+ /* @__PURE__ */ jsx2("span", { className: "flex-1", children: country.name }),
629
+ /* @__PURE__ */ jsx2("span", { className: "font-mono text-xs text-zinc-500 dark:text-zinc-400", children: country.dialCode }),
630
+ isActive && /* @__PURE__ */ jsx2(
614
631
  "svg",
615
632
  {
616
633
  className: "size-4 text-emerald-600 dark:text-emerald-400",
@@ -618,7 +635,7 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
618
635
  viewBox: "0 0 24 24",
619
636
  stroke: "currentColor",
620
637
  strokeWidth: 2,
621
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
638
+ children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
622
639
  }
623
640
  )
624
641
  ]
@@ -626,13 +643,17 @@ var PhoneInput = React3.forwardRef(function PhoneInput2({
626
643
  country.code
627
644
  );
628
645
  }),
629
- filtered.length === 0 && /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-zinc-500 dark:text-zinc-400", children: "No countries found" })
646
+ filtered.length === 0 && /* @__PURE__ */ jsx2("div", { className: "px-3 py-2 text-sm text-zinc-500 dark:text-zinc-400", children: "No countries found" })
630
647
  ] })
631
648
  ]
632
649
  }
633
650
  )
634
651
  ] });
635
652
  });
653
+
654
+ // src/registry/components/navbar.tsx
655
+ import * as React4 from "react";
656
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
636
657
  var LOCALE_MAP = {
637
658
  en: { label: "English", flag: "\u{1F1FA}\u{1F1F8}" },
638
659
  fr: { label: "Fran\xE7ais", flag: "\u{1F1EB}\u{1F1F7}" },
@@ -683,15 +704,13 @@ function getLocaleInfo(code) {
683
704
  var _a;
684
705
  return (_a = LOCALE_MAP[code]) != null ? _a : { label: code.toUpperCase(), flag: "\u{1F310}" };
685
706
  }
686
- var NavBar = React3.forwardRef(function NavBar2({
707
+ var NavBar = React4.forwardRef(function NavBar2({
687
708
  logo,
688
709
  links = [],
689
710
  locales = [],
690
711
  value,
691
712
  defaultValue,
692
713
  onValueChange,
693
- currentLocale,
694
- onLocaleChange,
695
714
  cta,
696
715
  showGitHub = false,
697
716
  githubUrl = "https://github.com/babelize/babelize-elements",
@@ -701,75 +720,85 @@ var NavBar = React3.forwardRef(function NavBar2({
701
720
  linkComponent: Link = "a",
702
721
  ...rest
703
722
  }, forwardedRef) {
723
+ var _a, _b;
704
724
  const [locale, setLocale] = useControllableState(
705
- value != null ? value : currentLocale,
706
- defaultValue != null ? defaultValue : "en",
707
- onValueChange != null ? onValueChange : onLocaleChange
725
+ value,
726
+ (_b = defaultValue != null ? defaultValue : (_a = locales[0]) == null ? void 0 : _a.code) != null ? _b : "en",
727
+ onValueChange
708
728
  );
709
- const [mobileOpen, setMobileOpen] = React3.useState(false);
710
- const [langOpen, setLangOpen] = React3.useState(false);
711
- const langRef = React3.useRef(null);
712
- const mobileLangRef = React3.useRef(null);
729
+ const [mobileOpen, setMobileOpen] = React4.useState(false);
730
+ const [langOpen, setLangOpen] = React4.useState(null);
731
+ const langRef = React4.useRef(null);
732
+ const mobileLangRef = React4.useRef(null);
733
+ const menuId = React4.useId();
713
734
  const currentLocaleInfo = getLocaleInfo(locale);
714
- React3.useEffect(() => {
735
+ React4.useEffect(() => {
715
736
  function handleClickOutside(e) {
716
- if (langRef.current && !langRef.current.contains(e.target)) {
717
- setLangOpen(false);
718
- }
737
+ var _a2, _b2;
738
+ const target = e.target;
739
+ if (((_a2 = langRef.current) == null ? void 0 : _a2.contains(target)) || ((_b2 = mobileLangRef.current) == null ? void 0 : _b2.contains(target))) return;
740
+ setLangOpen(null);
719
741
  }
720
742
  document.addEventListener("mousedown", handleClickOutside);
721
743
  return () => document.removeEventListener("mousedown", handleClickOutside);
722
744
  }, []);
723
- React3.useEffect(() => {
724
- if (mobileOpen) {
725
- document.body.style.overflow = "hidden";
726
- } else {
727
- document.body.style.overflow = "";
745
+ React4.useEffect(() => {
746
+ function handleKeyDown(e) {
747
+ if (e.key !== "Escape") return;
748
+ setLangOpen(null);
749
+ setMobileOpen(false);
728
750
  }
751
+ document.addEventListener("keydown", handleKeyDown);
752
+ return () => document.removeEventListener("keydown", handleKeyDown);
753
+ }, []);
754
+ React4.useEffect(() => {
755
+ if (!mobileOpen) return;
756
+ const previous = document.body.style.overflow;
757
+ document.body.style.overflow = "hidden";
729
758
  return () => {
730
- document.body.style.overflow = "";
759
+ document.body.style.overflow = previous;
731
760
  };
732
761
  }, [mobileOpen]);
733
- const langButton = /* @__PURE__ */ jsxs(
762
+ const langButton = /* @__PURE__ */ jsxs3(
734
763
  "button",
735
764
  {
736
765
  type: "button",
737
- onClick: () => setLangOpen(!langOpen),
766
+ onClick: () => setLangOpen(langOpen === "desktop" ? null : "desktop"),
738
767
  className: "flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm font-medium text-zinc-500 transition-colors hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
739
- "aria-expanded": langOpen,
768
+ "aria-expanded": langOpen === "desktop",
740
769
  "aria-haspopup": "listbox",
741
770
  "aria-label": `Current language: ${currentLocaleInfo.label}`,
742
771
  children: [
743
- showFlags && /* @__PURE__ */ jsx("span", { className: "text-sm leading-none", children: currentLocaleInfo.flag }),
744
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: currentLocaleInfo.label }),
745
- /* @__PURE__ */ jsx(
772
+ showFlags && /* @__PURE__ */ jsx3("span", { className: "text-sm leading-none", children: currentLocaleInfo.flag }),
773
+ /* @__PURE__ */ jsx3("span", { className: "hidden sm:inline", children: currentLocaleInfo.label }),
774
+ /* @__PURE__ */ jsx3(
746
775
  "svg",
747
776
  {
748
777
  className: cn(
749
778
  "size-3 text-zinc-500 transition-transform dark:text-zinc-400",
750
- langOpen && "rotate-180"
779
+ langOpen === "desktop" && "rotate-180"
751
780
  ),
752
781
  fill: "none",
753
782
  viewBox: "0 0 24 24",
754
783
  stroke: "currentColor",
755
784
  strokeWidth: 2,
756
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
785
+ children: /* @__PURE__ */ jsx3("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
757
786
  }
758
787
  )
759
788
  ]
760
789
  }
761
790
  );
762
- const langDropdown = /* @__PURE__ */ jsx(
791
+ const langDropdown = /* @__PURE__ */ jsx3(
763
792
  "div",
764
793
  {
765
794
  className: "absolute right-0 top-full z-50 mt-1.5 min-w-[170px] rounded-xl border border-zinc-200 bg-white py-1.5 shadow-xl dark:border-zinc-800 dark:bg-zinc-950",
766
795
  role: "listbox",
767
796
  "aria-label": "Select language",
768
797
  children: locales.map((item) => {
769
- var _a;
798
+ var _a2;
770
799
  const info = getLocaleInfo(item.code);
771
800
  const isActive = item.code === locale;
772
- return /* @__PURE__ */ jsxs(
801
+ return /* @__PURE__ */ jsxs3(
773
802
  "button",
774
803
  {
775
804
  type: "button",
@@ -777,16 +806,16 @@ var NavBar = React3.forwardRef(function NavBar2({
777
806
  "aria-selected": isActive,
778
807
  onClick: () => {
779
808
  setLocale(item.code);
780
- setLangOpen(false);
809
+ setLangOpen(null);
781
810
  },
782
811
  className: cn(
783
- "flex w-full items-center gap-2.5 px-3 py-2 text-sm rounded-lg mx-1.5 w-[calc(100%-12px)] transition-colors",
812
+ "mx-1.5 flex w-[calc(100%-12px)] items-center gap-2.5 rounded-lg px-3 py-2 text-sm transition-colors",
784
813
  isActive ? "bg-emerald-500/10 text-emerald-600 font-medium dark:text-emerald-400" : "text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100"
785
814
  ),
786
815
  children: [
787
- showFlags && /* @__PURE__ */ jsx("span", { className: "text-base leading-none", children: info.flag }),
788
- /* @__PURE__ */ jsx("span", { className: "flex-1", children: (_a = item.label) != null ? _a : info.label }),
789
- isActive && /* @__PURE__ */ jsx(
816
+ showFlags && /* @__PURE__ */ jsx3("span", { className: "text-base leading-none", children: info.flag }),
817
+ /* @__PURE__ */ jsx3("span", { className: "flex-1", children: (_a2 = item.label) != null ? _a2 : info.label }),
818
+ isActive && /* @__PURE__ */ jsx3(
790
819
  "svg",
791
820
  {
792
821
  className: "size-4 shrink-0 text-emerald-600 dark:text-emerald-400",
@@ -794,7 +823,7 @@ var NavBar = React3.forwardRef(function NavBar2({
794
823
  viewBox: "0 0 24 24",
795
824
  stroke: "currentColor",
796
825
  strokeWidth: 2.5,
797
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
826
+ children: /* @__PURE__ */ jsx3("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
798
827
  }
799
828
  )
800
829
  ]
@@ -804,7 +833,7 @@ var NavBar = React3.forwardRef(function NavBar2({
804
833
  })
805
834
  }
806
835
  );
807
- return /* @__PURE__ */ jsxs(
836
+ return /* @__PURE__ */ jsxs3(
808
837
  "nav",
809
838
  {
810
839
  ref: forwardedRef,
@@ -815,9 +844,9 @@ var NavBar = React3.forwardRef(function NavBar2({
815
844
  className
816
845
  ),
817
846
  children: [
818
- /* @__PURE__ */ jsxs("div", { className: "mx-auto hidden max-w-6xl items-center justify-between px-5 py-3 md:flex", children: [
819
- logo && /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: logo }),
820
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: links.map((link) => /* @__PURE__ */ jsx(
847
+ /* @__PURE__ */ jsxs3("div", { className: "mx-auto hidden max-w-6xl items-center justify-between px-5 py-3 md:flex", children: [
848
+ logo && /* @__PURE__ */ jsx3("div", { className: "flex-shrink-0", children: logo }),
849
+ /* @__PURE__ */ jsx3("div", { className: "flex items-center gap-1", children: links.map((link) => /* @__PURE__ */ jsx3(
821
850
  Link,
822
851
  {
823
852
  href: link.href,
@@ -826,12 +855,12 @@ var NavBar = React3.forwardRef(function NavBar2({
826
855
  },
827
856
  link.href
828
857
  )) }),
829
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
830
- locales.length > 0 && /* @__PURE__ */ jsxs("div", { ref: langRef, className: "relative", children: [
858
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
859
+ locales.length > 0 && /* @__PURE__ */ jsxs3("div", { ref: langRef, className: "relative", children: [
831
860
  langButton,
832
- langOpen && langDropdown
861
+ langOpen === "desktop" && langDropdown
833
862
  ] }),
834
- showGitHub && /* @__PURE__ */ jsx(
863
+ showGitHub && /* @__PURE__ */ jsx3(
835
864
  "a",
836
865
  {
837
866
  href: githubUrl,
@@ -839,10 +868,10 @@ var NavBar = React3.forwardRef(function NavBar2({
839
868
  rel: "noopener noreferrer",
840
869
  className: "inline-flex size-8 items-center justify-center rounded-md transition-colors no-underline text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
841
870
  "aria-label": "GitHub",
842
- children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" }) })
871
+ children: /* @__PURE__ */ jsx3("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx3("path", { d: "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" }) })
843
872
  }
844
873
  ),
845
- cta && /* @__PURE__ */ jsx(
874
+ cta && /* @__PURE__ */ jsx3(
846
875
  Link,
847
876
  {
848
877
  href: cta.href,
@@ -852,29 +881,34 @@ var NavBar = React3.forwardRef(function NavBar2({
852
881
  )
853
882
  ] })
854
883
  ] }),
855
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 md:hidden", children: [
856
- logo && /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: logo }),
857
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
858
- locales.length > 0 && /* @__PURE__ */ jsxs("div", { ref: mobileLangRef, className: "relative", children: [
859
- /* @__PURE__ */ jsx(
884
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between px-4 py-3 md:hidden", children: [
885
+ logo && /* @__PURE__ */ jsx3("div", { className: "flex-shrink-0", children: logo }),
886
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
887
+ locales.length > 0 && /* @__PURE__ */ jsxs3("div", { ref: mobileLangRef, className: "relative", children: [
888
+ /* @__PURE__ */ jsx3(
860
889
  "button",
861
890
  {
862
891
  type: "button",
863
- onClick: () => setLangOpen(!langOpen),
892
+ onClick: () => setLangOpen(langOpen === "mobile" ? null : "mobile"),
864
893
  className: "inline-flex size-8 items-center justify-center rounded-md transition-colors text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
894
+ "aria-expanded": langOpen === "mobile",
895
+ "aria-haspopup": "listbox",
865
896
  "aria-label": `Current language: ${currentLocaleInfo.label}`,
866
- children: showFlags && /* @__PURE__ */ jsx("span", { className: "text-base leading-none", children: currentLocaleInfo.flag })
897
+ children: showFlags && /* @__PURE__ */ jsx3("span", { className: "text-base leading-none", children: currentLocaleInfo.flag })
867
898
  }
868
899
  ),
869
- langOpen && langDropdown
900
+ langOpen === "mobile" && langDropdown
870
901
  ] }),
871
- /* @__PURE__ */ jsx(
902
+ /* @__PURE__ */ jsx3(
872
903
  "button",
873
904
  {
905
+ type: "button",
874
906
  className: "inline-flex size-8 items-center justify-center rounded-md transition-colors text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
875
907
  onClick: () => setMobileOpen(!mobileOpen),
876
908
  "aria-label": "Toggle menu",
877
- children: mobileOpen ? /* @__PURE__ */ jsx(
909
+ "aria-expanded": mobileOpen,
910
+ "aria-controls": mobileOpen ? menuId : void 0,
911
+ children: mobileOpen ? /* @__PURE__ */ jsx3(
878
912
  "svg",
879
913
  {
880
914
  className: "size-4",
@@ -882,9 +916,9 @@ var NavBar = React3.forwardRef(function NavBar2({
882
916
  viewBox: "0 0 24 24",
883
917
  stroke: "currentColor",
884
918
  strokeWidth: 2,
885
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
919
+ children: /* @__PURE__ */ jsx3("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
886
920
  }
887
- ) : /* @__PURE__ */ jsx(
921
+ ) : /* @__PURE__ */ jsx3(
888
922
  "svg",
889
923
  {
890
924
  className: "size-4",
@@ -892,39 +926,50 @@ var NavBar = React3.forwardRef(function NavBar2({
892
926
  viewBox: "0 0 24 24",
893
927
  stroke: "currentColor",
894
928
  strokeWidth: 2,
895
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 6h16M4 12h16M4 18h16" })
929
+ children: /* @__PURE__ */ jsx3("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 6h16M4 12h16M4 18h16" })
896
930
  }
897
931
  )
898
932
  }
899
933
  )
900
934
  ] })
901
935
  ] }),
902
- mobileOpen && /* @__PURE__ */ jsxs("div", { className: "border-t border-zinc-200 bg-white px-4 py-3 md:hidden dark:border-zinc-800 dark:bg-zinc-900", children: [
903
- links.map((link) => /* @__PURE__ */ jsx(
904
- Link,
905
- {
906
- href: link.href,
907
- onClick: () => setMobileOpen(false),
908
- className: "block py-2.5 text-sm transition-colors no-underline text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
909
- children: link.label
910
- },
911
- link.href
912
- )),
913
- cta && /* @__PURE__ */ jsx(
914
- Link,
915
- {
916
- href: cta.href,
917
- onClick: () => setMobileOpen(false),
918
- className: "mt-2 block rounded-md px-3.5 py-2 text-center text-sm font-medium transition-colors no-underline bg-emerald-500 text-white hover:opacity-90",
919
- children: cta.label
920
- }
921
- )
922
- ] })
936
+ mobileOpen && /* @__PURE__ */ jsxs3(
937
+ "div",
938
+ {
939
+ id: menuId,
940
+ className: "border-t border-zinc-200 bg-white px-4 py-3 md:hidden dark:border-zinc-800 dark:bg-zinc-900",
941
+ children: [
942
+ links.map((link) => /* @__PURE__ */ jsx3(
943
+ Link,
944
+ {
945
+ href: link.href,
946
+ onClick: () => setMobileOpen(false),
947
+ className: "block py-2.5 text-sm transition-colors no-underline text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50",
948
+ children: link.label
949
+ },
950
+ link.href
951
+ )),
952
+ cta && /* @__PURE__ */ jsx3(
953
+ Link,
954
+ {
955
+ href: cta.href,
956
+ onClick: () => setMobileOpen(false),
957
+ className: "mt-2 block rounded-md px-3.5 py-2 text-center text-sm font-medium transition-colors no-underline bg-emerald-500 text-white hover:opacity-90",
958
+ children: cta.label
959
+ }
960
+ )
961
+ ]
962
+ }
963
+ )
923
964
  ]
924
965
  }
925
966
  );
926
967
  });
927
-
928
- export { COUNTRIES, LanguageSwitcher, NavBar, PhoneInput, cn };
929
- //# sourceMappingURL=index.js.map
968
+ export {
969
+ COUNTRIES,
970
+ LanguageSwitcher,
971
+ NavBar,
972
+ PhoneInput,
973
+ cn
974
+ };
930
975
  //# sourceMappingURL=index.js.map