@syscore/ui-library 2.0.0-beta-publish-workflow-beta.11 → 2.0.0-beta-publish-workflow-beta.13
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/client/components/ui/alert.tsx +4 -0
- package/client/components/ui/button.tsx +8 -0
- package/client/components/ui/card.tsx +43 -3
- package/client/components/ui/copy.tsx +1 -1
- package/client/components/ui/data-grid.tsx +258 -0
- package/client/components/ui/dialog.tsx +35 -8
- package/client/components/ui/layout.tsx +11 -12
- package/client/components/ui/side-nav.tsx +162 -8
- package/client/components/ui/typography.tsx +11 -0
- package/client/global.css +398 -27
- package/client/ui/Button.stories.tsx +26 -0
- package/client/ui/DataGrid.stories.tsx +114 -0
- package/client/ui/SideNav.stories.tsx +39 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +24 -0
- package/dist/index.es.js +358 -46
- package/package.json +3 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
|
+
import { ChevronDown } from "lucide-react";
|
|
3
4
|
|
|
4
5
|
import { cn } from "@/lib/utils";
|
|
5
6
|
|
|
@@ -15,6 +16,11 @@ import { cn } from "@/lib/utils";
|
|
|
15
16
|
*
|
|
16
17
|
* `collapsed` hides group labels and item text and centres the icons. A collapsed item
|
|
17
18
|
* keeps its text as a `title` tooltip and an accessible name.
|
|
19
|
+
*
|
|
20
|
+
* Long menus fold: give a group `collapsible` (its label becomes a button with a chevron) and
|
|
21
|
+
* nest sub-pages under a `SideNavBranch`. Both open and close themselves, or are controlled with
|
|
22
|
+
* `open` / `onOpenChange`. In the collapsed rail every group is shown open and a branch shows
|
|
23
|
+
* only its icon (its `onClick` can take the user to the first sub-page).
|
|
18
24
|
*/
|
|
19
25
|
|
|
20
26
|
interface SideNavContextValue {
|
|
@@ -46,14 +52,74 @@ const SideNav = React.forwardRef<HTMLElement, SideNavProps>(
|
|
|
46
52
|
);
|
|
47
53
|
SideNav.displayName = "SideNav";
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
/** Open state that the parent can control (`open` + `onOpenChange`) or leave to the component. */
|
|
56
|
+
function useDisclosure(
|
|
57
|
+
open: boolean | undefined,
|
|
58
|
+
defaultOpen: boolean,
|
|
59
|
+
onOpenChange?: (open: boolean) => void,
|
|
60
|
+
) {
|
|
61
|
+
const [inner, setInner] = React.useState(defaultOpen);
|
|
62
|
+
const isOpen = open ?? inner;
|
|
63
|
+
const setOpen = (next: boolean) => {
|
|
64
|
+
if (open === undefined) setInner(next);
|
|
65
|
+
onOpenChange?.(next);
|
|
66
|
+
};
|
|
67
|
+
return [isOpen, setOpen] as const;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface SideNavGroupProps
|
|
71
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
50
72
|
/** Group heading, shown above the items (hidden when the nav is collapsed). */
|
|
51
73
|
label?: React.ReactNode;
|
|
74
|
+
/** Fold the group: the heading becomes a button that shows or hides its items. */
|
|
75
|
+
collapsible?: boolean;
|
|
76
|
+
/** Controlled open state (with `collapsible`). */
|
|
77
|
+
open?: boolean;
|
|
78
|
+
/** Initial open state when not controlled. Default `true`. */
|
|
79
|
+
defaultOpen?: boolean;
|
|
80
|
+
onOpenChange?: (open: boolean) => void;
|
|
52
81
|
}
|
|
53
82
|
|
|
54
83
|
const SideNavGroup = React.forwardRef<HTMLDivElement, SideNavGroupProps>(
|
|
55
|
-
(
|
|
84
|
+
(
|
|
85
|
+
{
|
|
86
|
+
className,
|
|
87
|
+
label,
|
|
88
|
+
collapsible = false,
|
|
89
|
+
open,
|
|
90
|
+
defaultOpen = true,
|
|
91
|
+
onOpenChange,
|
|
92
|
+
children,
|
|
93
|
+
...props
|
|
94
|
+
},
|
|
95
|
+
ref,
|
|
96
|
+
) => {
|
|
97
|
+
const { collapsed } = React.useContext(SideNavContext);
|
|
56
98
|
const headingId = React.useId();
|
|
99
|
+
const itemsId = React.useId();
|
|
100
|
+
const [isOpen, setOpen] = useDisclosure(open, defaultOpen, onOpenChange);
|
|
101
|
+
|
|
102
|
+
if (!collapsible) {
|
|
103
|
+
return (
|
|
104
|
+
<div
|
|
105
|
+
ref={ref}
|
|
106
|
+
role="group"
|
|
107
|
+
aria-labelledby={label ? headingId : undefined}
|
|
108
|
+
className={cn("side-nav__group", className)}
|
|
109
|
+
{...props}
|
|
110
|
+
>
|
|
111
|
+
{label ? (
|
|
112
|
+
<span id={headingId} className="side-nav__heading">
|
|
113
|
+
{label}
|
|
114
|
+
</span>
|
|
115
|
+
) : null}
|
|
116
|
+
{children}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// In the icon rail there is no heading to fold, so every item stays reachable.
|
|
122
|
+
const shown = collapsed || isOpen;
|
|
57
123
|
return (
|
|
58
124
|
<div
|
|
59
125
|
ref={ref}
|
|
@@ -63,11 +129,21 @@ const SideNavGroup = React.forwardRef<HTMLDivElement, SideNavGroupProps>(
|
|
|
63
129
|
{...props}
|
|
64
130
|
>
|
|
65
131
|
{label ? (
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
132
|
+
<button
|
|
133
|
+
type="button"
|
|
134
|
+
id={headingId}
|
|
135
|
+
className="side-nav__heading side-nav__heading--toggle"
|
|
136
|
+
aria-expanded={shown}
|
|
137
|
+
aria-controls={itemsId}
|
|
138
|
+
onClick={() => setOpen(!isOpen)}
|
|
139
|
+
>
|
|
140
|
+
<span>{label}</span>
|
|
141
|
+
<ChevronDown className="side-nav__chevron" aria-hidden="true" />
|
|
142
|
+
</button>
|
|
69
143
|
) : null}
|
|
70
|
-
{
|
|
144
|
+
<div id={itemsId} className="side-nav__items" hidden={!shown}>
|
|
145
|
+
{children}
|
|
146
|
+
</div>
|
|
71
147
|
</div>
|
|
72
148
|
);
|
|
73
149
|
},
|
|
@@ -122,5 +198,83 @@ const SideNavItem = React.forwardRef<HTMLButtonElement, SideNavItemProps>(
|
|
|
122
198
|
);
|
|
123
199
|
SideNavItem.displayName = "SideNavItem";
|
|
124
200
|
|
|
125
|
-
|
|
126
|
-
|
|
201
|
+
interface SideNavBranchProps
|
|
202
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "onClick"> {
|
|
203
|
+
/** Leading icon. */
|
|
204
|
+
icon?: React.ReactNode;
|
|
205
|
+
/** The branch's own text. Its sub-pages (`SideNavItem`s) go in `children`. */
|
|
206
|
+
label: string;
|
|
207
|
+
/** A sub-page is the current page: the branch is highlighted even while folded. */
|
|
208
|
+
active?: boolean;
|
|
209
|
+
/** Controlled open state. */
|
|
210
|
+
open?: boolean;
|
|
211
|
+
/** Initial open state when not controlled. Default `false`. */
|
|
212
|
+
defaultOpen?: boolean;
|
|
213
|
+
onOpenChange?: (open: boolean) => void;
|
|
214
|
+
/** Runs when the branch is pressed in the collapsed icon rail (where it cannot unfold). */
|
|
215
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** An item that unfolds into sub-pages (Users → Users, Roles, Permissions). */
|
|
219
|
+
const SideNavBranch = React.forwardRef<HTMLDivElement, SideNavBranchProps>(
|
|
220
|
+
(
|
|
221
|
+
{
|
|
222
|
+
className,
|
|
223
|
+
icon,
|
|
224
|
+
label,
|
|
225
|
+
active = false,
|
|
226
|
+
open,
|
|
227
|
+
defaultOpen = false,
|
|
228
|
+
onOpenChange,
|
|
229
|
+
onClick,
|
|
230
|
+
children,
|
|
231
|
+
...props
|
|
232
|
+
},
|
|
233
|
+
ref,
|
|
234
|
+
) => {
|
|
235
|
+
const { collapsed } = React.useContext(SideNavContext);
|
|
236
|
+
const subId = React.useId();
|
|
237
|
+
const [isOpen, setOpen] = useDisclosure(open, defaultOpen, onOpenChange);
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<div ref={ref} className={cn("side-nav__branch", className)} {...props}>
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
className={cn(
|
|
244
|
+
"side-nav__item",
|
|
245
|
+
"side-nav__item--branch",
|
|
246
|
+
active && "side-nav__item--branch-active",
|
|
247
|
+
)}
|
|
248
|
+
aria-expanded={collapsed ? undefined : isOpen}
|
|
249
|
+
aria-controls={subId}
|
|
250
|
+
aria-label={collapsed ? label : undefined}
|
|
251
|
+
title={collapsed ? label : undefined}
|
|
252
|
+
onClick={(event) => {
|
|
253
|
+
if (collapsed) onClick?.(event);
|
|
254
|
+
else setOpen(!isOpen);
|
|
255
|
+
}}
|
|
256
|
+
>
|
|
257
|
+
{icon ? (
|
|
258
|
+
<span className="side-nav__icon" aria-hidden="true">
|
|
259
|
+
{icon}
|
|
260
|
+
</span>
|
|
261
|
+
) : null}
|
|
262
|
+
<span className="side-nav__label">{label}</span>
|
|
263
|
+
<ChevronDown className="side-nav__chevron" aria-hidden="true" />
|
|
264
|
+
</button>
|
|
265
|
+
<div id={subId} className="side-nav__sub" hidden={collapsed || !isOpen}>
|
|
266
|
+
{children}
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
SideNavBranch.displayName = "SideNavBranch";
|
|
273
|
+
|
|
274
|
+
export { SideNav, SideNavGroup, SideNavItem, SideNavBranch };
|
|
275
|
+
export type {
|
|
276
|
+
SideNavProps,
|
|
277
|
+
SideNavGroupProps,
|
|
278
|
+
SideNavItemProps,
|
|
279
|
+
SideNavBranchProps,
|
|
280
|
+
};
|
|
@@ -49,6 +49,11 @@ const defaultElementMap: Record<Variant, React.ElementType> = {
|
|
|
49
49
|
interface TextProps extends React.HTMLAttributes<HTMLElement> {
|
|
50
50
|
variant?: Variant;
|
|
51
51
|
as?: React.ElementType;
|
|
52
|
+
/** Widens line-height beyond the DS variant's tight default — for a
|
|
53
|
+
* heading that wraps onto multiple lines (e.g. a page title in a narrow
|
|
54
|
+
* column) where the default reads cramped between the wrapped lines.
|
|
55
|
+
* Opt-in only; every existing `Text` keeps its variant's own line-height. */
|
|
56
|
+
loose?: boolean;
|
|
52
57
|
/** `muted` — quieter helper text (hints, secondary lines). Default inherits the surrounding colour. */
|
|
53
58
|
tone?: "default" | "muted";
|
|
54
59
|
/** `strong` — semibold, for a label inside running text. */
|
|
@@ -57,6 +62,8 @@ interface TextProps extends React.HTMLAttributes<HTMLElement> {
|
|
|
57
62
|
align?: "start" | "center";
|
|
58
63
|
/** `relaxed` — a 1.5 line height for short paragraphs that should breathe. */
|
|
59
64
|
leading?: "default" | "relaxed";
|
|
65
|
+
/** `sans` — set a heading in the body typeface (Mazzard) instead of the display serif. */
|
|
66
|
+
family?: "default" | "sans";
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
const Text = React.forwardRef<HTMLElement, TextProps>(
|
|
@@ -65,10 +72,12 @@ const Text = React.forwardRef<HTMLElement, TextProps>(
|
|
|
65
72
|
className,
|
|
66
73
|
variant = "body-base",
|
|
67
74
|
as,
|
|
75
|
+
loose = false,
|
|
68
76
|
tone = "default",
|
|
69
77
|
strong = false,
|
|
70
78
|
align,
|
|
71
79
|
leading = "default",
|
|
80
|
+
family = "default",
|
|
72
81
|
...props
|
|
73
82
|
},
|
|
74
83
|
ref,
|
|
@@ -80,10 +89,12 @@ const Text = React.forwardRef<HTMLElement, TextProps>(
|
|
|
80
89
|
ref={ref}
|
|
81
90
|
className={cn(
|
|
82
91
|
typographyVariants({ variant }),
|
|
92
|
+
loose && "typography--loose",
|
|
83
93
|
tone === "muted" && "typo--muted",
|
|
84
94
|
strong && "typo--strong",
|
|
85
95
|
align === "center" && "typo--center",
|
|
86
96
|
leading === "relaxed" && "typo--relaxed",
|
|
97
|
+
family === "sans" && "typo--sans",
|
|
87
98
|
className,
|
|
88
99
|
)}
|
|
89
100
|
{...props}
|