@marcoschwartz/lite-ui 0.25.2 → 0.25.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/README.md +73 -0
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +38 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -16
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -603,33 +603,44 @@ var SidebarNav = ({
|
|
|
603
603
|
collapsed: controlledCollapsed,
|
|
604
604
|
onCollapseChange,
|
|
605
605
|
storageKey = "sidebar-nav-collapsed",
|
|
606
|
-
className = ""
|
|
606
|
+
className = "",
|
|
607
|
+
expandedWidth = 256,
|
|
608
|
+
collapsedWidth = 64
|
|
607
609
|
}) => {
|
|
608
610
|
const [internalCollapsed, setInternalCollapsed] = useState3(defaultCollapsed);
|
|
609
611
|
const [mounted, setMounted] = useState3(false);
|
|
610
612
|
const isControlled = controlledCollapsed !== void 0;
|
|
611
613
|
const collapsed = isControlled ? controlledCollapsed : internalCollapsed;
|
|
614
|
+
const currentWidth = collapsible && collapsed ? collapsedWidth : expandedWidth;
|
|
612
615
|
useEffect4(() => {
|
|
613
616
|
setMounted(true);
|
|
614
617
|
if (!isControlled && collapsible && typeof window !== "undefined") {
|
|
615
618
|
const stored = localStorage.getItem(storageKey);
|
|
616
619
|
if (stored !== null) {
|
|
617
|
-
|
|
620
|
+
const isCollapsed = stored === "true";
|
|
621
|
+
setInternalCollapsed(isCollapsed);
|
|
622
|
+
onCollapseChange?.(isCollapsed, isCollapsed ? collapsedWidth : expandedWidth);
|
|
618
623
|
}
|
|
619
624
|
}
|
|
620
625
|
}, [isControlled, collapsible, storageKey]);
|
|
626
|
+
useEffect4(() => {
|
|
627
|
+
if (mounted && collapsible) {
|
|
628
|
+
onCollapseChange?.(collapsed, currentWidth);
|
|
629
|
+
}
|
|
630
|
+
}, [mounted]);
|
|
621
631
|
const setCollapsed = useCallback((value) => {
|
|
622
632
|
if (!collapsible) return;
|
|
633
|
+
const newWidth = value ? collapsedWidth : expandedWidth;
|
|
623
634
|
if (isControlled) {
|
|
624
|
-
onCollapseChange?.(value);
|
|
635
|
+
onCollapseChange?.(value, newWidth);
|
|
625
636
|
} else {
|
|
626
637
|
setInternalCollapsed(value);
|
|
627
638
|
if (typeof window !== "undefined") {
|
|
628
639
|
localStorage.setItem(storageKey, String(value));
|
|
629
640
|
}
|
|
641
|
+
onCollapseChange?.(value, newWidth);
|
|
630
642
|
}
|
|
631
|
-
|
|
632
|
-
}, [collapsible, isControlled, onCollapseChange, storageKey]);
|
|
643
|
+
}, [collapsible, isControlled, onCollapseChange, storageKey, collapsedWidth, expandedWidth]);
|
|
633
644
|
const toggleCollapsed = useCallback(() => {
|
|
634
645
|
setCollapsed(!collapsed);
|
|
635
646
|
}, [collapsed, setCollapsed]);
|
|
@@ -638,16 +649,15 @@ var SidebarNav = ({
|
|
|
638
649
|
setCollapsed,
|
|
639
650
|
toggleCollapsed
|
|
640
651
|
};
|
|
641
|
-
const widthClass = collapsible && collapsed ? "w-16" : "w-64";
|
|
642
652
|
return /* @__PURE__ */ jsx7(SidebarNavContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx7(
|
|
643
653
|
"nav",
|
|
644
654
|
{
|
|
645
655
|
className: `
|
|
646
|
-
flex flex-col h-full
|
|
647
|
-
${widthClass}
|
|
656
|
+
flex flex-col h-full overflow-x-hidden overflow-y-auto
|
|
648
657
|
transition-[width] duration-200 ease-in-out
|
|
649
658
|
${className}
|
|
650
659
|
`,
|
|
660
|
+
style: { width: currentWidth },
|
|
651
661
|
"data-collapsed": collapsed,
|
|
652
662
|
children
|
|
653
663
|
}
|
|
@@ -658,7 +668,7 @@ var SidebarNavSection = ({
|
|
|
658
668
|
grow = false,
|
|
659
669
|
className = ""
|
|
660
670
|
}) => {
|
|
661
|
-
return /* @__PURE__ */ jsx7("div", { className:
|
|
671
|
+
return /* @__PURE__ */ jsx7("div", { className: `p-3 space-y-1 ${grow ? "flex-1 overflow-y-auto overflow-x-hidden" : ""} ${className}`, children });
|
|
662
672
|
};
|
|
663
673
|
var SidebarNavItem = ({
|
|
664
674
|
icon,
|
|
@@ -683,8 +693,8 @@ var SidebarNavItem = ({
|
|
|
683
693
|
flex items-center gap-3 w-full px-3 py-2.5 rounded-lg
|
|
684
694
|
text-sm font-medium
|
|
685
695
|
transition-colors duration-150
|
|
686
|
-
${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer
|
|
687
|
-
${active ? "bg-[hsl(var(--
|
|
696
|
+
${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
|
|
697
|
+
${active ? "bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))]" : "text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--foreground))]"}
|
|
688
698
|
${collapsed ? "justify-center px-0" : ""}
|
|
689
699
|
${className}
|
|
690
700
|
`;
|
|
@@ -1472,6 +1482,14 @@ var widthClasses2 = {
|
|
|
1472
1482
|
lg: "w-80"
|
|
1473
1483
|
// 320px
|
|
1474
1484
|
};
|
|
1485
|
+
var getWidthClass = (width) => {
|
|
1486
|
+
if (typeof width === "number") return "";
|
|
1487
|
+
return widthClasses2[width || "md"];
|
|
1488
|
+
};
|
|
1489
|
+
var getWidthStyle = (width) => {
|
|
1490
|
+
if (typeof width === "number") return { width, transition: "width 200ms ease-in-out" };
|
|
1491
|
+
return {};
|
|
1492
|
+
};
|
|
1475
1493
|
var paddingClasses = {
|
|
1476
1494
|
none: "p-0",
|
|
1477
1495
|
sm: "p-2",
|
|
@@ -1614,10 +1632,11 @@ var AppShell = ({
|
|
|
1614
1632
|
navbar && !navbarCollapsedDesktop && /* @__PURE__ */ jsxs10(
|
|
1615
1633
|
"aside",
|
|
1616
1634
|
{
|
|
1617
|
-
className: `${navbarDesktopShowClass} ${
|
|
1635
|
+
className: `${navbarDesktopShowClass} ${getWidthClass(navbarWidth)} ${getVariantClasses(navbarVariant, navbarWithBorder)} ${navbarWithBorder ? "border-r" : ""} flex-col shrink-0`,
|
|
1636
|
+
style: getWidthStyle(navbarWidth),
|
|
1618
1637
|
children: [
|
|
1619
1638
|
(logo || title) && /* @__PURE__ */ jsx79("div", { className: `${heightClasses[headerHeight]} px-4 flex items-center border-b border-[hsl(var(--border))] shrink-0`, children: logo || /* @__PURE__ */ jsx79("span", { className: "text-xl font-bold text-[hsl(var(--foreground))]", children: title }) }),
|
|
1620
|
-
/* @__PURE__ */ jsx79("nav", { className: "flex-1 overflow-y-auto", children: navbar.content })
|
|
1639
|
+
/* @__PURE__ */ jsx79("nav", { className: "flex-1 overflow-y-auto overflow-x-hidden", children: navbar.content })
|
|
1621
1640
|
]
|
|
1622
1641
|
}
|
|
1623
1642
|
),
|
|
@@ -1661,7 +1680,8 @@ var AppShell = ({
|
|
|
1661
1680
|
aside && !asideCollapsedDesktop && /* @__PURE__ */ jsx79(
|
|
1662
1681
|
"aside",
|
|
1663
1682
|
{
|
|
1664
|
-
className: `${asideDesktopShowClass} ${
|
|
1683
|
+
className: `${asideDesktopShowClass} ${getWidthClass(asideWidth)} ${getVariantClasses(asideVariant, asideWithBorder)} ${asideWithBorder ? "border-l" : ""} flex-col shrink-0 overflow-y-auto overflow-x-hidden`,
|
|
1684
|
+
style: getWidthStyle(asideWidth),
|
|
1665
1685
|
children: aside.content
|
|
1666
1686
|
}
|
|
1667
1687
|
),
|
|
@@ -1743,7 +1763,8 @@ var AppShell = ({
|
|
|
1743
1763
|
navbar && !navbarCollapsedDesktop && /* @__PURE__ */ jsx79(
|
|
1744
1764
|
"nav",
|
|
1745
1765
|
{
|
|
1746
|
-
className: `${navbarDesktopShowClass} ${
|
|
1766
|
+
className: `${navbarDesktopShowClass} ${getWidthClass(navbarWidth)} ${getVariantClasses(navbarVariant, navbarWithBorder)} ${navbarWithBorder ? "border-r" : ""} flex-col shrink-0 overflow-y-auto overflow-x-hidden`,
|
|
1767
|
+
style: getWidthStyle(navbarWidth),
|
|
1747
1768
|
children: navbar.content
|
|
1748
1769
|
}
|
|
1749
1770
|
),
|
|
@@ -1751,7 +1772,8 @@ var AppShell = ({
|
|
|
1751
1772
|
aside && !asideCollapsedDesktop && /* @__PURE__ */ jsx79(
|
|
1752
1773
|
"aside",
|
|
1753
1774
|
{
|
|
1754
|
-
className: `${asideDesktopShowClass} ${
|
|
1775
|
+
className: `${asideDesktopShowClass} ${getWidthClass(asideWidth)} ${getVariantClasses(asideVariant, asideWithBorder)} ${asideWithBorder ? "border-l" : ""} flex-col shrink-0 overflow-y-auto overflow-x-hidden`,
|
|
1776
|
+
style: getWidthStyle(asideWidth),
|
|
1755
1777
|
children: aside.content
|
|
1756
1778
|
}
|
|
1757
1779
|
)
|