@ektyra/layout 0.0.0-stage → 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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/dist/appearance/appearance.d.ts +39 -0
  3. package/dist/appearance/appearance.js +102 -0
  4. package/dist/appearance/index.d.ts +3 -0
  5. package/dist/appearance/index.js +2 -0
  6. package/dist/appearance/preloader.d.ts +11 -0
  7. package/dist/appearance/preloader.js +28 -0
  8. package/dist/navigation/context.d.ts +25 -0
  9. package/dist/navigation/context.js +31 -0
  10. package/dist/navigation/index.d.ts +5 -0
  11. package/dist/navigation/index.js +3 -0
  12. package/dist/navigation/trail.d.ts +10 -0
  13. package/dist/navigation/trail.js +37 -0
  14. package/dist/navigation/types.d.ts +46 -0
  15. package/dist/navigation/types.js +1 -0
  16. package/dist/notifications/context.d.ts +16 -0
  17. package/dist/notifications/context.js +11 -0
  18. package/dist/notifications/index.d.ts +5 -0
  19. package/dist/notifications/index.js +3 -0
  20. package/dist/notifications/notification-item.d.ts +6 -0
  21. package/dist/notifications/notification-item.js +13 -0
  22. package/dist/notifications/notification-types.d.ts +27 -0
  23. package/dist/notifications/notification-types.js +10 -0
  24. package/dist/notifications/notifications-panel.d.ts +10 -0
  25. package/dist/notifications/notifications-panel.js +9 -0
  26. package/dist/shell/auth/auth-heading.d.ts +7 -0
  27. package/dist/shell/auth/auth-heading.js +5 -0
  28. package/dist/shell/auth/auth-layout.d.ts +10 -0
  29. package/dist/shell/auth/auth-layout.js +14 -0
  30. package/dist/shell/auth/auth-theme-toggle.d.ts +5 -0
  31. package/dist/shell/auth/auth-theme-toggle.js +12 -0
  32. package/dist/shell/auth/auth-usps.d.ts +2 -0
  33. package/dist/shell/auth/auth-usps.js +15 -0
  34. package/dist/shell/auth/index.d.ts +2 -0
  35. package/dist/shell/auth/index.js +2 -0
  36. package/dist/shell/customizer/color-scheme-choice.d.ts +2 -0
  37. package/dist/shell/customizer/color-scheme-choice.js +25 -0
  38. package/dist/shell/customizer/layout-wireframe.d.ts +11 -0
  39. package/dist/shell/customizer/layout-wireframe.js +12 -0
  40. package/dist/shell/customizer/option-picker.d.ts +17 -0
  41. package/dist/shell/customizer/option-picker.js +8 -0
  42. package/dist/shell/customizer/palette-data.d.ts +18 -0
  43. package/dist/shell/customizer/palette-data.js +64 -0
  44. package/dist/shell/customizer/theme-customizer.d.ts +5 -0
  45. package/dist/shell/customizer/theme-customizer.js +96 -0
  46. package/dist/shell/horizontal-menu/horizontal-menu-leaf.d.ts +5 -0
  47. package/dist/shell/horizontal-menu/horizontal-menu-leaf.js +11 -0
  48. package/dist/shell/horizontal-menu/horizontal-menu.d.ts +2 -0
  49. package/dist/shell/horizontal-menu/horizontal-menu.js +39 -0
  50. package/dist/shell/horizontal-menu/index.d.ts +1 -0
  51. package/dist/shell/horizontal-menu/index.js +1 -0
  52. package/dist/shell/logo.d.ts +7 -0
  53. package/dist/shell/logo.js +9 -0
  54. package/dist/shell/navbar/command-menu.d.ts +19 -0
  55. package/dist/shell/navbar/command-menu.js +32 -0
  56. package/dist/shell/navbar/index.d.ts +1 -0
  57. package/dist/shell/navbar/index.js +1 -0
  58. package/dist/shell/navbar/navbar-help.d.ts +1 -0
  59. package/dist/shell/navbar/navbar-help.js +6 -0
  60. package/dist/shell/navbar/navbar-notifications.d.ts +6 -0
  61. package/dist/shell/navbar/navbar-notifications.js +20 -0
  62. package/dist/shell/navbar/navbar-search.d.ts +1 -0
  63. package/dist/shell/navbar/navbar-search.js +19 -0
  64. package/dist/shell/navbar/navbar-sidebar-toggle.d.ts +1 -0
  65. package/dist/shell/navbar/navbar-sidebar-toggle.js +20 -0
  66. package/dist/shell/navbar/navbar-user-menu.d.ts +8 -0
  67. package/dist/shell/navbar/navbar-user-menu.js +14 -0
  68. package/dist/shell/navbar/navbar.d.ts +4 -0
  69. package/dist/shell/navbar/navbar.js +12 -0
  70. package/dist/shell/page-breadcrumbs.d.ts +11 -0
  71. package/dist/shell/page-breadcrumbs.js +23 -0
  72. package/dist/shell/page-header.d.ts +26 -0
  73. package/dist/shell/page-header.js +16 -0
  74. package/dist/shell/sidebar/index.d.ts +1 -0
  75. package/dist/shell/sidebar/index.js +1 -0
  76. package/dist/shell/sidebar/sidebar-group-label.d.ts +7 -0
  77. package/dist/shell/sidebar/sidebar-group-label.js +8 -0
  78. package/dist/shell/sidebar/sidebar-nav-item.d.ts +4 -0
  79. package/dist/shell/sidebar/sidebar-nav-item.js +12 -0
  80. package/dist/shell/sidebar/sidebar-nav-parent.d.ts +12 -0
  81. package/dist/shell/sidebar/sidebar-nav-parent.js +43 -0
  82. package/dist/shell/sidebar/sidebar-nav-styles.d.ts +7 -0
  83. package/dist/shell/sidebar/sidebar-nav-styles.js +7 -0
  84. package/dist/shell/sidebar/sidebar-nav.d.ts +6 -0
  85. package/dist/shell/sidebar/sidebar-nav.js +9 -0
  86. package/dist/shell/sidebar/sidebar-project-switcher.d.ts +11 -0
  87. package/dist/shell/sidebar/sidebar-project-switcher.js +19 -0
  88. package/dist/shell/sidebar/sidebar-tooltip.d.ts +19 -0
  89. package/dist/shell/sidebar/sidebar-tooltip.js +23 -0
  90. package/dist/shell/sidebar/sidebar.d.ts +8 -0
  91. package/dist/shell/sidebar/sidebar.js +18 -0
  92. package/dist/sidebar-state/index.d.ts +1 -0
  93. package/dist/sidebar-state/index.js +1 -0
  94. package/dist/sidebar-state/sidebar-state.d.ts +19 -0
  95. package/dist/sidebar-state/sidebar-state.js +75 -0
  96. package/package.json +67 -3
  97. package/README.md +0 -3
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from "react";
2
+ type PageHeaderProps = Readonly<{
3
+ title: string;
4
+ subtitle?: string;
5
+ /**
6
+ * Page-level actions, such as a "New entry" button or a date range. They sit on
7
+ * the right of the title and drop below it on narrow screens.
8
+ */
9
+ actions?: ReactNode;
10
+ /**
11
+ * For a detail page (one user, one entry): the name of the thing being viewed.
12
+ * It becomes the last breadcrumb, and the menu page before it becomes a link.
13
+ */
14
+ current?: string;
15
+ /** Replaces the icon tile, for example with a person's avatar. Pass `false` for none. */
16
+ leading?: ReactNode | false;
17
+ /** Hide the breadcrumbs, for a page that does not belong in the menu. */
18
+ hideBreadcrumbs?: boolean;
19
+ }>;
20
+ /**
21
+ * The top of every page: breadcrumbs, an icon tile (taken from the menu), the title
22
+ * (the page's <h1>) with its subtitle, and the actions on the right. A thin line
23
+ * separates it from the content.
24
+ */
25
+ export declare function PageHeader({ title, subtitle, actions, current, leading, hideBreadcrumbs, }: PageHeaderProps): import("react").JSX.Element;
26
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { PageBreadcrumbs, useTrailEntry } from "./page-breadcrumbs.js";
3
+ /**
4
+ * The top of every page: breadcrumbs, an icon tile (taken from the menu), the title
5
+ * (the page's <h1>) with its subtitle, and the actions on the right. A thin line
6
+ * separates it from the content.
7
+ */
8
+ export function PageHeader({ title, subtitle, actions, current, leading, hideBreadcrumbs, }) {
9
+ const entry = useTrailEntry();
10
+ const Icon = entry?.icon;
11
+ const tile = leading === false
12
+ ? null
13
+ : (leading ??
14
+ (Icon && (_jsx("span", { className: "hidden size-12 shrink-0 place-items-center rounded-xl bg-primary/10 text-primary sm:grid [&_svg]:size-6", children: _jsx(Icon, { "aria-hidden": "true" }) }))));
15
+ return (_jsxs("header", { className: "mb-8 border-b border-border pb-6", children: [!hideBreadcrumbs && _jsx(PageBreadcrumbs, { current: current }), _jsxs("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-4", children: [tile, _jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-3xl leading-tight tracking-tight", children: title }), subtitle && _jsx("p", { className: "mt-1 max-w-3xl text-muted-foreground", children: subtitle })] })] }), actions && _jsx("div", { className: "flex shrink-0 flex-wrap items-center gap-2", children: actions })] })] }));
16
+ }
@@ -0,0 +1 @@
1
+ export { Sidebar } from "./sidebar.tsx";
@@ -0,0 +1 @@
1
+ export { Sidebar } from "./sidebar.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A group heading in capitals. When the sidebar is collapsed the text goes and a
3
+ * divider takes its place, in a row of the same height so nothing below moves.
4
+ */
5
+ export declare function SidebarGroupLabel({ children }: Readonly<{
6
+ children: string;
7
+ }>): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A group heading in capitals. When the sidebar is collapsed the text goes and a
4
+ * divider takes its place, in a row of the same height so nothing below moves.
5
+ */
6
+ export function SidebarGroupLabel({ children }) {
7
+ return (_jsxs("div", { className: "flex h-8 items-center px-3 in-data-[sidebar=collapsed]:px-2", children: [_jsx("span", { className: "truncate text-[0.7rem] tracking-wider text-sidebar-foreground/50 uppercase in-data-[sidebar=collapsed]:hidden", children: children }), _jsx("div", { "aria-hidden": "true", className: "hidden h-px flex-1 bg-sidebar-border in-data-[sidebar=collapsed]:block" })] }));
8
+ }
@@ -0,0 +1,4 @@
1
+ import type { NavLeaf } from "../../navigation/index.ts";
2
+ export declare function SidebarNavItem({ item }: Readonly<{
3
+ item: NavLeaf;
4
+ }>): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link } from "@tanstack/react-router";
3
+ import { Badge } from "@ektyra/ui/components/badge";
4
+ import { useNavBadgeCount } from "../../navigation/index.js";
5
+ import { navLinkActiveClass, navLinkClass } from "./sidebar-nav-styles.js";
6
+ import { SidebarTooltip } from "./sidebar-tooltip.js";
7
+ export function SidebarNavItem({ item }) {
8
+ const Icon = item.icon;
9
+ const count = useNavBadgeCount(String(item.to));
10
+ const name = count > 0 ? `${item.label}, ${count} unread` : item.label;
11
+ return (_jsx(SidebarTooltip, { label: name, children: _jsxs(Link, { to: item.to, "aria-label": name, className: navLinkClass, activeProps: { className: navLinkActiveClass, "aria-current": "page" }, children: [_jsxs("span", { className: "relative shrink-0", children: [_jsx(Icon, { className: "size-4", "aria-hidden": "true" }), count > 0 && (_jsx("span", { "aria-hidden": "true", className: "absolute -top-1 -right-1 hidden size-2 rounded-full bg-primary ring-2 ring-sidebar in-data-[sidebar=collapsed]:block" }))] }), _jsx("span", { className: "truncate in-data-[sidebar=collapsed]:hidden", children: item.label }), count > 0 && (_jsx(Badge, { className: "ml-auto h-5 min-w-5 justify-center px-1.5 text-[0.65rem] tabular-nums in-data-[sidebar=collapsed]:hidden", children: count > 99 ? "99+" : count })), item.badge && (_jsx(Badge, { variant: "secondary", className: "ml-auto px-1.5 py-0 text-[0.65rem] in-data-[sidebar=collapsed]:hidden", children: item.badge }))] }) }));
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { NavParent } from "../../navigation/index.ts";
2
+ /**
3
+ * A menu item with a submenu. It is a button, not a link.
4
+ *
5
+ * - Sidebar expanded: the submenu opens below the item. It opens by itself
6
+ * while you are on one of its pages.
7
+ * - Sidebar collapsed: only the icon shows, and clicking it opens the submenu
8
+ * as a dropdown to the right of the item.
9
+ */
10
+ export declare function SidebarNavParent({ item }: Readonly<{
11
+ item: NavParent;
12
+ }>): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useState } from "react";
3
+ import { Link, useRouterState } from "@tanstack/react-router";
4
+ import { ChevronRight } from "lucide-react";
5
+ import { AnimatePresence, motion, useReducedMotion } from "motion/react";
6
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@ektyra/ui/components/dropdown-menu";
7
+ import { Tooltip, TooltipTrigger } from "@ektyra/ui/components/tooltip";
8
+ import { cn } from "@ektyra/ui/lib/cn";
9
+ import { useSidebarCollapsed } from "../../sidebar-state/index.js";
10
+ import { navLinkActiveClass, navLinkClass } from "./sidebar-nav-styles.js";
11
+ import { SidebarTooltipContent, useSidebarTooltip } from "./sidebar-tooltip.js";
12
+ /**
13
+ * A menu item with a submenu. It is a button, not a link.
14
+ *
15
+ * - Sidebar expanded: the submenu opens below the item. It opens by itself
16
+ * while you are on one of its pages.
17
+ * - Sidebar collapsed: only the icon shows, and clicking it opens the submenu
18
+ * as a dropdown to the right of the item.
19
+ */
20
+ export function SidebarNavParent({ item }) {
21
+ const Icon = item.icon;
22
+ const listId = useId();
23
+ const reduceMotion = useReducedMotion();
24
+ const collapsed = useSidebarCollapsed();
25
+ const tooltip = useSidebarTooltip();
26
+ const pathname = useRouterState({ select: (state) => state.location.pathname });
27
+ const inSection = item.children.some((child) => pathname === child.to || pathname.startsWith(`${child.to}/`));
28
+ // undefined = follow the route; a boolean = the user chose.
29
+ const [manual, setManual] = useState(undefined);
30
+ useEffect(() => setManual(undefined), [inSection]);
31
+ const open = manual ?? inSection;
32
+ const rowClass = cn(navLinkClass, "w-full cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring", inSection && "text-sidebar-foreground",
33
+ // Collapsed: no submenu is visible, so mark the section you are in.
34
+ inSection && "in-data-[sidebar=collapsed]:bg-sidebar-accent");
35
+ const rowContent = (_jsxs(_Fragment, { children: [_jsx(Icon, { className: "size-4 shrink-0", "aria-hidden": "true" }), _jsx("span", { className: "flex-1 truncate text-left in-data-[sidebar=collapsed]:hidden", children: item.label }), _jsx(ChevronRight, { className: cn("size-4 shrink-0 text-sidebar-foreground/50 transition-transform duration-200 in-data-[sidebar=collapsed]:hidden", !collapsed && open && "rotate-90"), "aria-hidden": "true" })] }));
36
+ if (collapsed) {
37
+ return (_jsxs(DropdownMenu, { children: [_jsxs(Tooltip, { ...tooltip, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": item.label, className: rowClass, children: rowContent }) }) }), _jsx(SidebarTooltipContent, { children: item.label })] }), _jsxs(DropdownMenuContent, { side: "right", align: "start", sideOffset: 12, className: "min-w-48", children: [_jsx(DropdownMenuLabel, { children: item.label }), item.children.map((child) => (_jsx(DropdownMenuItem, { asChild: true, children: _jsx(Link, { to: child.to, activeProps: {
38
+ className: "bg-accent text-accent-foreground",
39
+ "aria-current": "page",
40
+ }, children: child.label }) }, child.to)))] })] }));
41
+ }
42
+ return (_jsxs("div", { children: [_jsx("button", { type: "button", "aria-label": item.label, "aria-expanded": open, "aria-controls": listId, onClick: () => setManual(!open), className: rowClass, children: rowContent }), _jsx(AnimatePresence, { initial: false, children: open && (_jsx(motion.ul, { id: listId, initial: { height: 0, opacity: 0 }, animate: { height: "auto", opacity: 1 }, exit: { height: 0, opacity: 0 }, transition: { duration: reduceMotion ? 0 : 0.2, ease: [0.16, 1, 0.3, 1] }, className: "ml-5 flex flex-col gap-0.5 overflow-hidden border-l border-sidebar-border pl-2", children: item.children.map((child) => (_jsx("li", { className: "first:mt-1", children: _jsx(Link, { to: child.to, className: "flex h-8 items-center truncate rounded-md px-3 text-sm text-sidebar-foreground/70 transition-colors hover:bg-sidebar-accent/60 hover:text-sidebar-foreground", activeProps: { className: navLinkActiveClass, "aria-current": "page" }, children: child.label }) }, child.to))) })) })] }));
43
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared by menu items and submenu parents. The fixed height (h-9) matters: it
3
+ * keeps every row the same height whether the label is shown or hidden, so the
4
+ * icons do not move when the sidebar collapses.
5
+ */
6
+ export declare const navLinkClass = "flex h-9 items-center gap-3 rounded-md px-3 text-sm text-sidebar-foreground/70 transition-colors hover:bg-sidebar-accent/60 hover:text-sidebar-foreground";
7
+ export declare const navLinkActiveClass = "bg-sidebar-accent text-sidebar-accent-foreground hover:bg-sidebar-accent";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared by menu items and submenu parents. The fixed height (h-9) matters: it
3
+ * keeps every row the same height whether the label is shown or hidden, so the
4
+ * icons do not move when the sidebar collapses.
5
+ */
6
+ export const navLinkClass = "flex h-9 items-center gap-3 rounded-md px-3 text-sm text-sidebar-foreground/70 transition-colors hover:bg-sidebar-accent/60 hover:text-sidebar-foreground";
7
+ export const navLinkActiveClass = "bg-sidebar-accent text-sidebar-accent-foreground hover:bg-sidebar-accent";
@@ -0,0 +1,6 @@
1
+ import type { NavGroup } from "../../navigation/index.ts";
2
+ /** Renders groups of menu items. A group's label is a heading, or a divider when collapsed. */
3
+ export declare function SidebarNav({ groups, label }: Readonly<{
4
+ groups: NavGroup[];
5
+ label: string;
6
+ }>): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isNavParent } from "../../navigation/index.js";
3
+ import { SidebarGroupLabel } from "./sidebar-group-label.js";
4
+ import { SidebarNavItem } from "./sidebar-nav-item.js";
5
+ import { SidebarNavParent } from "./sidebar-nav-parent.js";
6
+ /** Renders groups of menu items. A group's label is a heading, or a divider when collapsed. */
7
+ export function SidebarNav({ groups, label }) {
8
+ return (_jsx("nav", { "aria-label": label, className: "flex flex-col gap-2", children: groups.map((group, index) => (_jsxs("div", { children: [group.label && _jsx(SidebarGroupLabel, { children: group.label }), _jsx("ul", { className: "flex flex-col gap-1", children: group.items.map((item) => (_jsx("li", { children: isNavParent(item) ? (_jsx(SidebarNavParent, { item: item })) : (_jsx(SidebarNavItem, { item: item })) }, item.label))) })] }, group.label ?? index))) }));
9
+ }
@@ -0,0 +1,11 @@
1
+ export type Project = {
2
+ id: string;
3
+ name: string;
4
+ };
5
+ /**
6
+ * Project / website selector. Renders nothing when there are no projects, so
7
+ * the sidebar works before that feature exists.
8
+ */
9
+ export declare function SidebarProjectSwitcher({ projects }: Readonly<{
10
+ projects: Project[];
11
+ }>): import("react").JSX.Element | null;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { ChevronsUpDown } from "lucide-react";
4
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@ektyra/ui/components/dropdown-menu";
5
+ import { SidebarTooltip } from "./sidebar-tooltip.js";
6
+ function ProjectMark({ name }) {
7
+ return (_jsx("span", { "aria-hidden": "true", className: "grid size-7 shrink-0 place-items-center rounded-md bg-secondary text-xs font-semibold text-secondary-foreground", children: name.charAt(0).toUpperCase() }));
8
+ }
9
+ /**
10
+ * Project / website selector. Renders nothing when there are no projects, so
11
+ * the sidebar works before that feature exists.
12
+ */
13
+ export function SidebarProjectSwitcher({ projects }) {
14
+ const [activeId, setActiveId] = useState(projects[0]?.id);
15
+ const active = projects.find((project) => project.id === activeId) ?? projects[0];
16
+ if (!active)
17
+ return null;
18
+ return (_jsxs(DropdownMenu, { children: [_jsx(SidebarTooltip, { label: active.name, children: _jsxs(DropdownMenuTrigger, { "aria-label": `Workspace: ${active.name}`, className: "flex w-full shrink-0 cursor-pointer items-center gap-2.5 rounded-lg border border-sidebar-border bg-background px-2.5 py-2 text-left text-sm outline-none transition-colors hover:bg-sidebar-accent/60 focus-visible:ring-2 focus-visible:ring-sidebar-ring data-[state=open]:bg-sidebar-accent/60 in-data-[sidebar=collapsed]:justify-center in-data-[sidebar=collapsed]:px-0", children: [_jsx(ProjectMark, { name: active.name }), _jsxs("span", { className: "grid min-w-0 flex-1 gap-0.5 in-data-[sidebar=collapsed]:hidden", children: [_jsx("span", { className: "truncate text-xs leading-none text-muted-foreground", children: "Workspace" }), _jsx("span", { className: "truncate leading-tight font-semibold", children: active.name })] }), _jsx(ChevronsUpDown, { className: "size-4 shrink-0 text-muted-foreground in-data-[sidebar=collapsed]:hidden", "aria-hidden": "true" })] }) }), _jsxs(DropdownMenuContent, { align: "start", className: "w-(--radix-dropdown-menu-trigger-width)", children: [_jsx(DropdownMenuLabel, { children: "Demo projects" }), _jsx(DropdownMenuRadioGroup, { value: active.id, onValueChange: setActiveId, children: projects.map((project) => (_jsxs(DropdownMenuRadioItem, { value: project.id, children: [_jsx(ProjectMark, { name: project.name }), _jsx("span", { className: "min-w-0 truncate", children: project.name })] }, project.id))) })] })] }));
19
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactElement } from "react";
2
+ /**
3
+ * Open state for a sidebar tooltip, which only ever shows while the sidebar is
4
+ * collapsed. When it is expanded the label is already visible, so a tooltip
5
+ * would only repeat it. Spread the result on a `Tooltip`.
6
+ */
7
+ export declare function useSidebarTooltip(): {
8
+ open: boolean;
9
+ onOpenChange: import("react").Dispatch<import("react").SetStateAction<boolean>>;
10
+ };
11
+ /** Tooltip content for a sidebar item: to the right, a little away from the icon. */
12
+ export declare function SidebarTooltipContent({ children }: Readonly<{
13
+ children: string;
14
+ }>): import("react").JSX.Element;
15
+ /** Wraps a single element (a link or button that accepts a ref and props). */
16
+ export declare function SidebarTooltip({ label, children, }: Readonly<{
17
+ label: string;
18
+ children: ReactElement;
19
+ }>): import("react").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Tooltip, TooltipContent, TooltipTrigger } from "@ektyra/ui/components/tooltip";
4
+ import { useSidebarCollapsed } from "../../sidebar-state/index.js";
5
+ /**
6
+ * Open state for a sidebar tooltip, which only ever shows while the sidebar is
7
+ * collapsed. When it is expanded the label is already visible, so a tooltip
8
+ * would only repeat it. Spread the result on a `Tooltip`.
9
+ */
10
+ export function useSidebarTooltip() {
11
+ const collapsed = useSidebarCollapsed();
12
+ const [open, setOpen] = useState(false);
13
+ return { open: open && collapsed, onOpenChange: setOpen };
14
+ }
15
+ /** Tooltip content for a sidebar item: to the right, a little away from the icon. */
16
+ export function SidebarTooltipContent({ children }) {
17
+ return (_jsx(TooltipContent, { side: "right", sideOffset: 14, children: children }));
18
+ }
19
+ /** Wraps a single element (a link or button that accepts a ref and props). */
20
+ export function SidebarTooltip({ label, children, }) {
21
+ const state = useSidebarTooltip();
22
+ return (_jsxs(Tooltip, { ...state, children: [_jsx(TooltipTrigger, { asChild: true, children: children }), _jsx(SidebarTooltipContent, { children: label })] }));
23
+ }
@@ -0,0 +1,8 @@
1
+ import type { Project } from "./sidebar-project-switcher.tsx";
2
+ /**
3
+ * The width comes from `--sidebar-width` and the collapsed look from
4
+ * `<html data-sidebar="collapsed">`. Both are set by `core/sidebar`.
5
+ */
6
+ export declare function Sidebar({ projects }: Readonly<{
7
+ projects?: Project[];
8
+ }>): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link } from "@tanstack/react-router";
3
+ import { useAutohideScrollbar } from "@ektyra/ui/lib/use-autohide-scrollbar";
4
+ import { Logo } from "../logo.js";
5
+ import { useNavigation } from "../../navigation/index.js";
6
+ import { SidebarNav } from "./sidebar-nav.js";
7
+ import { SidebarProjectSwitcher } from "./sidebar-project-switcher.js";
8
+ // No project feature yet. When projects exist, pass them in from the layout.
9
+ const NO_PROJECTS = [];
10
+ /**
11
+ * The width comes from `--sidebar-width` and the collapsed look from
12
+ * `<html data-sidebar="collapsed">`. Both are set by `core/sidebar`.
13
+ */
14
+ export function Sidebar({ projects = NO_PROJECTS }) {
15
+ const scrollRef = useAutohideScrollbar();
16
+ const { main, footer } = useNavigation();
17
+ return (_jsxs("aside", { className: "sticky top-0 flex h-dvh w-(--sidebar-width) in-data-[layout=horizontal]:hidden shrink-0 flex-col gap-4 overflow-hidden border-r border-sidebar-border bg-sidebar p-3 text-sidebar-foreground in-data-[layout=detached]:top-3 in-data-[layout=detached]:m-3 in-data-[layout=detached]:h-[calc(100dvh-1.5rem)] in-data-[layout=detached]:rounded-xl in-data-[layout=detached]:border in-data-[layout=detached]:shadow-sm", children: [_jsx(Link, { to: "/", "aria-label": "Ektyra, go to the app", className: "flex h-9 shrink-0 items-center rounded-md px-3 outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring", children: _jsx("span", { className: "block overflow-hidden", style: { width: "clamp(1.1rem, calc(var(--sidebar-width) - 3rem), 4.9rem)" }, children: _jsx(Logo, { className: "h-6 w-auto max-w-none" }) }) }), _jsx(SidebarProjectSwitcher, { projects: projects }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-2", children: [_jsx("div", { ref: scrollRef, className: "scrollbar-primary scrollbar-autohide -mr-3 -ml-1 min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain pr-1 pl-1 in-data-[sidebar=collapsed]:scrollbar-hidden in-data-[sidebar=collapsed]:pr-3", children: _jsx(SidebarNav, { groups: main, label: "Main" }) }), _jsx(SidebarNav, { groups: footer, label: "Secondary" })] })] }));
18
+ }
@@ -0,0 +1 @@
1
+ export { setSidebarCollapsed, sidebarInitScript, toggleSidebar, useSidebarCollapsed, } from "./sidebar-state.ts";
@@ -0,0 +1 @@
1
+ export { setSidebarCollapsed, sidebarInitScript, toggleSidebar, useSidebarCollapsed, } from "./sidebar-state.js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Sidebar collapse state, driven by the DOM instead of React state so the
3
+ * right layout is there from first paint (no flash on reload):
4
+ *
5
+ * - `<html data-sidebar="collapsed">` is the resting state. CSS reads it for the
6
+ * width (`--sidebar-width`) and to hide labels. See `styles.css`.
7
+ * - While the width animates, Motion drives `--sidebar-width` inline.
8
+ * - On collapse the attribute is set only AFTER the animation finishes, so
9
+ * labels stay visible until the sidebar is narrow. On expand it is removed
10
+ * immediately, so labels are there while the sidebar grows.
11
+ */
12
+ export declare const SIDEBAR_STORAGE_KEY = "ektyra-cms-sidebar";
13
+ /** Inline script for <head>: restores the saved state before first paint. */
14
+ export declare const sidebarInitScript: string;
15
+ export declare function toggleSidebar(): void;
16
+ /** True when the sidebar is (or is becoming) collapsed. Safe to use for aria only. */
17
+ export declare function useSidebarCollapsed(): boolean;
18
+ /** Collapse or expand the sidebar to a known state (it does nothing if it already is). */
19
+ export declare function setSidebarCollapsed(collapsed: boolean): void;
@@ -0,0 +1,75 @@
1
+ import { animate } from "motion";
2
+ import { useSyncExternalStore } from "react";
3
+ /**
4
+ * Sidebar collapse state, driven by the DOM instead of React state so the
5
+ * right layout is there from first paint (no flash on reload):
6
+ *
7
+ * - `<html data-sidebar="collapsed">` is the resting state. CSS reads it for the
8
+ * width (`--sidebar-width`) and to hide labels. See `styles.css`.
9
+ * - While the width animates, Motion drives `--sidebar-width` inline.
10
+ * - On collapse the attribute is set only AFTER the animation finishes, so
11
+ * labels stay visible until the sidebar is narrow. On expand it is removed
12
+ * immediately, so labels are there while the sidebar grows.
13
+ */
14
+ export const SIDEBAR_STORAGE_KEY = "ektyra-cms-sidebar";
15
+ const ATTRIBUTE = "data-sidebar";
16
+ const COLLAPSED_WIDTH = "4rem";
17
+ const EXPANDED_WIDTH = "16rem";
18
+ const DURATION = 0.3;
19
+ /** Inline script for <head>: restores the saved state before first paint. */
20
+ export const sidebarInitScript = `(function(){try{if(localStorage.getItem(${JSON.stringify(SIDEBAR_STORAGE_KEY)})==="collapsed")document.documentElement.setAttribute(${JSON.stringify(ATTRIBUTE)},"collapsed")}catch(e){}})();`;
21
+ // The intended state. It differs from the attribute while an animation runs.
22
+ let target;
23
+ let run = 0;
24
+ const listeners = new Set();
25
+ const root = () => document.documentElement;
26
+ const readAttribute = () => root().getAttribute(ATTRIBUTE) === "collapsed";
27
+ function getTarget() {
28
+ target ??= readAttribute();
29
+ return target;
30
+ }
31
+ const subscribe = (listener) => {
32
+ listeners.add(listener);
33
+ return () => listeners.delete(listener);
34
+ };
35
+ export function toggleSidebar() {
36
+ const collapsing = !getTarget();
37
+ target = collapsing;
38
+ const thisRun = ++run;
39
+ try {
40
+ localStorage.setItem(SIDEBAR_STORAGE_KEY, collapsing ? "collapsed" : "expanded");
41
+ }
42
+ catch {
43
+ /* storage unavailable: the choice lasts for this visit only */
44
+ }
45
+ // Freeze the current width so an interrupted animation continues from it.
46
+ const from = getComputedStyle(root()).getPropertyValue("--sidebar-width").trim();
47
+ const to = collapsing ? COLLAPSED_WIDTH : EXPANDED_WIDTH;
48
+ const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
49
+ if (!collapsing)
50
+ root().removeAttribute(ATTRIBUTE);
51
+ root().style.setProperty("--sidebar-width", from);
52
+ const finish = () => {
53
+ if (thisRun !== run)
54
+ return; // a newer toggle took over
55
+ if (collapsing)
56
+ root().setAttribute(ATTRIBUTE, "collapsed");
57
+ root().style.removeProperty("--sidebar-width");
58
+ };
59
+ if (reduceMotion) {
60
+ finish();
61
+ }
62
+ else {
63
+ void animate(root(), { "--sidebar-width": [from, to] }, { duration: DURATION, ease: [0.16, 1, 0.3, 1] }).then(finish);
64
+ }
65
+ listeners.forEach((listener) => listener());
66
+ }
67
+ /** True when the sidebar is (or is becoming) collapsed. Safe to use for aria only. */
68
+ export function useSidebarCollapsed() {
69
+ return useSyncExternalStore(subscribe, getTarget, () => false);
70
+ }
71
+ /** Collapse or expand the sidebar to a known state (it does nothing if it already is). */
72
+ export function setSidebarCollapsed(collapsed) {
73
+ if (getTarget() !== collapsed)
74
+ toggleSidebar();
75
+ }
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@ektyra/layout",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ektyra/packages.git",
8
+ "directory": "packages/layout"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "LICENSE"
13
+ ],
14
+ "type": "module",
15
+ "exports": {
16
+ "./navigation": {
17
+ "types": "./dist/navigation/index.d.ts",
18
+ "default": "./dist/navigation/index.js"
19
+ },
20
+ "./notifications": {
21
+ "types": "./dist/notifications/index.d.ts",
22
+ "default": "./dist/notifications/index.js"
23
+ },
24
+ "./appearance": {
25
+ "types": "./dist/appearance/index.d.ts",
26
+ "default": "./dist/appearance/index.js"
27
+ },
28
+ "./sidebar-state": {
29
+ "types": "./dist/sidebar-state/index.d.ts",
30
+ "default": "./dist/sidebar-state/index.js"
31
+ },
32
+ "./shell/customizer/palette-data": {
33
+ "types": "./dist/shell/customizer/palette-data.d.ts",
34
+ "default": "./dist/shell/customizer/palette-data.js"
35
+ },
36
+ "./shell/*": {
37
+ "types": "./dist/shell/*.d.ts",
38
+ "default": "./dist/shell/*.js"
39
+ }
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "provenance": true
44
+ },
45
+ "dependencies": {
46
+ "lucide-react": "1.74.0",
47
+ "radix-ui": "1.8.1",
48
+ "@ektyra/ui": "0.2.0"
49
+ },
50
+ "devDependencies": {
51
+ "@tanstack/react-router": "1.170.46",
52
+ "@types/react": "19.3.0",
53
+ "@types/react-dom": "19.3.0",
54
+ "date-fns": "4.4.0",
55
+ "motion": "14.14.0",
56
+ "react": "19.3.1",
57
+ "react-dom": "19.3.1"
58
+ },
59
+ "peerDependencies": {
60
+ "@tanstack/react-router": "1.170.46",
61
+ "date-fns": "4.4.0",
62
+ "motion": "14.14.0",
63
+ "react": ">=19",
64
+ "react-dom": ">=19"
65
+ },
66
+ "scripts": {
67
+ "test": "node --test tests/*.test.mjs",
68
+ "typecheck": "tsc -p tsconfig.json --noEmit"
69
+ }
6
70
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.