@ggem-farming/ui 0.0.0-stage → 0.0.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.
- package/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/accordion/accordion.d.ts +41 -0
- package/dist/accordion/accordion.js +89 -0
- package/dist/avatar/avatar.d.ts +20 -0
- package/dist/avatar/avatar.js +38 -0
- package/dist/badge/badge.d.ts +16 -0
- package/dist/badge/badge.js +85 -0
- package/dist/breadcrumbs/breadcrumbs.d.ts +19 -0
- package/dist/breadcrumbs/breadcrumbs.js +44 -0
- package/dist/button/button.d.ts +16 -0
- package/dist/button/button.js +49 -0
- package/dist/button/icon-button.d.ts +17 -0
- package/dist/button/icon-button.js +33 -0
- package/dist/card/card.d.ts +16 -0
- package/dist/card/card.js +56 -0
- package/dist/checkbox/checkbox.d.ts +15 -0
- package/dist/checkbox/checkbox.js +47 -0
- package/dist/combobox/combobox.d.ts +37 -0
- package/dist/combobox/combobox.js +155 -0
- package/dist/command/command-palette.d.ts +50 -0
- package/dist/command/command-palette.js +170 -0
- package/dist/command/kbd.d.ts +6 -0
- package/dist/command/kbd.js +16 -0
- package/dist/data/data-table.d.ts +105 -0
- package/dist/data/data-table.js +269 -0
- package/dist/data/export-button.d.ts +19 -0
- package/dist/data/export-button.js +34 -0
- package/dist/data/filter-bar.d.ts +54 -0
- package/dist/data/filter-bar.js +187 -0
- package/dist/data/pagination.d.ts +13 -0
- package/dist/data/pagination.js +84 -0
- package/dist/data/selection-bar.d.ts +21 -0
- package/dist/data/selection-bar.js +31 -0
- package/dist/date/date-input.d.ts +41 -0
- package/dist/date/date-input.js +71 -0
- package/dist/dialog/confirm-dialog.d.ts +24 -0
- package/dist/dialog/confirm-dialog.js +77 -0
- package/dist/dialog/dialog.d.ts +46 -0
- package/dist/dialog/dialog.js +102 -0
- package/dist/dialog/form-panel.d.ts +28 -0
- package/dist/dialog/form-panel.js +51 -0
- package/dist/feedback/alert.d.ts +29 -0
- package/dist/feedback/alert.js +70 -0
- package/dist/feedback/progress.d.ts +25 -0
- package/dist/feedback/progress.js +54 -0
- package/dist/feedback/toaster.d.ts +7 -0
- package/dist/feedback/toaster.js +35 -0
- package/dist/field/field.d.ts +40 -0
- package/dist/field/field.js +83 -0
- package/dist/field/text-field.d.ts +9 -0
- package/dist/field/text-field.js +16 -0
- package/dist/file-input/file-input.d.ts +26 -0
- package/dist/file-input/file-input.js +149 -0
- package/dist/fonts.css +3 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/input/input.d.ts +13 -0
- package/dist/input/input.js +25 -0
- package/dist/layout/app-shell.d.ts +100 -0
- package/dist/layout/app-shell.js +433 -0
- package/dist/layout/page.d.ts +20 -0
- package/dist/layout/page.js +53 -0
- package/dist/layout/record.d.ts +39 -0
- package/dist/layout/record.js +79 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/cn.js +18 -0
- package/dist/lib/control.js +14 -0
- package/dist/lib/popup.js +20 -0
- package/dist/menu/menu.d.ts +45 -0
- package/dist/menu/menu.js +85 -0
- package/dist/popover/popover.d.ts +22 -0
- package/dist/popover/popover.js +39 -0
- package/dist/radio/radio.d.ts +12 -0
- package/dist/radio/radio.js +25 -0
- package/dist/select/select.d.ts +23 -0
- package/dist/select/select.js +66 -0
- package/dist/separator/separator.d.ts +6 -0
- package/dist/separator/separator.js +14 -0
- package/dist/stat/stat.d.ts +28 -0
- package/dist/stat/stat.js +55 -0
- package/dist/state/states.d.ts +36 -0
- package/dist/state/states.js +108 -0
- package/dist/styles.css +42 -0
- package/dist/switch/switch.d.ts +9 -0
- package/dist/switch/switch.js +18 -0
- package/dist/table/table.d.ts +28 -0
- package/dist/table/table.js +72 -0
- package/dist/tabs/tabs.d.ts +26 -0
- package/dist/tabs/tabs.js +45 -0
- package/dist/tooltip/tooltip.d.ts +17 -0
- package/dist/tooltip/tooltip.js +27 -0
- package/package.json +57 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the sidebar is showing as the icon rail. Use it for your own header and footer content,
|
|
5
|
+
* e.g. to show a logo mark instead of the full name. Always false in the navigation drawer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSidebarCollapsed(): boolean;
|
|
8
|
+
export interface AppShellProps {
|
|
9
|
+
/** The navigation, built from Sidebar parts. Shown as a column from 1024px, a drawer below. */
|
|
10
|
+
sidebar: ReactNode;
|
|
11
|
+
/** The current page. Pages set the top bar with `PageBar`. */
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/** Name of the navigation drawer for screen readers. */
|
|
14
|
+
navLabel?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Adds a top-bar button that collapses the sidebar column to a rail of icons. Give every
|
|
17
|
+
* top-level `SidebarLink` and `SidebarSubmenu` an icon.
|
|
18
|
+
*/
|
|
19
|
+
sidebarCollapsible?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Lets the user drag the sidebar column's edge (or use the arrow keys on it) to set its width.
|
|
22
|
+
* Pass limits in px to change the default 200–400.
|
|
23
|
+
*/
|
|
24
|
+
sidebarResizable?: boolean | {
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
};
|
|
28
|
+
/** A localStorage key: the user's width and collapsed choice are kept there for that browser. */
|
|
29
|
+
sidebarStorageKey?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The app frame: sidebar on the canvas, the page in an inset panel with a slim top bar.
|
|
33
|
+
* Includes a "Skip to content" link and a menu button that opens the sidebar on small screens.
|
|
34
|
+
*/
|
|
35
|
+
export declare function AppShell({ sidebar, children, navLabel, sidebarCollapsible, sidebarResizable, sidebarStorageKey }: AppShellProps): import("react").JSX.Element;
|
|
36
|
+
export interface PageBarProps {
|
|
37
|
+
/** The page name. Rendered as the page's h1 unless `as` says otherwise. */
|
|
38
|
+
title: ReactNode;
|
|
39
|
+
/** Where the page sits, e.g. a link back to "Farmers" before a farmer's name. */
|
|
40
|
+
breadcrumb?: ReactNode;
|
|
41
|
+
/** Page actions; the main one last, e.g. Export then "Register farmer". */
|
|
42
|
+
actions?: ReactNode;
|
|
43
|
+
as?: 'h1' | 'h2';
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets the AppShell top bar for the current page: title on the left, actions on the right.
|
|
47
|
+
* Render it once per page, anywhere inside the page. Outside an AppShell it renders in place.
|
|
48
|
+
*/
|
|
49
|
+
export declare function PageBar({ title, breadcrumb, actions, as: Heading }: PageBarProps): import("react").JSX.Element | null;
|
|
50
|
+
type DivProps = HTMLAttributes<HTMLDivElement>;
|
|
51
|
+
/** The sidebar column: SidebarHeader, SidebarNav and SidebarFooter go inside. */
|
|
52
|
+
export declare function Sidebar({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
53
|
+
/** Top of the sidebar: workspace name, logo, search button. */
|
|
54
|
+
export declare function SidebarHeader({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
55
|
+
export interface SidebarNavProps extends HTMLAttributes<HTMLElement> {
|
|
56
|
+
'aria-label'?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function SidebarNav({ className, 'aria-label': label, ...props }: SidebarNavProps): import("react").JSX.Element;
|
|
59
|
+
export interface SidebarSectionProps extends DivProps {
|
|
60
|
+
label?: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
/** A group of links with an optional small heading, e.g. "Operations". */
|
|
63
|
+
export declare function SidebarSection({ label, className, children, ...props }: SidebarSectionProps): import("react").JSX.Element;
|
|
64
|
+
export interface SidebarLinkProps extends useRender.ComponentProps<'a'> {
|
|
65
|
+
/** A 16px line icon. */
|
|
66
|
+
icon?: ReactNode;
|
|
67
|
+
/** The current page; sets `aria-current="page"`. */
|
|
68
|
+
active?: boolean;
|
|
69
|
+
/** A small count or status on the right, e.g. pending reviews. */
|
|
70
|
+
count?: ReactNode;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A navigation link. Pass `href`, or `render={<Link to="/farmers" />}` for your router.
|
|
74
|
+
* Closes the navigation drawer on small screens when followed.
|
|
75
|
+
*/
|
|
76
|
+
export declare function SidebarLink({ icon, active, count, render, className, children, ...props }: SidebarLinkProps): import("react").JSX.Element;
|
|
77
|
+
export interface SidebarSubmenuProps {
|
|
78
|
+
/** The row's name, e.g. "Call centre". */
|
|
79
|
+
label: ReactNode;
|
|
80
|
+
/** A 16px line icon. */
|
|
81
|
+
icon?: ReactNode;
|
|
82
|
+
/**
|
|
83
|
+
* The current page is one of its links. It opens when this becomes true, and while closed its
|
|
84
|
+
* row is marked so the user can still see where they are.
|
|
85
|
+
*/
|
|
86
|
+
active?: boolean;
|
|
87
|
+
/** Open on first render. Defaults to `active`. */
|
|
88
|
+
defaultOpen?: boolean;
|
|
89
|
+
/** `SidebarLink`s, usually without icons. */
|
|
90
|
+
children: ReactNode;
|
|
91
|
+
className?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A row that shows and hides related links, so a long sidebar stays short. Opens by itself when
|
|
95
|
+
* the user navigates to one of its links; the user can close it again.
|
|
96
|
+
*/
|
|
97
|
+
export declare function SidebarSubmenu({ label, icon, active, defaultOpen, children, className }: SidebarSubmenuProps): import("react").JSX.Element;
|
|
98
|
+
/** Bottom of the sidebar: settings link, signed-in user. */
|
|
99
|
+
export declare function SidebarFooter({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { IconButton } from "../button/icon-button.js";
|
|
2
|
+
import { overlayBackdrop } from "../dialog/dialog.js";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { popupSurface } from "../lib/popup.js";
|
|
5
|
+
import { Tooltip as Tooltip$1 } from "../tooltip/tooltip.js";
|
|
6
|
+
import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { Tooltip } from "@base-ui/react/tooltip";
|
|
9
|
+
import { ChevronRight, Menu, PanelLeftClose, PanelLeftOpen } from "lucide-react";
|
|
10
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
11
|
+
import { Popover } from "@base-ui/react/popover";
|
|
12
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
13
|
+
import { mergeProps } from "@base-ui/react/merge-props";
|
|
14
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
15
|
+
import { createPortal } from "react-dom";
|
|
16
|
+
// src/layout/app-shell.tsx
|
|
17
|
+
const ShellContext = createContext(null);
|
|
18
|
+
/** True inside the sidebar column while it is collapsed to the icon rail. */
|
|
19
|
+
const SidebarCollapsedContext = createContext(false);
|
|
20
|
+
/**
|
|
21
|
+
* Whether the sidebar is showing as the icon rail. Use it for your own header and footer content,
|
|
22
|
+
* e.g. to show a logo mark instead of the full name. Always false in the navigation drawer.
|
|
23
|
+
*/
|
|
24
|
+
function useSidebarCollapsed() {
|
|
25
|
+
return useContext(SidebarCollapsedContext);
|
|
26
|
+
}
|
|
27
|
+
const SIDEBAR_RAIL = 56;
|
|
28
|
+
const SIDEBAR_DEFAULT = 240;
|
|
29
|
+
const SIDEBAR_STEP = 16;
|
|
30
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
31
|
+
function readSidebarSize(key, min, max) {
|
|
32
|
+
const size = {
|
|
33
|
+
width: clamp(SIDEBAR_DEFAULT, min, max),
|
|
34
|
+
collapsed: false
|
|
35
|
+
};
|
|
36
|
+
if (!key || typeof window === "undefined") return size;
|
|
37
|
+
try {
|
|
38
|
+
const stored = JSON.parse(window.localStorage.getItem(key) ?? "null");
|
|
39
|
+
if (stored && typeof stored === "object") {
|
|
40
|
+
const { width, collapsed } = stored;
|
|
41
|
+
if (typeof width === "number" && Number.isFinite(width)) size.width = clamp(width, min, max);
|
|
42
|
+
if (typeof collapsed === "boolean") size.collapsed = collapsed;
|
|
43
|
+
}
|
|
44
|
+
} catch {}
|
|
45
|
+
return size;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The app frame: sidebar on the canvas, the page in an inset panel with a slim top bar.
|
|
49
|
+
* Includes a "Skip to content" link and a menu button that opens the sidebar on small screens.
|
|
50
|
+
*/
|
|
51
|
+
function AppShell({ sidebar, children, navLabel = "Navigation", sidebarCollapsible = false, sidebarResizable = false, sidebarStorageKey }) {
|
|
52
|
+
const [barNode, setBarNode] = useState(null);
|
|
53
|
+
const [navOpen, setNavOpen] = useState(false);
|
|
54
|
+
const closeNav = useCallback(() => {
|
|
55
|
+
setNavOpen(false);
|
|
56
|
+
}, []);
|
|
57
|
+
const context = useMemo(() => ({
|
|
58
|
+
barNode,
|
|
59
|
+
closeNav
|
|
60
|
+
}), [barNode, closeNav]);
|
|
61
|
+
const limits = typeof sidebarResizable === "object" ? sidebarResizable : {};
|
|
62
|
+
const min = limits.min ?? 200;
|
|
63
|
+
const max = Math.max(min, limits.max ?? 400);
|
|
64
|
+
const [size, setSize] = useState(() => readSidebarSize(sidebarStorageKey, min, max));
|
|
65
|
+
const [dragging, setDragging] = useState(false);
|
|
66
|
+
const columnId = useId();
|
|
67
|
+
const columnRef = useRef(null);
|
|
68
|
+
const collapsed = sidebarCollapsible && size.collapsed;
|
|
69
|
+
const width = collapsed ? SIDEBAR_RAIL : clamp(size.width, min, max);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!sidebarStorageKey || dragging) return;
|
|
72
|
+
try {
|
|
73
|
+
window.localStorage.setItem(sidebarStorageKey, JSON.stringify(size));
|
|
74
|
+
} catch {}
|
|
75
|
+
}, [
|
|
76
|
+
sidebarStorageKey,
|
|
77
|
+
size,
|
|
78
|
+
dragging
|
|
79
|
+
]);
|
|
80
|
+
const setWidth = (next) => {
|
|
81
|
+
setSize({
|
|
82
|
+
width: clamp(next, min, max),
|
|
83
|
+
collapsed: false
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const onHandlePointerDown = (event) => {
|
|
87
|
+
if (event.button !== 0) return;
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
90
|
+
setDragging(true);
|
|
91
|
+
};
|
|
92
|
+
const onHandlePointerMove = (event) => {
|
|
93
|
+
if (!dragging || !columnRef.current) return;
|
|
94
|
+
const next = event.clientX - columnRef.current.getBoundingClientRect().left;
|
|
95
|
+
if (sidebarCollapsible && next < (SIDEBAR_RAIL + min) / 2) setSize((current) => ({
|
|
96
|
+
...current,
|
|
97
|
+
collapsed: true
|
|
98
|
+
}));
|
|
99
|
+
else setWidth(next);
|
|
100
|
+
};
|
|
101
|
+
const onHandleKeyDown = (event) => {
|
|
102
|
+
if (event.key === "ArrowLeft") {
|
|
103
|
+
if (collapsed) return;
|
|
104
|
+
if (sidebarCollapsible && width <= min) setSize({
|
|
105
|
+
...size,
|
|
106
|
+
collapsed: true
|
|
107
|
+
});
|
|
108
|
+
else setWidth(width - SIDEBAR_STEP);
|
|
109
|
+
} else if (event.key === "ArrowRight") setWidth(collapsed ? size.width : width + SIDEBAR_STEP);
|
|
110
|
+
else if (event.key === "Home") setWidth(min);
|
|
111
|
+
else if (event.key === "End") setWidth(max);
|
|
112
|
+
else if (event.key === "Enter" && sidebarCollapsible) setSize({
|
|
113
|
+
...size,
|
|
114
|
+
collapsed: !collapsed
|
|
115
|
+
});
|
|
116
|
+
else return;
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
};
|
|
119
|
+
return /* @__PURE__ */ jsx(ShellContext.Provider, {
|
|
120
|
+
value: context,
|
|
121
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
122
|
+
className: cn("flex h-dvh bg-bg text-fg", dragging && "cursor-col-resize select-none"),
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsx("a", {
|
|
125
|
+
href: "#main",
|
|
126
|
+
className: "sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-(--z-tooltip) focus:rounded-md focus:bg-surface focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-md",
|
|
127
|
+
children: "Skip to content"
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsxs("div", {
|
|
130
|
+
ref: columnRef,
|
|
131
|
+
id: columnId,
|
|
132
|
+
style: { width },
|
|
133
|
+
className: cn("relative hidden shrink-0 lg:flex", !dragging && "transition-[width] duration-normal ease-standard motion-reduce:transition-none"),
|
|
134
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
135
|
+
className: "flex min-w-0 flex-1 overflow-hidden",
|
|
136
|
+
children: /* @__PURE__ */ jsx(SidebarCollapsedContext.Provider, {
|
|
137
|
+
value: collapsed,
|
|
138
|
+
children: sidebar
|
|
139
|
+
})
|
|
140
|
+
}), sidebarResizable && /* @__PURE__ */ jsx("div", {
|
|
141
|
+
role: "slider",
|
|
142
|
+
"aria-label": `${navLabel} width`,
|
|
143
|
+
"aria-valuetext": collapsed ? "Collapsed" : `${String(width)} pixels`,
|
|
144
|
+
"aria-controls": columnId,
|
|
145
|
+
"aria-valuenow": width,
|
|
146
|
+
"aria-valuemin": sidebarCollapsible ? SIDEBAR_RAIL : min,
|
|
147
|
+
"aria-valuemax": max,
|
|
148
|
+
tabIndex: 0,
|
|
149
|
+
"data-dragging": dragging ? "" : void 0,
|
|
150
|
+
onPointerDown: onHandlePointerDown,
|
|
151
|
+
onPointerMove: onHandlePointerMove,
|
|
152
|
+
onPointerUp: () => {
|
|
153
|
+
setDragging(false);
|
|
154
|
+
},
|
|
155
|
+
onPointerCancel: () => {
|
|
156
|
+
setDragging(false);
|
|
157
|
+
},
|
|
158
|
+
onDoubleClick: () => {
|
|
159
|
+
setWidth(SIDEBAR_DEFAULT);
|
|
160
|
+
},
|
|
161
|
+
onKeyDown: onHandleKeyDown,
|
|
162
|
+
className: cn("absolute inset-y-0 -right-1 z-1 w-2 cursor-col-resize touch-none outline-none", "after:absolute after:inset-y-4 after:left-1/2 after:w-0.5 after:-translate-x-1/2 after:rounded-full after:transition-colors after:duration-fast", "hover:after:bg-border-input focus-visible:after:bg-focus data-dragging:after:bg-focus")
|
|
163
|
+
})]
|
|
164
|
+
}),
|
|
165
|
+
/* @__PURE__ */ jsx(Dialog.Root, {
|
|
166
|
+
open: navOpen,
|
|
167
|
+
onOpenChange: setNavOpen,
|
|
168
|
+
children: /* @__PURE__ */ jsxs(Dialog.Portal, { children: [/* @__PURE__ */ jsx(Dialog.Backdrop, { className: cn(overlayBackdrop, "lg:hidden") }), /* @__PURE__ */ jsxs(Dialog.Popup, {
|
|
169
|
+
className: cn("fixed inset-y-0 left-0 z-(--z-modal) flex w-72 max-w-[85vw] bg-bg text-fg shadow-lg outline-none", "transition-transform duration-normal ease-standard", "data-starting-style:-translate-x-full data-ending-style:-translate-x-full lg:hidden"),
|
|
170
|
+
children: [/* @__PURE__ */ jsx(Dialog.Title, {
|
|
171
|
+
className: "sr-only",
|
|
172
|
+
children: navLabel
|
|
173
|
+
}), sidebar]
|
|
174
|
+
})] })
|
|
175
|
+
}),
|
|
176
|
+
/* @__PURE__ */ jsx("div", {
|
|
177
|
+
className: "flex min-w-0 flex-1 flex-col lg:py-2 lg:pr-2",
|
|
178
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
179
|
+
className: "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface lg:rounded-xl lg:border lg:border-border lg:shadow-xs",
|
|
180
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
181
|
+
className: "flex h-12 shrink-0 items-center gap-2 border-b border-border px-3 pointer-coarse:h-14 lg:px-5",
|
|
182
|
+
children: [
|
|
183
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
184
|
+
label: "Open navigation",
|
|
185
|
+
tooltip: false,
|
|
186
|
+
size: "sm",
|
|
187
|
+
className: "-ml-1 lg:hidden",
|
|
188
|
+
onClick: () => {
|
|
189
|
+
setNavOpen(true);
|
|
190
|
+
},
|
|
191
|
+
children: /* @__PURE__ */ jsx(Menu, {})
|
|
192
|
+
}),
|
|
193
|
+
sidebarCollapsible && /* @__PURE__ */ jsx(IconButton, {
|
|
194
|
+
label: collapsed ? `Expand ${navLabel.toLowerCase()}` : `Collapse ${navLabel.toLowerCase()}`,
|
|
195
|
+
size: "sm",
|
|
196
|
+
className: "-ml-2 hidden text-fg-muted lg:inline-flex",
|
|
197
|
+
"aria-controls": columnId,
|
|
198
|
+
"aria-expanded": !collapsed,
|
|
199
|
+
onClick: () => {
|
|
200
|
+
setSize({
|
|
201
|
+
...size,
|
|
202
|
+
collapsed: !collapsed
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
children: collapsed ? /* @__PURE__ */ jsx(PanelLeftOpen, {}) : /* @__PURE__ */ jsx(PanelLeftClose, {})
|
|
206
|
+
}),
|
|
207
|
+
/* @__PURE__ */ jsx("div", {
|
|
208
|
+
ref: setBarNode,
|
|
209
|
+
className: "flex min-w-0 flex-1 items-center gap-2"
|
|
210
|
+
})
|
|
211
|
+
]
|
|
212
|
+
}), /* @__PURE__ */ jsx("main", {
|
|
213
|
+
id: "main",
|
|
214
|
+
tabIndex: -1,
|
|
215
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto focus:outline-hidden",
|
|
216
|
+
children
|
|
217
|
+
})]
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Sets the AppShell top bar for the current page: title on the left, actions on the right.
|
|
226
|
+
* Render it once per page, anywhere inside the page. Outside an AppShell it renders in place.
|
|
227
|
+
*/
|
|
228
|
+
function PageBar({ title, breadcrumb, actions, as: Heading = "h1" }) {
|
|
229
|
+
const shell = useContext(ShellContext);
|
|
230
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
231
|
+
breadcrumb && /* @__PURE__ */ jsxs("div", {
|
|
232
|
+
className: "hidden min-w-0 items-center gap-2 text-sm text-fg-muted sm:flex",
|
|
233
|
+
children: [breadcrumb, /* @__PURE__ */ jsx("span", {
|
|
234
|
+
"aria-hidden": true,
|
|
235
|
+
children: "/"
|
|
236
|
+
})]
|
|
237
|
+
}),
|
|
238
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
239
|
+
className: "min-w-0 truncate text-sm font-medium",
|
|
240
|
+
children: title
|
|
241
|
+
}),
|
|
242
|
+
actions && /* @__PURE__ */ jsx("div", {
|
|
243
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
244
|
+
children: actions
|
|
245
|
+
})
|
|
246
|
+
] });
|
|
247
|
+
if (!shell) return /* @__PURE__ */ jsx("div", {
|
|
248
|
+
className: "flex h-12 items-center gap-2 border-b border-border px-4",
|
|
249
|
+
children: content
|
|
250
|
+
});
|
|
251
|
+
return shell.barNode ? createPortal(content, shell.barNode) : null;
|
|
252
|
+
}
|
|
253
|
+
/** The sidebar column: SidebarHeader, SidebarNav and SidebarFooter go inside. */
|
|
254
|
+
function Sidebar({ className, ...props }) {
|
|
255
|
+
const collapsed = useSidebarCollapsed();
|
|
256
|
+
return /* @__PURE__ */ jsx("div", {
|
|
257
|
+
"data-collapsed": collapsed ? "" : void 0,
|
|
258
|
+
className: cn("flex h-full w-full flex-col gap-3 px-3 pt-3 pb-2 data-collapsed:px-1.5", className),
|
|
259
|
+
...props
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** Top of the sidebar: workspace name, logo, search button. */
|
|
263
|
+
function SidebarHeader({ className, ...props }) {
|
|
264
|
+
return /* @__PURE__ */ jsx("div", {
|
|
265
|
+
className: cn("flex flex-col gap-3", className),
|
|
266
|
+
...props
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function SidebarNav({ className, "aria-label": label = "Main", ...props }) {
|
|
270
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
271
|
+
"aria-label": label,
|
|
272
|
+
className: cn("-mx-1 flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-1", className),
|
|
273
|
+
...props
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/** A group of links with an optional small heading, e.g. "Operations". */
|
|
277
|
+
function SidebarSection({ label, className, children, ...props }) {
|
|
278
|
+
const collapsed = useSidebarCollapsed();
|
|
279
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
280
|
+
className: cn("flex flex-col", className),
|
|
281
|
+
...props,
|
|
282
|
+
children: [label && (collapsed ? /* @__PURE__ */ jsx("p", {
|
|
283
|
+
className: "mx-auto mb-2 h-px w-6 bg-border",
|
|
284
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
285
|
+
className: "sr-only",
|
|
286
|
+
children: label
|
|
287
|
+
})
|
|
288
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
289
|
+
className: "mb-1 truncate px-2 text-xs font-medium text-fg-muted",
|
|
290
|
+
children: label
|
|
291
|
+
})), /* @__PURE__ */ jsx("div", {
|
|
292
|
+
className: "flex flex-col gap-0.5",
|
|
293
|
+
children
|
|
294
|
+
})]
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
const sidebarRow = cn("flex h-8 items-center gap-2.5 rounded-md border border-transparent px-2 text-sm font-medium text-fg-muted", "hover:bg-surface-hover hover:text-fg pointer-coarse:h-11", "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus", "[&_svg]:size-4 [&_svg]:shrink-0");
|
|
298
|
+
/** A row on the icon rail: a centred square showing only the icon. */
|
|
299
|
+
const sidebarRailRow = "mx-auto size-8 justify-center gap-0 px-0 pointer-coarse:size-11";
|
|
300
|
+
/** Stands in for a missing icon on the rail. */
|
|
301
|
+
function railInitial(label) {
|
|
302
|
+
return typeof label === "string" ? /* @__PURE__ */ jsx("span", {
|
|
303
|
+
"aria-hidden": true,
|
|
304
|
+
children: label.trim().charAt(0)
|
|
305
|
+
}) : null;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A navigation link. Pass `href`, or `render={<Link to="/farmers" />}` for your router.
|
|
309
|
+
* Closes the navigation drawer on small screens when followed.
|
|
310
|
+
*/
|
|
311
|
+
function SidebarLink({ icon, active = false, count, render, className, children, ...props }) {
|
|
312
|
+
const shell = useContext(ShellContext);
|
|
313
|
+
const collapsed = useSidebarCollapsed();
|
|
314
|
+
const link = useRender({
|
|
315
|
+
defaultTagName: "a",
|
|
316
|
+
render,
|
|
317
|
+
props: mergeProps({
|
|
318
|
+
"aria-current": active ? "page" : void 0,
|
|
319
|
+
onClick: () => shell?.closeNav(),
|
|
320
|
+
className: cn(sidebarRow, collapsed && sidebarRailRow, "aria-[current=page]:border-border aria-[current=page]:bg-surface aria-[current=page]:text-fg aria-[current=page]:shadow-xs", typeof className === "string" ? className : void 0),
|
|
321
|
+
children: collapsed ? /* @__PURE__ */ jsxs(Fragment, { children: [icon ?? railInitial(children), /* @__PURE__ */ jsx("span", {
|
|
322
|
+
className: "sr-only",
|
|
323
|
+
children
|
|
324
|
+
})] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
325
|
+
icon,
|
|
326
|
+
/* @__PURE__ */ jsx("span", {
|
|
327
|
+
className: "min-w-0 flex-1 truncate",
|
|
328
|
+
children
|
|
329
|
+
}),
|
|
330
|
+
count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
331
|
+
className: "text-xs font-medium text-fg-muted tabular-nums",
|
|
332
|
+
children: count
|
|
333
|
+
})
|
|
334
|
+
] })
|
|
335
|
+
}, props)
|
|
336
|
+
});
|
|
337
|
+
return collapsed ? /* @__PURE__ */ jsx(Tooltip$1, {
|
|
338
|
+
content: children,
|
|
339
|
+
side: "right",
|
|
340
|
+
children: link
|
|
341
|
+
}) : link;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* A row that shows and hides related links, so a long sidebar stays short. Opens by itself when
|
|
345
|
+
* the user navigates to one of its links; the user can close it again.
|
|
346
|
+
*/
|
|
347
|
+
function SidebarSubmenu({ label, icon, active = false, defaultOpen, children, className }) {
|
|
348
|
+
const [open, setOpen] = useState(defaultOpen ?? active);
|
|
349
|
+
const [wasActive, setWasActive] = useState(active);
|
|
350
|
+
if (active !== wasActive) {
|
|
351
|
+
setWasActive(active);
|
|
352
|
+
if (active) setOpen(true);
|
|
353
|
+
}
|
|
354
|
+
const collapsed = useSidebarCollapsed();
|
|
355
|
+
const [railOpen, setRailOpen] = useState(false);
|
|
356
|
+
if (collapsed) return /* @__PURE__ */ jsxs(Popover.Root, {
|
|
357
|
+
open: railOpen,
|
|
358
|
+
onOpenChange: setRailOpen,
|
|
359
|
+
children: [/* @__PURE__ */ jsxs(Tooltip.Root, {
|
|
360
|
+
disabled: railOpen,
|
|
361
|
+
children: [/* @__PURE__ */ jsxs(Tooltip.Trigger, {
|
|
362
|
+
render: /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
363
|
+
"data-current": active ? "" : void 0,
|
|
364
|
+
className: cn(sidebarRow, sidebarRailRow, "data-current:bg-surface-hover data-current:text-fg data-popup-open:bg-surface-hover data-popup-open:text-fg", className)
|
|
365
|
+
}),
|
|
366
|
+
children: [icon ?? railInitial(label), /* @__PURE__ */ jsx("span", {
|
|
367
|
+
className: "sr-only",
|
|
368
|
+
children: label
|
|
369
|
+
})]
|
|
370
|
+
}), /* @__PURE__ */ jsx(Tooltip.Portal, { children: /* @__PURE__ */ jsx(Tooltip.Positioner, {
|
|
371
|
+
side: "right",
|
|
372
|
+
sideOffset: 6,
|
|
373
|
+
className: "z-(--z-tooltip)",
|
|
374
|
+
children: /* @__PURE__ */ jsx(Tooltip.Popup, {
|
|
375
|
+
className: "rounded-md bg-primary px-2 py-1 text-xs font-medium text-on-primary shadow-md",
|
|
376
|
+
children: label
|
|
377
|
+
})
|
|
378
|
+
}) })]
|
|
379
|
+
}), /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
|
|
380
|
+
side: "right",
|
|
381
|
+
align: "start",
|
|
382
|
+
sideOffset: 10,
|
|
383
|
+
className: "z-(--z-popover)",
|
|
384
|
+
children: /* @__PURE__ */ jsxs(Popover.Popup, {
|
|
385
|
+
className: cn(popupSurface, "flex w-56 flex-col gap-0.5 p-1.5"),
|
|
386
|
+
onClick: (event) => {
|
|
387
|
+
if (event.target.closest("a")) setRailOpen(false);
|
|
388
|
+
},
|
|
389
|
+
children: [/* @__PURE__ */ jsx(Popover.Title, {
|
|
390
|
+
className: "px-2 py-1 text-xs font-medium text-fg-muted",
|
|
391
|
+
children: label
|
|
392
|
+
}), /* @__PURE__ */ jsx(SidebarCollapsedContext.Provider, {
|
|
393
|
+
value: false,
|
|
394
|
+
children
|
|
395
|
+
})]
|
|
396
|
+
})
|
|
397
|
+
}) })]
|
|
398
|
+
});
|
|
399
|
+
return /* @__PURE__ */ jsxs(Collapsible.Root, {
|
|
400
|
+
open,
|
|
401
|
+
onOpenChange: setOpen,
|
|
402
|
+
className: cn("flex flex-col", className),
|
|
403
|
+
children: [/* @__PURE__ */ jsxs(Collapsible.Trigger, {
|
|
404
|
+
"data-current": active && !open ? "" : void 0,
|
|
405
|
+
className: cn(sidebarRow, "group w-full text-left data-current:bg-surface-hover data-current:text-fg"),
|
|
406
|
+
children: [
|
|
407
|
+
icon,
|
|
408
|
+
/* @__PURE__ */ jsx("span", {
|
|
409
|
+
className: "min-w-0 flex-1 truncate",
|
|
410
|
+
children: label
|
|
411
|
+
}),
|
|
412
|
+
/* @__PURE__ */ jsx(ChevronRight, {
|
|
413
|
+
className: "text-fg-muted transition-transform duration-fast group-data-panel-open:rotate-90 motion-reduce:transition-none",
|
|
414
|
+
"aria-hidden": true
|
|
415
|
+
})
|
|
416
|
+
]
|
|
417
|
+
}), /* @__PURE__ */ jsx(Collapsible.Panel, {
|
|
418
|
+
className: "h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-normal ease-standard data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",
|
|
419
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
420
|
+
className: "ml-4 flex flex-col gap-0.5 border-l border-border py-0.5 pl-2",
|
|
421
|
+
children
|
|
422
|
+
})
|
|
423
|
+
})]
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/** Bottom of the sidebar: settings link, signed-in user. */
|
|
427
|
+
function SidebarFooter({ className, ...props }) {
|
|
428
|
+
return /* @__PURE__ */ jsx("div", {
|
|
429
|
+
className: cn("flex min-w-0 flex-col gap-0.5 border-t border-border pt-2", className),
|
|
430
|
+
...props
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
export { AppShell, PageBar, Sidebar, SidebarFooter, SidebarHeader, SidebarLink, SidebarNav, SidebarSection, SidebarSubmenu, useSidebarCollapsed };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VariantProps } from "class-variance-authority";
|
|
2
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
3
|
+
declare const page: (props?: ({
|
|
4
|
+
width?: "default" | "wide" | "full" | null | undefined;
|
|
5
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
|
+
export interface PageProps extends HTMLAttributes<HTMLDivElement>, VariantProps<typeof page> {}
|
|
7
|
+
/** The page body inside AppShell. Use `width="full"` for list pages with a table. */
|
|
8
|
+
export declare const Page: import("react").ForwardRefExoticComponent<PageProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export interface PageHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
10
|
+
title: ReactNode;
|
|
11
|
+
/** Small text above the title, e.g. today's date. */
|
|
12
|
+
eyebrow?: ReactNode;
|
|
13
|
+
description?: ReactNode;
|
|
14
|
+
actions?: ReactNode;
|
|
15
|
+
/** Defaults to h2 because the PageBar title is the page's h1. */
|
|
16
|
+
as?: 'h1' | 'h2';
|
|
17
|
+
}
|
|
18
|
+
/** A large heading block at the top of the page content (dashboards, settings sections). */
|
|
19
|
+
export declare const PageHeader: import("react").ForwardRefExoticComponent<PageHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/layout/page.tsx
|
|
6
|
+
const page = cva("w-full", {
|
|
7
|
+
variants: { width: {
|
|
8
|
+
/** Reading pages, dashboards, forms. */
|
|
9
|
+
default: "mx-auto flex max-w-6xl flex-col gap-6 px-4 py-6 lg:px-8 lg:py-8",
|
|
10
|
+
/** Record pages with a summary rail. */
|
|
11
|
+
wide: "mx-auto flex max-w-7xl flex-col gap-6 px-4 py-6 lg:px-8 lg:py-8",
|
|
12
|
+
/** Full-bleed lists: toolbars and a table that fills the remaining height. */
|
|
13
|
+
full: "flex min-h-0 flex-1 flex-col"
|
|
14
|
+
} },
|
|
15
|
+
defaultVariants: { width: "default" }
|
|
16
|
+
});
|
|
17
|
+
/** The page body inside AppShell. Use `width="full"` for list pages with a table. */
|
|
18
|
+
const Page = forwardRef(function Page({ className, width, ...props }, ref) {
|
|
19
|
+
return /* @__PURE__ */ jsx("div", {
|
|
20
|
+
ref,
|
|
21
|
+
className: cn(page({ width }), className),
|
|
22
|
+
...props
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
/** A large heading block at the top of the page content (dashboards, settings sections). */
|
|
26
|
+
const PageHeader = forwardRef(function PageHeader({ title, eyebrow, description, actions, as: Heading = "h2", className, ...props }, ref) {
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
ref,
|
|
29
|
+
className: cn("flex flex-wrap items-end justify-between gap-3", className),
|
|
30
|
+
...props,
|
|
31
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
32
|
+
className: "min-w-0",
|
|
33
|
+
children: [
|
|
34
|
+
eyebrow && /* @__PURE__ */ jsx("p", {
|
|
35
|
+
className: "text-sm text-fg-muted",
|
|
36
|
+
children: eyebrow
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
39
|
+
className: "mt-0.5 text-2xl font-semibold tracking-tight sm:text-3xl",
|
|
40
|
+
children: title
|
|
41
|
+
}),
|
|
42
|
+
description && /* @__PURE__ */ jsx("p", {
|
|
43
|
+
className: "mt-1 text-sm text-fg-muted",
|
|
44
|
+
children: description
|
|
45
|
+
})
|
|
46
|
+
]
|
|
47
|
+
}), actions && /* @__PURE__ */ jsx("div", {
|
|
48
|
+
className: "flex flex-wrap items-center gap-2",
|
|
49
|
+
children: actions
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
export { Page, PageHeader };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
export interface RecordLayoutProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
3
|
+
/** Identity, status and actions; usually a RecordHeader. */
|
|
4
|
+
header: ReactNode;
|
|
5
|
+
/** Key facts beside the content (right rail from 1024px, above the content on smaller screens). */
|
|
6
|
+
aside?: ReactNode;
|
|
7
|
+
/** Name of the aside region for screen readers. */
|
|
8
|
+
asideLabel?: string;
|
|
9
|
+
/** The record's sections, usually Tabs kept in the URL. */
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/** One layout for every record page (farmer, contract, partner): header, summary rail, tabs. */
|
|
13
|
+
export declare const RecordLayout: import("react").ForwardRefExoticComponent<RecordLayoutProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
14
|
+
export interface RecordHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
15
|
+
title: ReactNode;
|
|
16
|
+
/** An Avatar or icon. */
|
|
17
|
+
media?: ReactNode;
|
|
18
|
+
/** A Badge with the record's status. */
|
|
19
|
+
status?: ReactNode;
|
|
20
|
+
/** One line of context, e.g. "GGEM farmer · Chikwawa hub · Registered 4 Mar 2025". */
|
|
21
|
+
meta?: ReactNode;
|
|
22
|
+
/** The main action visible; the rest in an overflow menu. */
|
|
23
|
+
actions?: ReactNode;
|
|
24
|
+
/** Defaults to h2 because the PageBar title is the page's h1. */
|
|
25
|
+
as?: 'h1' | 'h2';
|
|
26
|
+
}
|
|
27
|
+
export declare const RecordHeader: import("react").ForwardRefExoticComponent<RecordHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
28
|
+
export interface DetailItem {
|
|
29
|
+
label: ReactNode;
|
|
30
|
+
/** Shown as "—" (read as "Not recorded") when null, undefined or an empty string. */
|
|
31
|
+
value?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
export interface DetailListProps extends HTMLAttributes<HTMLDListElement> {
|
|
34
|
+
items: readonly DetailItem[];
|
|
35
|
+
/** Two columns from 640px. */
|
|
36
|
+
columns?: 1 | 2;
|
|
37
|
+
}
|
|
38
|
+
/** Label/value pairs for record details. Never shows raw IDs or true/false: format values first. */
|
|
39
|
+
export declare const DetailList: import("react").ForwardRefExoticComponent<DetailListProps & import("react").RefAttributes<HTMLDListElement>>;
|