@dimaan/ui 0.0.1 → 0.0.2

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.cjs CHANGED
@@ -557,18 +557,11 @@ function SidebarNavItem({
557
557
  }
558
558
  );
559
559
  }
560
- function isSection(entry) {
561
- return "items" in entry && !("label" in entry && "href" in entry) && Array.isArray(entry.items);
562
- }
563
560
  function isGroup(entry) {
564
- return "items" in entry;
565
- }
566
- function normalize(nav) {
567
- if (nav.length === 0) return [];
568
- if (isSection(nav[0])) return nav;
569
- return [{ key: "__root", items: nav }];
561
+ return "items" in entry && Array.isArray(entry.items);
570
562
  }
571
- function renderItem(item) {
563
+ function renderItem(item, fallbackKey) {
564
+ const key = item.key ?? fallbackKey;
572
565
  if (item.render) {
573
566
  return /* @__PURE__ */ jsxRuntime.jsx(
574
567
  SidebarNavItem,
@@ -579,7 +572,7 @@ function renderItem(item) {
579
572
  render: item.render,
580
573
  children: item.label
581
574
  },
582
- item.key
575
+ key
583
576
  );
584
577
  }
585
578
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -591,7 +584,7 @@ function renderItem(item) {
591
584
  endSlot: item.endSlot,
592
585
  children: item.label
593
586
  },
594
- item.key
587
+ key
595
588
  );
596
589
  }
597
590
  function AppShell({
@@ -607,7 +600,6 @@ function AppShell({
607
600
  onCollapsedChange,
608
601
  children
609
602
  }) {
610
- const sections = normalize(nav);
611
603
  return /* @__PURE__ */ jsxRuntime.jsxs(
612
604
  DashboardLayout,
613
605
  {
@@ -620,19 +612,19 @@ function AppShell({
620
612
  brand.logo,
621
613
  brand.name ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm font-semibold", children: brand.name }) : null
622
614
  ] }),
623
- /* @__PURE__ */ jsxRuntime.jsx(SidebarNav, { children: sections.map((section) => /* @__PURE__ */ jsxRuntime.jsx(SidebarGroup, { label: section.label, children: section.items.map(
624
- (entry) => isGroup(entry) ? /* @__PURE__ */ jsxRuntime.jsx(
615
+ /* @__PURE__ */ jsxRuntime.jsx(SidebarNav, { children: nav.map(
616
+ (entry, index) => isGroup(entry) ? /* @__PURE__ */ jsxRuntime.jsx(
625
617
  SidebarNavGroup,
626
618
  {
627
619
  label: entry.label,
628
620
  icon: entry.icon,
629
621
  active: entry.active,
630
622
  defaultOpen: entry.defaultOpen ?? entry.items.some((i) => i.active),
631
- children: entry.items.map(renderItem)
623
+ children: entry.items.map((item, itemIndex) => renderItem(item, itemIndex))
632
624
  },
633
- entry.key
634
- ) : renderItem(entry)
635
- ) }, section.key)) }),
625
+ entry.key ?? index
626
+ ) : renderItem(entry, index)
627
+ ) }),
636
628
  sidebarFooter ? /* @__PURE__ */ jsxRuntime.jsx(SidebarFooter, { children: sidebarFooter }) : null
637
629
  ] }),
638
630
  /* @__PURE__ */ jsxRuntime.jsxs(DashboardMain, { children: [
@@ -849,6 +841,43 @@ var Input = react.forwardRef(function Input2({
849
841
  hasError ? /* @__PURE__ */ jsxRuntime.jsx("p", { id: errorId, className: "text-xs text-destructive", children: error }) : helperText ? /* @__PURE__ */ jsxRuntime.jsx("p", { id: helperId, className: "text-xs text-muted-foreground", children: helperText }) : null
850
842
  ] });
851
843
  });
844
+ function LanguageSwitcher({
845
+ languages,
846
+ value,
847
+ onChange,
848
+ ariaLabel = "Language",
849
+ className,
850
+ ...props
851
+ }) {
852
+ return /* @__PURE__ */ jsxRuntime.jsx(
853
+ "fieldset",
854
+ {
855
+ "aria-label": ariaLabel,
856
+ className: cn(
857
+ "inline-flex items-center rounded-md border border-border bg-background p-0.5 text-xs",
858
+ className
859
+ ),
860
+ ...props,
861
+ children: languages.map((lang) => {
862
+ const isActive = lang.code === value;
863
+ return /* @__PURE__ */ jsxRuntime.jsx(
864
+ "button",
865
+ {
866
+ type: "button",
867
+ onClick: () => onChange(lang.code),
868
+ "aria-pressed": isActive,
869
+ className: cn(
870
+ "rounded px-2 py-1 font-medium transition-colors",
871
+ isActive ? "bg-primary text-primary-foreground" : "text-muted-foreground hover:text-foreground"
872
+ ),
873
+ children: lang.label ?? lang.code.toUpperCase()
874
+ },
875
+ lang.code
876
+ );
877
+ })
878
+ }
879
+ );
880
+ }
852
881
  function readDocumentDirection() {
853
882
  if (typeof document === "undefined") return "ltr";
854
883
  const dir = document.documentElement.getAttribute("dir");
@@ -1371,6 +1400,7 @@ exports.HeaderMobileTrigger = HeaderMobileTrigger;
1371
1400
  exports.HeaderSearch = HeaderSearch;
1372
1401
  exports.HeaderTitle = HeaderTitle;
1373
1402
  exports.Input = Input;
1403
+ exports.LanguageSwitcher = LanguageSwitcher;
1374
1404
  exports.Sidebar = Sidebar;
1375
1405
  exports.SidebarFooter = SidebarFooter;
1376
1406
  exports.SidebarGroup = SidebarGroup;