@platned/ui 0.9.5 → 0.9.7
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 +31 -0
- package/README.md +8 -0
- package/dist/{chunk-OGQIGGVB.js → chunk-O2Y4XUXQ.js} +2 -1
- package/dist/data-table.js +1 -1
- package/dist/index.cjs +1350 -661
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +288 -3
- package/dist/index.js +1159 -463
- package/dist/index.js.map +1 -1
- package/dist/sidebar.cjs +20 -1158
- package/dist/sidebar.cjs.map +1 -1
- package/dist/sidebar.d.cts +175 -105
- package/dist/sidebar.d.ts +175 -105
- package/dist/sidebar.js +18 -1170
- package/dist/sidebar.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- /package/dist/{chunk-OGQIGGVB.js.map → chunk-O2Y4XUXQ.js.map} +0 -0
package/dist/sidebar.d.cts
CHANGED
|
@@ -1,9 +1,173 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, HTMLAttributes } from 'react';
|
|
2
|
+
import { ReactNode, ComponentType, AnchorHTMLAttributes, RefAttributes, HTMLAttributes } from 'react';
|
|
3
3
|
import { RowData } from '@tanstack/react-table';
|
|
4
4
|
|
|
5
5
|
type NavItemSize = 'sm' | 'md';
|
|
6
6
|
type NavItemVariant = 'card' | 'plain';
|
|
7
|
+
/**
|
|
8
|
+
* The two Figma sidebar variants (Sidebar Navigation, node 3133:255). New in 0.9.6.
|
|
9
|
+
*
|
|
10
|
+
* `comfortable` is the card row: 44px, its own border and surface. `compact` is the plain
|
|
11
|
+
* row: 40px, text on the rail. Both use the 16px Body Base label and a 20px icon.
|
|
12
|
+
*/
|
|
13
|
+
type NavItemDensity = 'comfortable' | 'compact';
|
|
14
|
+
|
|
15
|
+
interface SidebarNavItem {
|
|
16
|
+
/** Stable key. Falls back to `to`, then `href`, then `label`. New in 0.9.6. */
|
|
17
|
+
id?: string;
|
|
18
|
+
/**
|
|
19
|
+
* An in-app destination, rendered through `linkComponent`. May carry a hash
|
|
20
|
+
* (`/docs/floating#tooltip`) to link to a section of a page: that row is current only when
|
|
21
|
+
* the hash matches too, and the page's own plain row steps aside while it is. Optional from
|
|
22
|
+
* 0.9.6, so a row can exist only to open its `children`.
|
|
23
|
+
*/
|
|
24
|
+
to?: string;
|
|
25
|
+
/**
|
|
26
|
+
* An external destination, opened in a new tab as a plain `<a>`. New in 0.9.6. Use `to`
|
|
27
|
+
* for anything inside the app.
|
|
28
|
+
*/
|
|
29
|
+
href?: string;
|
|
30
|
+
label: string;
|
|
31
|
+
/** Optional — a collapsed row without one falls back to a monogram of its label. */
|
|
32
|
+
icon?: ReactNode;
|
|
33
|
+
/** Red dot on the row — something new behind this destination. */
|
|
34
|
+
indicator?: boolean;
|
|
35
|
+
/** Match the path exactly rather than as a prefix. Needed for an index route. */
|
|
36
|
+
end?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A destination that exists but cannot be opened right now (coming soon). The row is
|
|
39
|
+
* dimmed, announced with `aria-disabled`, out of the tab order, and refuses the press.
|
|
40
|
+
* Something the user has no permission for should not be in the list at all: see
|
|
41
|
+
* `filterNav`.
|
|
42
|
+
*/
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Overrides route matching, for a row whose "current" rule is more than a path prefix —
|
|
46
|
+
* one page reached from two places, say. New in 0.9.6.
|
|
47
|
+
*/
|
|
48
|
+
isActive?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Child rows, one level deep. Expanded they open under the row; on the collapsed rail the
|
|
51
|
+
* row opens them as a flyout menu. New in 0.9.6.
|
|
52
|
+
*/
|
|
53
|
+
children?: SidebarNavItem[];
|
|
54
|
+
/** Whether the children start open. Default: open when one of them is the current route. */
|
|
55
|
+
defaultOpen?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface SidebarNavGroup {
|
|
58
|
+
/** Stable key. Falls back to `title`. New in 0.9.6. */
|
|
59
|
+
id?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Heading above the group. Omit for an ungrouped run of rows.
|
|
62
|
+
*
|
|
63
|
+
* Kept in the accessibility tree when the rail is collapsed rather than dropped: it is the
|
|
64
|
+
* only thing saying what the run of icons below it has in common.
|
|
65
|
+
*/
|
|
66
|
+
title?: string;
|
|
67
|
+
items: SidebarNavItem[];
|
|
68
|
+
/** Give the heading a chevron that folds the group away. Needs a `title`. New in 0.9.6. */
|
|
69
|
+
collapsible?: boolean;
|
|
70
|
+
/** With `collapsible`: whether the group starts open. Default `true`. */
|
|
71
|
+
defaultOpen?: boolean;
|
|
72
|
+
/** Trailing slot in the heading — an "add" icon button, say. New in 0.9.6. */
|
|
73
|
+
action?: ReactNode;
|
|
74
|
+
}
|
|
75
|
+
interface SidebarLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
76
|
+
href: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Renders an in-app row's link. It must forward its ref to the anchor — the collapsed rail
|
|
80
|
+
* anchors a tooltip to it and the flyout a menu item — as `next/link` and react-router's
|
|
81
|
+
* `Link` both do.
|
|
82
|
+
*/
|
|
83
|
+
type SidebarLinkComponent = ComponentType<SidebarLinkProps & RefAttributes<HTMLAnchorElement>>;
|
|
84
|
+
interface SidebarRenderState {
|
|
85
|
+
collapsed: boolean;
|
|
86
|
+
density: NavItemDensity;
|
|
87
|
+
}
|
|
88
|
+
interface SidebarProps {
|
|
89
|
+
/** The scrolling nav. One untitled group is a flat list. */
|
|
90
|
+
groups: SidebarNavGroup[];
|
|
91
|
+
/** Rows pinned below the scrolling nav — settings, help, a feedback link. */
|
|
92
|
+
footerNav?: SidebarNavItem[];
|
|
93
|
+
/**
|
|
94
|
+
* Brand lockup. Given a function it receives `collapsed` and `density`, so the caller can
|
|
95
|
+
* swap a full lockup for a mark alone rather than having one squeezed into the rail.
|
|
96
|
+
*/
|
|
97
|
+
brand?: ReactNode | ((state: SidebarRenderState) => ReactNode);
|
|
98
|
+
/** Bottom slot — a `SidebarUserCard`, a version pill, nothing. A function gets the state. */
|
|
99
|
+
footer?: ReactNode | ((state: SidebarRenderState) => ReactNode);
|
|
100
|
+
/**
|
|
101
|
+
* Figma's two sidebar variants. `comfortable` (default): 44px card rows, an 80px rail.
|
|
102
|
+
* `compact`: 40px plain rows, a 72px rail. New in 0.9.6.
|
|
103
|
+
*/
|
|
104
|
+
density?: NavItemDensity;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the rail can collapse at all. `false` locks it open: no toggle button, and
|
|
107
|
+
* `collapsed` is ignored rather than half honoured.
|
|
108
|
+
*/
|
|
109
|
+
collapsible?: boolean;
|
|
110
|
+
/** Controlled collapsed state. Omit for uncontrolled. */
|
|
111
|
+
collapsed?: boolean;
|
|
112
|
+
/** Initial collapsed state when uncontrolled. */
|
|
113
|
+
defaultCollapsed?: boolean;
|
|
114
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
115
|
+
/**
|
|
116
|
+
* Called by the collapse toggle. Kept from before 0.9.6, when `collapsed` was always
|
|
117
|
+
* controlled: passing `collapsed` with neither this nor `onCollapsedChange` still means
|
|
118
|
+
* "no toggle button".
|
|
119
|
+
*/
|
|
120
|
+
onToggle?: () => void;
|
|
121
|
+
/**
|
|
122
|
+
* localStorage key the collapsed state is remembered under, so it survives a reload.
|
|
123
|
+
* Read after mount, so server and client render the same first frame. New in 0.9.6.
|
|
124
|
+
*/
|
|
125
|
+
storageKey?: string;
|
|
126
|
+
/** The current pathname, which decides the current row. New in 0.9.6. */
|
|
127
|
+
currentPath?: string;
|
|
128
|
+
/** The current hash, for rows that link to a section (`#tooltip`). */
|
|
129
|
+
currentHash?: string;
|
|
130
|
+
/** Renders in-app links. Default a plain `<a>`; pass `next/link` or a router link. */
|
|
131
|
+
linkComponent?: SidebarLinkComponent;
|
|
132
|
+
/** Called when a row is pressed — after the mobile drawer has closed itself. */
|
|
133
|
+
onNavigate?: () => void;
|
|
134
|
+
/** Accessible name of the sidebar landmark. Default "Primary". */
|
|
135
|
+
label?: string;
|
|
136
|
+
/** @deprecated Use `density`. `plain` maps to `compact`; `size` is ignored. */
|
|
137
|
+
size?: NavItemSize;
|
|
138
|
+
/** @deprecated Use `density`. `plain` maps to `compact`, `card` to `comfortable`. */
|
|
139
|
+
variant?: NavItemVariant;
|
|
140
|
+
/** Expanded width, as a Tailwind class. Default `w-80` (320px). */
|
|
141
|
+
width?: string;
|
|
142
|
+
/** Collapsed width. Default `w-20` (80px) comfortable, `w-[72px]` compact. */
|
|
143
|
+
collapsedWidth?: string;
|
|
144
|
+
className?: string;
|
|
145
|
+
}
|
|
146
|
+
type SidebarSeparatorProps = HTMLAttributes<HTMLDivElement>;
|
|
147
|
+
/**
|
|
148
|
+
* A rule for the sidebar's `footer` slot or a hand-composed rail. The sidebar itself no
|
|
149
|
+
* longer draws one between groups from 0.9.6 — the Figma frames separate groups by space.
|
|
150
|
+
*
|
|
151
|
+
* Decorative by default. Pass `role="separator"` through where it marks a grouping nothing
|
|
152
|
+
* else names.
|
|
153
|
+
*/
|
|
154
|
+
declare function SidebarSeparator({ className, ...rest }: SidebarSeparatorProps): react.JSX.Element;
|
|
155
|
+
interface SidebarUserCardProps {
|
|
156
|
+
name: string;
|
|
157
|
+
role: string;
|
|
158
|
+
onLogout: () => void;
|
|
159
|
+
collapsed?: boolean;
|
|
160
|
+
/** Extra menu entries above Sign out. */
|
|
161
|
+
menu?: ReactNode;
|
|
162
|
+
className?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The signed-in user block, for the sidebar's `footer` slot — Figma `UserCard` (node
|
|
166
|
+
* 3123:156). On the main entry from 0.9.6; `@platned/ui/sidebar` still exports it.
|
|
167
|
+
*
|
|
168
|
+
* Its menu is `DropdownMenu`, which portals, so the collapsed rail does not clip it.
|
|
169
|
+
*/
|
|
170
|
+
declare function SidebarUserCard({ name, role, onLogout, collapsed, menu, className, }: SidebarUserCardProps): react.JSX.Element;
|
|
7
171
|
|
|
8
172
|
/** How a column appears in card mode. */
|
|
9
173
|
type ColumnMobileRole = 'title' | 'status' | 'actions' | 'field' | 'hidden';
|
|
@@ -68,120 +232,26 @@ interface NavTabsProps {
|
|
|
68
232
|
* Figma specifies for a tab rule, rather than the lighter `brand` border token. */
|
|
69
233
|
declare function NavTabs({ items, className }: NavTabsProps): react.JSX.Element;
|
|
70
234
|
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The destination. May carry a hash (`/docs/floating#tooltip`) to link to a section of a
|
|
74
|
-
* page: that row is current only when the hash matches too, and the page's own plain row
|
|
75
|
-
* steps aside while it is. New in 0.7.0.
|
|
76
|
-
*/
|
|
77
|
-
to: string;
|
|
78
|
-
label: string;
|
|
79
|
-
/** Optional — a collapsed row without one falls back to a monogram of its label. */
|
|
80
|
-
icon?: ReactNode;
|
|
81
|
-
/** Red dot on the row — something new behind this destination. */
|
|
82
|
-
indicator?: boolean;
|
|
83
|
-
/** Match the path exactly rather than as a prefix. Needed for an index route. */
|
|
84
|
-
end?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* A destination that exists but cannot be opened right now (no permission, coming soon).
|
|
87
|
-
* The row is dimmed, announced with `aria-disabled`, out of the tab order, and refuses the
|
|
88
|
-
* press. New in 0.7.0.
|
|
89
|
-
*/
|
|
90
|
-
disabled?: boolean;
|
|
91
|
-
}
|
|
92
|
-
interface SidebarNavGroup {
|
|
93
|
-
/**
|
|
94
|
-
* Uppercase heading above the group. Omit for an ungrouped run of rows.
|
|
95
|
-
*
|
|
96
|
-
* Kept in the accessibility tree when the rail is collapsed rather than dropped: it is the
|
|
97
|
-
* only thing saying what the run of icons below it has in common.
|
|
98
|
-
*/
|
|
99
|
-
title?: string;
|
|
100
|
-
items: SidebarNavItem[];
|
|
101
|
-
}
|
|
102
|
-
interface AppSidebarProps {
|
|
103
|
-
/** The scrolling nav. One untitled group is a flat list. */
|
|
104
|
-
groups: SidebarNavGroup[];
|
|
105
|
-
/** Rows pinned below the scrolling nav — settings, help, a sign-out link. */
|
|
106
|
-
footerNav?: SidebarNavItem[];
|
|
107
|
-
/**
|
|
108
|
-
* Brand lockup. Given a function it receives `collapsed`, so the caller can swap a full
|
|
109
|
-
* lockup for a mark alone rather than having one squeezed into an 80px rail.
|
|
110
|
-
*/
|
|
111
|
-
brand?: ReactNode | ((state: {
|
|
112
|
-
collapsed: boolean;
|
|
113
|
-
}) => ReactNode);
|
|
114
|
-
/** Bottom slot, below a divider — a user card, a version pill, nothing. */
|
|
115
|
-
footer?: ReactNode;
|
|
116
|
-
/**
|
|
117
|
-
* Whether the rail can collapse at all.
|
|
118
|
-
*
|
|
119
|
-
* `false` locks it open: no toggle button, and `collapsed` is ignored rather than half
|
|
120
|
-
* honoured. A collapsed rail is 80px of icons, so it only earns its place in a nav short
|
|
121
|
-
* enough and iconographic enough to survive the loss of its labels — a long text nav
|
|
122
|
-
* (the docs site's own, for one) is better off never offering it.
|
|
123
|
-
*/
|
|
124
|
-
collapsible?: boolean;
|
|
125
|
-
collapsed?: boolean;
|
|
126
|
-
/** Omit and the collapse toggle is not rendered, though `collapsed` still applies. */
|
|
127
|
-
onToggle?: () => void;
|
|
128
|
-
size?: NavItemSize;
|
|
129
|
-
variant?: NavItemVariant;
|
|
130
|
-
/** Expanded width, as a Tailwind class. */
|
|
131
|
-
width?: string;
|
|
132
|
-
collapsedWidth?: string;
|
|
133
|
-
className?: string;
|
|
134
|
-
}
|
|
235
|
+
type AppSidebarProps = Omit<SidebarProps, 'currentPath' | 'currentHash' | 'linkComponent'>;
|
|
135
236
|
/**
|
|
136
|
-
* The application nav rail
|
|
237
|
+
* The application nav rail, wired to react-router: the current row comes from `useLocation`
|
|
238
|
+
* and rows link with `Link`.
|
|
137
239
|
*
|
|
138
|
-
* Lives on its own entry point (`@platned/ui/sidebar`) because
|
|
139
|
-
* `
|
|
240
|
+
* Lives on its own entry point (`@platned/ui/sidebar`) because `react-router-dom` is an
|
|
241
|
+
* optional peer dependency. From 0.9.6 it is a thin wrapper over `Sidebar` on the main entry,
|
|
242
|
+
* which takes the location and the link component as props — use that directly in an app on
|
|
243
|
+
* another router (Next.js).
|
|
140
244
|
*
|
|
141
245
|
* Through 0.4.0 this was not a library component at all. It hardcoded ten product routes,
|
|
142
246
|
* their labels and their icons, an `SCIC` wordmark, and an `isAdmin` flag gating two of the
|
|
143
|
-
* rows — so the only app it could render was the one it was extracted from
|
|
144
|
-
*
|
|
145
|
-
* app-specific is now a prop or a slot, and the docs site runs on this component.
|
|
247
|
+
* rows — so the only app it could render was the one it was extracted from. Everything
|
|
248
|
+
* app-specific is now a prop or a slot.
|
|
146
249
|
*
|
|
147
250
|
* Width is an explicit prop rather than something `className` overrides: the width is
|
|
148
251
|
* conditional on `collapsed`, so a `className="w-64"` would tailwind-merge away the
|
|
149
252
|
* collapsed width too and break the collapse. Everything else about the shell is fair game
|
|
150
253
|
* for `className` — `rounded-none` to flatten it for a full-bleed layout, for instance.
|
|
151
254
|
*/
|
|
152
|
-
declare function AppSidebar(
|
|
153
|
-
type SidebarSeparatorProps = HTMLAttributes<HTMLDivElement>;
|
|
154
|
-
/**
|
|
155
|
-
* The rule between nav groups. `AppSidebar` draws one above every group after the first;
|
|
156
|
-
* this is exported so the same line can be used in the `footer` slot or in a hand-composed
|
|
157
|
-
* rail without anyone re-deriving `h-px bg-divider` and inevitably picking a different inset.
|
|
158
|
-
*
|
|
159
|
-
* Decorative by default. The grouping it marks is already carried semantically by each
|
|
160
|
-
* group's heading — which stays in the accessibility tree even when the rail is collapsed and
|
|
161
|
-
* the heading is visually hidden — so announcing the rule as well is redundant. Pass
|
|
162
|
-
* `role="separator"` through if you are using it somewhere that has no heading to lean on.
|
|
163
|
-
*/
|
|
164
|
-
declare function SidebarSeparator({ className, ...rest }: SidebarSeparatorProps): react.JSX.Element;
|
|
165
|
-
interface SidebarUserCardProps {
|
|
166
|
-
name: string;
|
|
167
|
-
role: string;
|
|
168
|
-
onLogout: () => void;
|
|
169
|
-
collapsed?: boolean;
|
|
170
|
-
/** Extra menu entries above Sign out. */
|
|
171
|
-
menu?: ReactNode;
|
|
172
|
-
className?: string;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* The signed-in user block, for `AppSidebar`'s `footer` slot.
|
|
176
|
-
*
|
|
177
|
-
* Was private, and its props were on `AppSidebar` itself — which meant every consumer of the
|
|
178
|
-
* sidebar had to have a user, a role and a logout handler whether it had a concept of any
|
|
179
|
-
* of them or not. The docs site has none, and passes no footer.
|
|
180
|
-
*
|
|
181
|
-
* Its menu is `DropdownMenu` rather than the hand-rolled click-outside popover it was: that
|
|
182
|
-
* one had no keyboard contract and, being absolutely positioned, was clipped by the
|
|
183
|
-
* collapsed rail. `DropdownMenu` portals.
|
|
184
|
-
*/
|
|
185
|
-
declare function SidebarUserCard({ name, role, onLogout, collapsed, menu, className, }: SidebarUserCardProps): react.JSX.Element;
|
|
255
|
+
declare function AppSidebar(props: AppSidebarProps): react.JSX.Element;
|
|
186
256
|
|
|
187
257
|
export { AppSidebar, type AppSidebarProps, type NavTabItem, NavTabs, type NavTabsProps, type SidebarNavGroup, type SidebarNavItem, SidebarSeparator, type SidebarSeparatorProps, SidebarUserCard, type SidebarUserCardProps };
|
package/dist/sidebar.d.ts
CHANGED
|
@@ -1,9 +1,173 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, HTMLAttributes } from 'react';
|
|
2
|
+
import { ReactNode, ComponentType, AnchorHTMLAttributes, RefAttributes, HTMLAttributes } from 'react';
|
|
3
3
|
import { RowData } from '@tanstack/react-table';
|
|
4
4
|
|
|
5
5
|
type NavItemSize = 'sm' | 'md';
|
|
6
6
|
type NavItemVariant = 'card' | 'plain';
|
|
7
|
+
/**
|
|
8
|
+
* The two Figma sidebar variants (Sidebar Navigation, node 3133:255). New in 0.9.6.
|
|
9
|
+
*
|
|
10
|
+
* `comfortable` is the card row: 44px, its own border and surface. `compact` is the plain
|
|
11
|
+
* row: 40px, text on the rail. Both use the 16px Body Base label and a 20px icon.
|
|
12
|
+
*/
|
|
13
|
+
type NavItemDensity = 'comfortable' | 'compact';
|
|
14
|
+
|
|
15
|
+
interface SidebarNavItem {
|
|
16
|
+
/** Stable key. Falls back to `to`, then `href`, then `label`. New in 0.9.6. */
|
|
17
|
+
id?: string;
|
|
18
|
+
/**
|
|
19
|
+
* An in-app destination, rendered through `linkComponent`. May carry a hash
|
|
20
|
+
* (`/docs/floating#tooltip`) to link to a section of a page: that row is current only when
|
|
21
|
+
* the hash matches too, and the page's own plain row steps aside while it is. Optional from
|
|
22
|
+
* 0.9.6, so a row can exist only to open its `children`.
|
|
23
|
+
*/
|
|
24
|
+
to?: string;
|
|
25
|
+
/**
|
|
26
|
+
* An external destination, opened in a new tab as a plain `<a>`. New in 0.9.6. Use `to`
|
|
27
|
+
* for anything inside the app.
|
|
28
|
+
*/
|
|
29
|
+
href?: string;
|
|
30
|
+
label: string;
|
|
31
|
+
/** Optional — a collapsed row without one falls back to a monogram of its label. */
|
|
32
|
+
icon?: ReactNode;
|
|
33
|
+
/** Red dot on the row — something new behind this destination. */
|
|
34
|
+
indicator?: boolean;
|
|
35
|
+
/** Match the path exactly rather than as a prefix. Needed for an index route. */
|
|
36
|
+
end?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A destination that exists but cannot be opened right now (coming soon). The row is
|
|
39
|
+
* dimmed, announced with `aria-disabled`, out of the tab order, and refuses the press.
|
|
40
|
+
* Something the user has no permission for should not be in the list at all: see
|
|
41
|
+
* `filterNav`.
|
|
42
|
+
*/
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Overrides route matching, for a row whose "current" rule is more than a path prefix —
|
|
46
|
+
* one page reached from two places, say. New in 0.9.6.
|
|
47
|
+
*/
|
|
48
|
+
isActive?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Child rows, one level deep. Expanded they open under the row; on the collapsed rail the
|
|
51
|
+
* row opens them as a flyout menu. New in 0.9.6.
|
|
52
|
+
*/
|
|
53
|
+
children?: SidebarNavItem[];
|
|
54
|
+
/** Whether the children start open. Default: open when one of them is the current route. */
|
|
55
|
+
defaultOpen?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface SidebarNavGroup {
|
|
58
|
+
/** Stable key. Falls back to `title`. New in 0.9.6. */
|
|
59
|
+
id?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Heading above the group. Omit for an ungrouped run of rows.
|
|
62
|
+
*
|
|
63
|
+
* Kept in the accessibility tree when the rail is collapsed rather than dropped: it is the
|
|
64
|
+
* only thing saying what the run of icons below it has in common.
|
|
65
|
+
*/
|
|
66
|
+
title?: string;
|
|
67
|
+
items: SidebarNavItem[];
|
|
68
|
+
/** Give the heading a chevron that folds the group away. Needs a `title`. New in 0.9.6. */
|
|
69
|
+
collapsible?: boolean;
|
|
70
|
+
/** With `collapsible`: whether the group starts open. Default `true`. */
|
|
71
|
+
defaultOpen?: boolean;
|
|
72
|
+
/** Trailing slot in the heading — an "add" icon button, say. New in 0.9.6. */
|
|
73
|
+
action?: ReactNode;
|
|
74
|
+
}
|
|
75
|
+
interface SidebarLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
76
|
+
href: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Renders an in-app row's link. It must forward its ref to the anchor — the collapsed rail
|
|
80
|
+
* anchors a tooltip to it and the flyout a menu item — as `next/link` and react-router's
|
|
81
|
+
* `Link` both do.
|
|
82
|
+
*/
|
|
83
|
+
type SidebarLinkComponent = ComponentType<SidebarLinkProps & RefAttributes<HTMLAnchorElement>>;
|
|
84
|
+
interface SidebarRenderState {
|
|
85
|
+
collapsed: boolean;
|
|
86
|
+
density: NavItemDensity;
|
|
87
|
+
}
|
|
88
|
+
interface SidebarProps {
|
|
89
|
+
/** The scrolling nav. One untitled group is a flat list. */
|
|
90
|
+
groups: SidebarNavGroup[];
|
|
91
|
+
/** Rows pinned below the scrolling nav — settings, help, a feedback link. */
|
|
92
|
+
footerNav?: SidebarNavItem[];
|
|
93
|
+
/**
|
|
94
|
+
* Brand lockup. Given a function it receives `collapsed` and `density`, so the caller can
|
|
95
|
+
* swap a full lockup for a mark alone rather than having one squeezed into the rail.
|
|
96
|
+
*/
|
|
97
|
+
brand?: ReactNode | ((state: SidebarRenderState) => ReactNode);
|
|
98
|
+
/** Bottom slot — a `SidebarUserCard`, a version pill, nothing. A function gets the state. */
|
|
99
|
+
footer?: ReactNode | ((state: SidebarRenderState) => ReactNode);
|
|
100
|
+
/**
|
|
101
|
+
* Figma's two sidebar variants. `comfortable` (default): 44px card rows, an 80px rail.
|
|
102
|
+
* `compact`: 40px plain rows, a 72px rail. New in 0.9.6.
|
|
103
|
+
*/
|
|
104
|
+
density?: NavItemDensity;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the rail can collapse at all. `false` locks it open: no toggle button, and
|
|
107
|
+
* `collapsed` is ignored rather than half honoured.
|
|
108
|
+
*/
|
|
109
|
+
collapsible?: boolean;
|
|
110
|
+
/** Controlled collapsed state. Omit for uncontrolled. */
|
|
111
|
+
collapsed?: boolean;
|
|
112
|
+
/** Initial collapsed state when uncontrolled. */
|
|
113
|
+
defaultCollapsed?: boolean;
|
|
114
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
115
|
+
/**
|
|
116
|
+
* Called by the collapse toggle. Kept from before 0.9.6, when `collapsed` was always
|
|
117
|
+
* controlled: passing `collapsed` with neither this nor `onCollapsedChange` still means
|
|
118
|
+
* "no toggle button".
|
|
119
|
+
*/
|
|
120
|
+
onToggle?: () => void;
|
|
121
|
+
/**
|
|
122
|
+
* localStorage key the collapsed state is remembered under, so it survives a reload.
|
|
123
|
+
* Read after mount, so server and client render the same first frame. New in 0.9.6.
|
|
124
|
+
*/
|
|
125
|
+
storageKey?: string;
|
|
126
|
+
/** The current pathname, which decides the current row. New in 0.9.6. */
|
|
127
|
+
currentPath?: string;
|
|
128
|
+
/** The current hash, for rows that link to a section (`#tooltip`). */
|
|
129
|
+
currentHash?: string;
|
|
130
|
+
/** Renders in-app links. Default a plain `<a>`; pass `next/link` or a router link. */
|
|
131
|
+
linkComponent?: SidebarLinkComponent;
|
|
132
|
+
/** Called when a row is pressed — after the mobile drawer has closed itself. */
|
|
133
|
+
onNavigate?: () => void;
|
|
134
|
+
/** Accessible name of the sidebar landmark. Default "Primary". */
|
|
135
|
+
label?: string;
|
|
136
|
+
/** @deprecated Use `density`. `plain` maps to `compact`; `size` is ignored. */
|
|
137
|
+
size?: NavItemSize;
|
|
138
|
+
/** @deprecated Use `density`. `plain` maps to `compact`, `card` to `comfortable`. */
|
|
139
|
+
variant?: NavItemVariant;
|
|
140
|
+
/** Expanded width, as a Tailwind class. Default `w-80` (320px). */
|
|
141
|
+
width?: string;
|
|
142
|
+
/** Collapsed width. Default `w-20` (80px) comfortable, `w-[72px]` compact. */
|
|
143
|
+
collapsedWidth?: string;
|
|
144
|
+
className?: string;
|
|
145
|
+
}
|
|
146
|
+
type SidebarSeparatorProps = HTMLAttributes<HTMLDivElement>;
|
|
147
|
+
/**
|
|
148
|
+
* A rule for the sidebar's `footer` slot or a hand-composed rail. The sidebar itself no
|
|
149
|
+
* longer draws one between groups from 0.9.6 — the Figma frames separate groups by space.
|
|
150
|
+
*
|
|
151
|
+
* Decorative by default. Pass `role="separator"` through where it marks a grouping nothing
|
|
152
|
+
* else names.
|
|
153
|
+
*/
|
|
154
|
+
declare function SidebarSeparator({ className, ...rest }: SidebarSeparatorProps): react.JSX.Element;
|
|
155
|
+
interface SidebarUserCardProps {
|
|
156
|
+
name: string;
|
|
157
|
+
role: string;
|
|
158
|
+
onLogout: () => void;
|
|
159
|
+
collapsed?: boolean;
|
|
160
|
+
/** Extra menu entries above Sign out. */
|
|
161
|
+
menu?: ReactNode;
|
|
162
|
+
className?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The signed-in user block, for the sidebar's `footer` slot — Figma `UserCard` (node
|
|
166
|
+
* 3123:156). On the main entry from 0.9.6; `@platned/ui/sidebar` still exports it.
|
|
167
|
+
*
|
|
168
|
+
* Its menu is `DropdownMenu`, which portals, so the collapsed rail does not clip it.
|
|
169
|
+
*/
|
|
170
|
+
declare function SidebarUserCard({ name, role, onLogout, collapsed, menu, className, }: SidebarUserCardProps): react.JSX.Element;
|
|
7
171
|
|
|
8
172
|
/** How a column appears in card mode. */
|
|
9
173
|
type ColumnMobileRole = 'title' | 'status' | 'actions' | 'field' | 'hidden';
|
|
@@ -68,120 +232,26 @@ interface NavTabsProps {
|
|
|
68
232
|
* Figma specifies for a tab rule, rather than the lighter `brand` border token. */
|
|
69
233
|
declare function NavTabs({ items, className }: NavTabsProps): react.JSX.Element;
|
|
70
234
|
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The destination. May carry a hash (`/docs/floating#tooltip`) to link to a section of a
|
|
74
|
-
* page: that row is current only when the hash matches too, and the page's own plain row
|
|
75
|
-
* steps aside while it is. New in 0.7.0.
|
|
76
|
-
*/
|
|
77
|
-
to: string;
|
|
78
|
-
label: string;
|
|
79
|
-
/** Optional — a collapsed row without one falls back to a monogram of its label. */
|
|
80
|
-
icon?: ReactNode;
|
|
81
|
-
/** Red dot on the row — something new behind this destination. */
|
|
82
|
-
indicator?: boolean;
|
|
83
|
-
/** Match the path exactly rather than as a prefix. Needed for an index route. */
|
|
84
|
-
end?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* A destination that exists but cannot be opened right now (no permission, coming soon).
|
|
87
|
-
* The row is dimmed, announced with `aria-disabled`, out of the tab order, and refuses the
|
|
88
|
-
* press. New in 0.7.0.
|
|
89
|
-
*/
|
|
90
|
-
disabled?: boolean;
|
|
91
|
-
}
|
|
92
|
-
interface SidebarNavGroup {
|
|
93
|
-
/**
|
|
94
|
-
* Uppercase heading above the group. Omit for an ungrouped run of rows.
|
|
95
|
-
*
|
|
96
|
-
* Kept in the accessibility tree when the rail is collapsed rather than dropped: it is the
|
|
97
|
-
* only thing saying what the run of icons below it has in common.
|
|
98
|
-
*/
|
|
99
|
-
title?: string;
|
|
100
|
-
items: SidebarNavItem[];
|
|
101
|
-
}
|
|
102
|
-
interface AppSidebarProps {
|
|
103
|
-
/** The scrolling nav. One untitled group is a flat list. */
|
|
104
|
-
groups: SidebarNavGroup[];
|
|
105
|
-
/** Rows pinned below the scrolling nav — settings, help, a sign-out link. */
|
|
106
|
-
footerNav?: SidebarNavItem[];
|
|
107
|
-
/**
|
|
108
|
-
* Brand lockup. Given a function it receives `collapsed`, so the caller can swap a full
|
|
109
|
-
* lockup for a mark alone rather than having one squeezed into an 80px rail.
|
|
110
|
-
*/
|
|
111
|
-
brand?: ReactNode | ((state: {
|
|
112
|
-
collapsed: boolean;
|
|
113
|
-
}) => ReactNode);
|
|
114
|
-
/** Bottom slot, below a divider — a user card, a version pill, nothing. */
|
|
115
|
-
footer?: ReactNode;
|
|
116
|
-
/**
|
|
117
|
-
* Whether the rail can collapse at all.
|
|
118
|
-
*
|
|
119
|
-
* `false` locks it open: no toggle button, and `collapsed` is ignored rather than half
|
|
120
|
-
* honoured. A collapsed rail is 80px of icons, so it only earns its place in a nav short
|
|
121
|
-
* enough and iconographic enough to survive the loss of its labels — a long text nav
|
|
122
|
-
* (the docs site's own, for one) is better off never offering it.
|
|
123
|
-
*/
|
|
124
|
-
collapsible?: boolean;
|
|
125
|
-
collapsed?: boolean;
|
|
126
|
-
/** Omit and the collapse toggle is not rendered, though `collapsed` still applies. */
|
|
127
|
-
onToggle?: () => void;
|
|
128
|
-
size?: NavItemSize;
|
|
129
|
-
variant?: NavItemVariant;
|
|
130
|
-
/** Expanded width, as a Tailwind class. */
|
|
131
|
-
width?: string;
|
|
132
|
-
collapsedWidth?: string;
|
|
133
|
-
className?: string;
|
|
134
|
-
}
|
|
235
|
+
type AppSidebarProps = Omit<SidebarProps, 'currentPath' | 'currentHash' | 'linkComponent'>;
|
|
135
236
|
/**
|
|
136
|
-
* The application nav rail
|
|
237
|
+
* The application nav rail, wired to react-router: the current row comes from `useLocation`
|
|
238
|
+
* and rows link with `Link`.
|
|
137
239
|
*
|
|
138
|
-
* Lives on its own entry point (`@platned/ui/sidebar`) because
|
|
139
|
-
* `
|
|
240
|
+
* Lives on its own entry point (`@platned/ui/sidebar`) because `react-router-dom` is an
|
|
241
|
+
* optional peer dependency. From 0.9.6 it is a thin wrapper over `Sidebar` on the main entry,
|
|
242
|
+
* which takes the location and the link component as props — use that directly in an app on
|
|
243
|
+
* another router (Next.js).
|
|
140
244
|
*
|
|
141
245
|
* Through 0.4.0 this was not a library component at all. It hardcoded ten product routes,
|
|
142
246
|
* their labels and their icons, an `SCIC` wordmark, and an `isAdmin` flag gating two of the
|
|
143
|
-
* rows — so the only app it could render was the one it was extracted from
|
|
144
|
-
*
|
|
145
|
-
* app-specific is now a prop or a slot, and the docs site runs on this component.
|
|
247
|
+
* rows — so the only app it could render was the one it was extracted from. Everything
|
|
248
|
+
* app-specific is now a prop or a slot.
|
|
146
249
|
*
|
|
147
250
|
* Width is an explicit prop rather than something `className` overrides: the width is
|
|
148
251
|
* conditional on `collapsed`, so a `className="w-64"` would tailwind-merge away the
|
|
149
252
|
* collapsed width too and break the collapse. Everything else about the shell is fair game
|
|
150
253
|
* for `className` — `rounded-none` to flatten it for a full-bleed layout, for instance.
|
|
151
254
|
*/
|
|
152
|
-
declare function AppSidebar(
|
|
153
|
-
type SidebarSeparatorProps = HTMLAttributes<HTMLDivElement>;
|
|
154
|
-
/**
|
|
155
|
-
* The rule between nav groups. `AppSidebar` draws one above every group after the first;
|
|
156
|
-
* this is exported so the same line can be used in the `footer` slot or in a hand-composed
|
|
157
|
-
* rail without anyone re-deriving `h-px bg-divider` and inevitably picking a different inset.
|
|
158
|
-
*
|
|
159
|
-
* Decorative by default. The grouping it marks is already carried semantically by each
|
|
160
|
-
* group's heading — which stays in the accessibility tree even when the rail is collapsed and
|
|
161
|
-
* the heading is visually hidden — so announcing the rule as well is redundant. Pass
|
|
162
|
-
* `role="separator"` through if you are using it somewhere that has no heading to lean on.
|
|
163
|
-
*/
|
|
164
|
-
declare function SidebarSeparator({ className, ...rest }: SidebarSeparatorProps): react.JSX.Element;
|
|
165
|
-
interface SidebarUserCardProps {
|
|
166
|
-
name: string;
|
|
167
|
-
role: string;
|
|
168
|
-
onLogout: () => void;
|
|
169
|
-
collapsed?: boolean;
|
|
170
|
-
/** Extra menu entries above Sign out. */
|
|
171
|
-
menu?: ReactNode;
|
|
172
|
-
className?: string;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* The signed-in user block, for `AppSidebar`'s `footer` slot.
|
|
176
|
-
*
|
|
177
|
-
* Was private, and its props were on `AppSidebar` itself — which meant every consumer of the
|
|
178
|
-
* sidebar had to have a user, a role and a logout handler whether it had a concept of any
|
|
179
|
-
* of them or not. The docs site has none, and passes no footer.
|
|
180
|
-
*
|
|
181
|
-
* Its menu is `DropdownMenu` rather than the hand-rolled click-outside popover it was: that
|
|
182
|
-
* one had no keyboard contract and, being absolutely positioned, was clipped by the
|
|
183
|
-
* collapsed rail. `DropdownMenu` portals.
|
|
184
|
-
*/
|
|
185
|
-
declare function SidebarUserCard({ name, role, onLogout, collapsed, menu, className, }: SidebarUserCardProps): react.JSX.Element;
|
|
255
|
+
declare function AppSidebar(props: AppSidebarProps): react.JSX.Element;
|
|
186
256
|
|
|
187
257
|
export { AppSidebar, type AppSidebarProps, type NavTabItem, NavTabs, type NavTabsProps, type SidebarNavGroup, type SidebarNavItem, SidebarSeparator, type SidebarSeparatorProps, SidebarUserCard, type SidebarUserCardProps };
|