@designa8/vibedesign-stripe-deepseek-85ea 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +183 -52
- package/dist/index.js +183 -52
- package/dist/styles.css +4 -0
- package/package.json +1 -1
- package/src/atoms/Drawer/Drawer.tsx +45 -22
- package/src/atoms/Modal/Modal.tsx +11 -4
- package/src/atoms/Sidebar/preview.tsx +74 -116
- package/src/atoms/SidebarDesktop/SidebarDesktop.tsx +135 -15
- package/src/atoms/SidebarMobile/SidebarMobile.tsx +115 -9
|
@@ -2,30 +2,35 @@ import * as React from "react";
|
|
|
2
2
|
import { Avatar } from "../Avatar";
|
|
3
3
|
import { Button } from "../Button";
|
|
4
4
|
import { Icon } from "../Icon";
|
|
5
|
-
import {
|
|
6
|
-
import { SidebarMobile } from "../SidebarMobile";
|
|
5
|
+
import { type SidebarDesktopNavItem } from "../SidebarDesktop";
|
|
7
6
|
import { Sidebar, type SidebarNavTarget } from "./Sidebar";
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/** Nav fixtures with the count wired to state, so the pill really hides at 0. */
|
|
9
|
+
const buildItems = (pending: number): SidebarDesktopNavItem[] => [
|
|
10
|
+
{
|
|
11
|
+
id: "payments",
|
|
12
|
+
label: "Tasks",
|
|
13
|
+
icon: "credit-card",
|
|
14
|
+
href: "/tasks",
|
|
15
|
+
badge: pending,
|
|
16
|
+
},
|
|
11
17
|
{ id: "balances", label: "Balances", icon: "layers", href: "/balances" },
|
|
12
18
|
{
|
|
13
19
|
id: "payouts",
|
|
14
|
-
label: "
|
|
20
|
+
label: "Approvals",
|
|
15
21
|
icon: "arrow-left-right",
|
|
22
|
+
badge: pending,
|
|
16
23
|
children: [
|
|
17
|
-
{ id: "scheduled", label: "Scheduled payouts", href: "/
|
|
18
|
-
{ id: "payout-accounts", label: "Payout accounts", href: "/
|
|
19
|
-
{ id: "payout-limits", label: "Payout limits", href: "/payouts/limits" },
|
|
24
|
+
{ id: "scheduled", label: "Scheduled payouts", href: "/approvals/scheduled" },
|
|
25
|
+
{ id: "payout-accounts", label: "Payout accounts", href: "/approvals/accounts" },
|
|
20
26
|
],
|
|
21
27
|
},
|
|
22
28
|
{ id: "developers", label: "Developers", icon: "code", href: "/developers" },
|
|
23
|
-
{ id: "api-logs", label: "API logs", icon: "file", href: "/api-logs" },
|
|
24
29
|
];
|
|
25
30
|
|
|
26
31
|
const SECONDARY_ITEMS: SidebarDesktopNavItem[] = [
|
|
27
32
|
{ id: "settings", label: "Settings", icon: "settings", href: "/settings" },
|
|
28
|
-
{ id: "team", label: "Team", icon: "group", href: "/team" },
|
|
33
|
+
{ id: "team", label: "Team", icon: "group", href: "/team", badge: "New" },
|
|
29
34
|
];
|
|
30
35
|
|
|
31
36
|
const ACCOUNTS = [
|
|
@@ -35,27 +40,11 @@ const ACCOUNTS = [
|
|
|
35
40
|
|
|
36
41
|
const PROFILE = { name: "Priya Shah", email: "priya@acme.com" };
|
|
37
42
|
|
|
38
|
-
/** A tiny content pane so the routed shell reads as a page, not a floating rail. */
|
|
39
|
-
const ContentPane = ({ route, unread }: { route: string; unread: number }) => (
|
|
40
|
-
<div className="flex min-w-0 flex-col gap-sm bg-canvas p-lg">
|
|
41
|
-
<p className="text-caption uppercase text-muted">Current route</p>
|
|
42
|
-
<p className="text-heading-md text-ink">{route}</p>
|
|
43
|
-
<p className="text-body-sm text-body">
|
|
44
|
-
Click any destination in the navigation to route there. The rail keeps its
|
|
45
|
-
header and footer pinned while the destination list scrolls on its own.
|
|
46
|
-
</p>
|
|
47
|
-
<p className="text-body-sm text-body">
|
|
48
|
-
{unread > 0
|
|
49
|
-
? `${unread} unread notifications waiting in the footer bell.`
|
|
50
|
-
: "Notifications cleared — the badge is gone."}
|
|
51
|
-
</p>
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
|
|
55
43
|
export default function Preview() {
|
|
56
44
|
const [activeId, setActiveId] = React.useState("payments");
|
|
57
|
-
const [route, setRoute] = React.useState("/
|
|
45
|
+
const [route, setRoute] = React.useState("/tasks");
|
|
58
46
|
const [unread, setUnread] = React.useState(4);
|
|
47
|
+
const [pending, setPending] = React.useState(2);
|
|
59
48
|
|
|
60
49
|
const handleNavigate = (item: SidebarNavTarget) => {
|
|
61
50
|
setRoute(item.href ?? `#${item.id}`);
|
|
@@ -63,99 +52,68 @@ export default function Preview() {
|
|
|
63
52
|
};
|
|
64
53
|
|
|
65
54
|
return (
|
|
66
|
-
<div className="mx-auto w-full max-w-3xl space-y-
|
|
67
|
-
|
|
68
|
-
<section className="space-y-sm">
|
|
55
|
+
<div className="mx-auto w-full max-w-3xl space-y-sm p-lg">
|
|
56
|
+
<div className="flex flex-wrap items-center justify-between gap-sm">
|
|
69
57
|
<p className="text-caption uppercase text-muted">
|
|
70
|
-
|
|
58
|
+
Count pill unfolded, dot on the glyph once folded
|
|
71
59
|
</p>
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
secondaryActiveId="settings"
|
|
81
|
-
accounts={ACCOUNTS}
|
|
82
|
-
profile={PROFILE}
|
|
83
|
-
plan={{ name: "Pro", price: "$2,400.00 / month", href: "/billing" }}
|
|
84
|
-
notificationCount={unread}
|
|
85
|
-
onNotifications={() => setUnread(0)}
|
|
86
|
-
mobileActions={
|
|
87
|
-
<>
|
|
88
|
-
<Button variant="bare" size="icon-sm" aria-label="Search">
|
|
89
|
-
<Icon name="search" size={20} strokeWidth={1.75} />
|
|
90
|
-
</Button>
|
|
91
|
-
<Button variant="bare" size="icon-sm" aria-label="Notifications">
|
|
92
|
-
<Icon name="bell" size={20} strokeWidth={1.75} />
|
|
93
|
-
</Button>
|
|
94
|
-
<Avatar name={PROFILE.name} size="sm" />
|
|
95
|
-
</>
|
|
96
|
-
}
|
|
97
|
-
mobileDrawerFooter={
|
|
98
|
-
<Button variant="outline-soft" size="md" fullWidth>
|
|
99
|
-
Switch theme
|
|
100
|
-
</Button>
|
|
101
|
-
}
|
|
102
|
-
/>
|
|
103
|
-
<ContentPane route={route} unread={unread} />
|
|
104
|
-
</div>
|
|
105
|
-
</section>
|
|
60
|
+
<Button
|
|
61
|
+
variant="outline-soft"
|
|
62
|
+
size="sm"
|
|
63
|
+
onClick={() => setPending((current) => (current === 0 ? 2 : 0))}
|
|
64
|
+
>
|
|
65
|
+
{pending === 0 ? "Show pending counts" : "Clear pending counts"}
|
|
66
|
+
</Button>
|
|
67
|
+
</div>
|
|
106
68
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
<p className="text-caption uppercase text-muted">
|
|
130
|
-
Mobile header — tap the menu to open the drawer
|
|
131
|
-
</p>
|
|
132
|
-
<div className="w-full overflow-hidden rounded-xl border border-hairline bg-surface">
|
|
133
|
-
<SidebarMobile
|
|
134
|
-
items={ITEMS}
|
|
135
|
-
activeId={activeId}
|
|
136
|
-
onNavigate={handleNavigate}
|
|
137
|
-
secondaryItems={SECONDARY_ITEMS}
|
|
138
|
-
accounts={ACCOUNTS}
|
|
139
|
-
profile={PROFILE}
|
|
140
|
-
plan={null}
|
|
141
|
-
notificationCount={unread}
|
|
142
|
-
mobileActions={
|
|
143
|
-
<>
|
|
144
|
-
<Button variant="bare" size="icon-sm" aria-label="Search">
|
|
145
|
-
<Icon name="search" size={20} strokeWidth={1.75} />
|
|
146
|
-
</Button>
|
|
147
|
-
<Avatar name={PROFILE.name} size="sm" />
|
|
148
|
-
</>
|
|
149
|
-
}
|
|
150
|
-
mobileDrawerFooter={
|
|
151
|
-
<Button variant="outline-soft" size="md" fullWidth>
|
|
152
|
-
Switch theme
|
|
69
|
+
<div className="grid w-full grid-cols-1 overflow-hidden rounded-xl border border-hairline bg-surface md:grid-cols-[auto_minmax(0,1fr)]">
|
|
70
|
+
<Sidebar
|
|
71
|
+
wordmark="Nimbus"
|
|
72
|
+
homeHref="/"
|
|
73
|
+
items={buildItems(pending)}
|
|
74
|
+
activeId={activeId}
|
|
75
|
+
onNavigate={handleNavigate}
|
|
76
|
+
secondaryItems={SECONDARY_ITEMS}
|
|
77
|
+
secondaryActiveId="settings"
|
|
78
|
+
accounts={ACCOUNTS}
|
|
79
|
+
profile={PROFILE}
|
|
80
|
+
plan={{ name: "Pro", price: "$2,400.00 / month", href: "/billing" }}
|
|
81
|
+
notificationCount={unread}
|
|
82
|
+
onNotifications={() => setUnread(0)}
|
|
83
|
+
defaultExpandedId={null}
|
|
84
|
+
mobileActions={
|
|
85
|
+
<>
|
|
86
|
+
<Button variant="bare" size="icon-sm" aria-label="Search">
|
|
87
|
+
<Icon name="search" size={20} strokeWidth={1.75} />
|
|
88
|
+
</Button>
|
|
89
|
+
<Button variant="bare" size="icon-sm" aria-label="Notifications">
|
|
90
|
+
<Icon name="bell" size={20} strokeWidth={1.75} />
|
|
153
91
|
</Button>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
92
|
+
<Avatar name={PROFILE.name} size="sm" />
|
|
93
|
+
</>
|
|
94
|
+
}
|
|
95
|
+
mobileDrawerFooter={
|
|
96
|
+
<Button variant="outline-soft" size="md" fullWidth>
|
|
97
|
+
Switch theme
|
|
98
|
+
</Button>
|
|
99
|
+
}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<div className="flex min-w-0 flex-col gap-sm bg-canvas p-lg">
|
|
103
|
+
<p className="text-caption uppercase text-muted">Current route</p>
|
|
104
|
+
<p className="text-heading-md text-ink">{route}</p>
|
|
105
|
+
<p className="text-body-sm text-body">
|
|
106
|
+
Tasks carries a count pill after its label. Collapse the rail and the
|
|
107
|
+
same count becomes a dot on the glyph, while the row still announces
|
|
108
|
+
the number to a screen reader.
|
|
109
|
+
</p>
|
|
110
|
+
<p className="text-body-sm text-body">
|
|
111
|
+
{unread > 0
|
|
112
|
+
? `${unread} unread notifications sit in the footer bell.`
|
|
113
|
+
: "Notifications cleared — the bell badge is gone."}
|
|
114
|
+
</p>
|
|
157
115
|
</div>
|
|
158
|
-
</
|
|
116
|
+
</div>
|
|
159
117
|
</div>
|
|
160
118
|
);
|
|
161
119
|
}
|
|
@@ -36,6 +36,12 @@ export interface SidebarDesktopNavItem {
|
|
|
36
36
|
icon: IconName;
|
|
37
37
|
/** Destination for a plain row. */
|
|
38
38
|
href?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Pending-work count painted as a pill after the label, and as a dot on the
|
|
41
|
+
* glyph while the rail is folded. A number (99+ collapses), or a short string
|
|
42
|
+
* such as "New". Hidden when undefined, empty, or zero.
|
|
43
|
+
*/
|
|
44
|
+
badge?: number | string;
|
|
39
45
|
/** Nested rows: turns the parent into a disclosure. */
|
|
40
46
|
children?: Array<{ id: string; label: string; href?: string }>;
|
|
41
47
|
}
|
|
@@ -149,6 +155,85 @@ const glyph = (name: IconName, size = 16, strokeWidth = 1.75) => (
|
|
|
149
155
|
/>
|
|
150
156
|
);
|
|
151
157
|
|
|
158
|
+
/** True when an item carries a count worth painting. Zero and empties hide. */
|
|
159
|
+
const hasBadge = (badge?: number | string) => {
|
|
160
|
+
if (badge === undefined || badge === null) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if (typeof badge === "number") {
|
|
164
|
+
return Number.isFinite(badge) && badge !== 0;
|
|
165
|
+
}
|
|
166
|
+
const trimmed = badge.trim();
|
|
167
|
+
return trimmed.length > 0 && trimmed !== "0";
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** The pill copy: numbers above 99 collapse so a row never reflows. */
|
|
171
|
+
const badgeText = (badge: number | string) =>
|
|
172
|
+
typeof badge === "number"
|
|
173
|
+
? badge > 99
|
|
174
|
+
? "99+"
|
|
175
|
+
: String(badge)
|
|
176
|
+
: badge.trim();
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The row's accessible name. The count rides along as pending work, so a folded
|
|
180
|
+
* icon rail still announces "API logs, 12 pending" instead of a bare glyph.
|
|
181
|
+
*/
|
|
182
|
+
const rowAccessibleName = (label: string, badge?: number | string) => {
|
|
183
|
+
if (!hasBadge(badge)) {
|
|
184
|
+
return label;
|
|
185
|
+
}
|
|
186
|
+
return typeof badge === "number"
|
|
187
|
+
? `${label}, ${badge} pending`
|
|
188
|
+
: `${label}, ${badgeText(badge as string)}`;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The count pill that follows a row's label. It wears the same recipe as the
|
|
193
|
+
* footer bell: the brand fill with inverse type on the navy rail, flipped to the
|
|
194
|
+
* inverse fill while the row itself is the selected brand block.
|
|
195
|
+
*/
|
|
196
|
+
const RailBadge = ({
|
|
197
|
+
badge,
|
|
198
|
+
active,
|
|
199
|
+
}: {
|
|
200
|
+
badge: number | string;
|
|
201
|
+
active?: boolean;
|
|
202
|
+
}) => (
|
|
203
|
+
<span
|
|
204
|
+
aria-hidden="true"
|
|
205
|
+
data-active={active || undefined}
|
|
206
|
+
className={cn(
|
|
207
|
+
"ml-auto flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full",
|
|
208
|
+
"bg-primary px-xxs text-caption text-on-primary",
|
|
209
|
+
"data-[active=true]:bg-on-primary data-[active=true]:text-primary",
|
|
210
|
+
)}
|
|
211
|
+
>
|
|
212
|
+
{badgeText(badge)}
|
|
213
|
+
</span>
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The leading glyph plus, while the rail is folded, a dot on its top corner.
|
|
218
|
+
* The folded rail has no room for a pill, so the dot carries the signal and the
|
|
219
|
+
* count lives in the row's accessible name.
|
|
220
|
+
*/
|
|
221
|
+
const railGlyph = (item: SidebarDesktopNavItem, folded: boolean) => (
|
|
222
|
+
<span className="relative inline-flex shrink-0 items-center">
|
|
223
|
+
{glyph(item.icon, 16, 1.75)}
|
|
224
|
+
{folded && hasBadge(item.badge) ? (
|
|
225
|
+
<span
|
|
226
|
+
aria-hidden="true"
|
|
227
|
+
className={cn(
|
|
228
|
+
"pointer-events-none absolute -right-xxs -top-xxs size-2 rounded-full",
|
|
229
|
+
"bg-primary",
|
|
230
|
+
"group-data-[active=true]:bg-on-primary",
|
|
231
|
+
)}
|
|
232
|
+
/>
|
|
233
|
+
) : null}
|
|
234
|
+
</span>
|
|
235
|
+
);
|
|
236
|
+
|
|
152
237
|
/** The visible label, kept in the tree as an accessible name while folded. */
|
|
153
238
|
const RowLabel = ({
|
|
154
239
|
folded,
|
|
@@ -170,7 +255,7 @@ const RowLabel = ({
|
|
|
170
255
|
*/
|
|
171
256
|
const railRowClass = (active: boolean, folded: boolean) =>
|
|
172
257
|
cn(
|
|
173
|
-
"flex w-full cursor-pointer items-center rounded-lg border-0 bg-transparent",
|
|
258
|
+
"group flex w-full cursor-pointer items-center rounded-lg border-0 bg-transparent",
|
|
174
259
|
"text-body-md transition duration-150 ease-out",
|
|
175
260
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
176
261
|
"focus-visible:ring-inset",
|
|
@@ -201,6 +286,10 @@ interface PanelBox {
|
|
|
201
286
|
* width and the labels change, so the item order and the active row survive the
|
|
202
287
|
* fold.
|
|
203
288
|
*
|
|
289
|
+
* A destination may carry a count: unfolded it reads as a pill after the label,
|
|
290
|
+
* folded it becomes a dot on the glyph, and either way the number is part of the
|
|
291
|
+
* row's accessible name. Nothing is painted when the count is absent or zero.
|
|
292
|
+
*
|
|
204
293
|
* The rail fills the height of its parent (`h-full`), so a one-viewport shell
|
|
205
294
|
* (`md:sticky md:top-0 md:h-dvh`) is all the sizing it needs. The header, the
|
|
206
295
|
* account switcher and the footer stay pinned; only the destination list
|
|
@@ -606,6 +695,7 @@ export const SidebarDesktop = React.forwardRef<HTMLElement, SidebarDesktopProps>
|
|
|
606
695
|
>
|
|
607
696
|
{navItems.map((item) => {
|
|
608
697
|
const active = item.id === activeId;
|
|
698
|
+
const badged = hasBadge(item.badge);
|
|
609
699
|
|
|
610
700
|
if (!item.children?.length) {
|
|
611
701
|
return (
|
|
@@ -614,11 +704,19 @@ export const SidebarDesktop = React.forwardRef<HTMLElement, SidebarDesktopProps>
|
|
|
614
704
|
href={item.href ?? `#${item.id}`}
|
|
615
705
|
onClick={navigate({ id: item.id, href: item.href })}
|
|
616
706
|
aria-current={active ? "page" : undefined}
|
|
617
|
-
|
|
707
|
+
data-active={active}
|
|
708
|
+
aria-label={
|
|
709
|
+
isFolded || badged
|
|
710
|
+
? rowAccessibleName(item.label, item.badge)
|
|
711
|
+
: undefined
|
|
712
|
+
}
|
|
618
713
|
className={railRowClass(active, isFolded)}
|
|
619
714
|
>
|
|
620
|
-
{
|
|
715
|
+
{railGlyph(item, isFolded)}
|
|
621
716
|
<RowLabel folded={isFolded}>{item.label}</RowLabel>
|
|
717
|
+
{!isFolded && badged ? (
|
|
718
|
+
<RailBadge badge={item.badge as number | string} active={active} />
|
|
719
|
+
) : null}
|
|
622
720
|
</a>
|
|
623
721
|
);
|
|
624
722
|
}
|
|
@@ -633,21 +731,34 @@ export const SidebarDesktop = React.forwardRef<HTMLElement, SidebarDesktopProps>
|
|
|
633
731
|
size="rail"
|
|
634
732
|
aria-expanded={expanded}
|
|
635
733
|
aria-controls={subId}
|
|
636
|
-
aria-label={
|
|
734
|
+
aria-label={
|
|
735
|
+
isFolded || badged
|
|
736
|
+
? rowAccessibleName(item.label, item.badge)
|
|
737
|
+
: undefined
|
|
738
|
+
}
|
|
637
739
|
data-active={active}
|
|
638
740
|
data-folded={isFolded}
|
|
639
741
|
onClick={() => toggleExpanded(item.id)}
|
|
640
|
-
|
|
742
|
+
className="group"
|
|
743
|
+
leadingIcon={railGlyph(item, isFolded)}
|
|
641
744
|
trailingIcon={
|
|
642
745
|
isFolded ? undefined : (
|
|
643
|
-
<span
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
746
|
+
<span className="flex items-center gap-xs">
|
|
747
|
+
{badged ? (
|
|
748
|
+
<RailBadge
|
|
749
|
+
badge={item.badge as number | string}
|
|
750
|
+
active={active}
|
|
751
|
+
/>
|
|
752
|
+
) : null}
|
|
753
|
+
<span
|
|
754
|
+
aria-hidden="true"
|
|
755
|
+
className={cn(
|
|
756
|
+
"flex shrink-0 items-center transition-transform duration-200 ease-out",
|
|
757
|
+
expanded ? "rotate-180" : "rotate-0",
|
|
758
|
+
)}
|
|
759
|
+
>
|
|
760
|
+
{glyph("chevron-down", 16, 2)}
|
|
761
|
+
</span>
|
|
651
762
|
</span>
|
|
652
763
|
)
|
|
653
764
|
}
|
|
@@ -713,6 +824,7 @@ export const SidebarDesktop = React.forwardRef<HTMLElement, SidebarDesktopProps>
|
|
|
713
824
|
<nav aria-label="Secondary" className="mt-lg flex flex-col gap-xxs">
|
|
714
825
|
{secondaryNav.map((item) => {
|
|
715
826
|
const active = item.id === secondaryActiveId;
|
|
827
|
+
const badged = hasBadge(item.badge);
|
|
716
828
|
|
|
717
829
|
return (
|
|
718
830
|
<a
|
|
@@ -720,11 +832,19 @@ export const SidebarDesktop = React.forwardRef<HTMLElement, SidebarDesktopProps>
|
|
|
720
832
|
href={item.href ?? `#${item.id}`}
|
|
721
833
|
onClick={navigate({ id: item.id, href: item.href })}
|
|
722
834
|
aria-current={active ? "page" : undefined}
|
|
723
|
-
|
|
835
|
+
data-active={active}
|
|
836
|
+
aria-label={
|
|
837
|
+
isFolded || badged
|
|
838
|
+
? rowAccessibleName(item.label, item.badge)
|
|
839
|
+
: undefined
|
|
840
|
+
}
|
|
724
841
|
className={railRowClass(active, isFolded)}
|
|
725
842
|
>
|
|
726
|
-
{
|
|
843
|
+
{railGlyph(item, isFolded)}
|
|
727
844
|
<RowLabel folded={isFolded}>{item.label}</RowLabel>
|
|
845
|
+
{!isFolded && badged ? (
|
|
846
|
+
<RailBadge badge={item.badge as number | string} active={active} />
|
|
847
|
+
) : null}
|
|
728
848
|
</a>
|
|
729
849
|
);
|
|
730
850
|
})}
|
|
@@ -33,6 +33,12 @@ export interface SidebarMobileNavItem {
|
|
|
33
33
|
icon: IconName;
|
|
34
34
|
/** Destination for a plain row. */
|
|
35
35
|
href?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Pending-work count painted as a pill after the label. A number (99+
|
|
38
|
+
* collapses), or a short string such as "New". Hidden when undefined, empty,
|
|
39
|
+
* or zero, and always part of the row's accessible name.
|
|
40
|
+
*/
|
|
41
|
+
badge?: number | string;
|
|
36
42
|
/** Nested rows: turns the parent into a disclosure. */
|
|
37
43
|
children?: Array<{ id: string; label: string; href?: string }>;
|
|
38
44
|
}
|
|
@@ -156,6 +162,64 @@ const glyph = (name: IconName, size = 18, strokeWidth = 1.75) => (
|
|
|
156
162
|
<Icon name={name} size={size} strokeWidth={strokeWidth} style={{ color: "inherit" }} />
|
|
157
163
|
);
|
|
158
164
|
|
|
165
|
+
/** True when an item carries a count worth painting. Zero and empties hide. */
|
|
166
|
+
const hasBadge = (badge?: number | string) => {
|
|
167
|
+
if (badge === undefined || badge === null) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (typeof badge === "number") {
|
|
171
|
+
return Number.isFinite(badge) && badge !== 0;
|
|
172
|
+
}
|
|
173
|
+
const trimmed = badge.trim();
|
|
174
|
+
return trimmed.length > 0 && trimmed !== "0";
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/** The pill copy: numbers above 99 collapse so a row never reflows. */
|
|
178
|
+
const badgeText = (badge: number | string) =>
|
|
179
|
+
typeof badge === "number"
|
|
180
|
+
? badge > 99
|
|
181
|
+
? "99+"
|
|
182
|
+
: String(badge)
|
|
183
|
+
: badge.trim();
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The row's accessible name. The count rides along as pending work, so the row
|
|
187
|
+
* announces "Tasks, 2 pending" instead of only its label.
|
|
188
|
+
*/
|
|
189
|
+
const rowAccessibleName = (label: string, badge?: number | string) => {
|
|
190
|
+
if (!hasBadge(badge)) {
|
|
191
|
+
return label;
|
|
192
|
+
}
|
|
193
|
+
return typeof badge === "number"
|
|
194
|
+
? `${label}, ${badge} pending`
|
|
195
|
+
: `${label}, ${badgeText(badge as string)}`;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The count pill that follows a row's label. It wears the brand fill with
|
|
200
|
+
* inverse type on the light drawer, flipped to the inverse fill while the row
|
|
201
|
+
* itself is the selected brand block.
|
|
202
|
+
*/
|
|
203
|
+
const NavBadge = ({
|
|
204
|
+
badge,
|
|
205
|
+
active,
|
|
206
|
+
}: {
|
|
207
|
+
badge: number | string;
|
|
208
|
+
active?: boolean;
|
|
209
|
+
}) => (
|
|
210
|
+
<span
|
|
211
|
+
aria-hidden="true"
|
|
212
|
+
data-active={active || undefined}
|
|
213
|
+
className={cn(
|
|
214
|
+
"ml-auto flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full",
|
|
215
|
+
"bg-primary px-xxs text-caption text-on-primary",
|
|
216
|
+
"data-[active=true]:bg-on-primary data-[active=true]:text-primary",
|
|
217
|
+
)}
|
|
218
|
+
>
|
|
219
|
+
{badgeText(badge)}
|
|
220
|
+
</span>
|
|
221
|
+
);
|
|
222
|
+
|
|
159
223
|
/**
|
|
160
224
|
* A destination row in the drawer. A nav row spans the panel's gutter, so its
|
|
161
225
|
* press is a tint rather than a scale — scaling would pull the fill away from
|
|
@@ -174,8 +238,8 @@ const rowClass = (active: boolean) =>
|
|
|
174
238
|
);
|
|
175
239
|
|
|
176
240
|
/** A nested destination: one step quieter and tighter than its parent, indented
|
|
177
|
-
*
|
|
178
|
-
*
|
|
241
|
+
* onto the parent's label by an invisible glyph-sized spacer rather than a
|
|
242
|
+
* second padding utility. */
|
|
179
243
|
const subRowClass = cn(
|
|
180
244
|
"flex min-h-7 w-full cursor-pointer items-center gap-md rounded-md px-md py-xxs",
|
|
181
245
|
"text-body-sm text-body transition duration-150 ease-out",
|
|
@@ -203,6 +267,10 @@ const isModified = (event: React.MouseEvent) =>
|
|
|
203
267
|
* profile row pinned to the foot of the panel. A row click closes the drawer, so
|
|
204
268
|
* a routed navigation never leaves the panel hanging open behind the new page.
|
|
205
269
|
*
|
|
270
|
+
* A destination may carry a count: it reads as a pill after the label, and the
|
|
271
|
+
* number is part of the row's accessible name. Nothing is painted when the
|
|
272
|
+
* count is absent or zero.
|
|
273
|
+
*
|
|
206
274
|
* The panel stays mounted and travels with `translate-x`, so the close
|
|
207
275
|
* animation is never skipped; it only drops out of the paint once it has
|
|
208
276
|
* finished travelling, and nothing inside can be tabbed while it is off-canvas.
|
|
@@ -557,6 +625,7 @@ export const SidebarMobile = React.forwardRef<HTMLDivElement, SidebarMobileProps
|
|
|
557
625
|
<nav aria-label="Primary" className="mt-md flex flex-col gap-xxs">
|
|
558
626
|
{navItems.map((item) => {
|
|
559
627
|
const active = item.id === activeId;
|
|
628
|
+
const badged = hasBadge(item.badge);
|
|
560
629
|
|
|
561
630
|
if (!item.children?.length) {
|
|
562
631
|
return (
|
|
@@ -565,10 +634,21 @@ export const SidebarMobile = React.forwardRef<HTMLDivElement, SidebarMobileProps
|
|
|
565
634
|
href={item.href ?? `#${item.id}`}
|
|
566
635
|
onClick={navigate({ id: item.id, href: item.href })}
|
|
567
636
|
aria-current={active ? "page" : undefined}
|
|
637
|
+
aria-label={
|
|
638
|
+
badged
|
|
639
|
+
? rowAccessibleName(item.label, item.badge)
|
|
640
|
+
: undefined
|
|
641
|
+
}
|
|
568
642
|
className={rowClass(active)}
|
|
569
643
|
>
|
|
570
644
|
{glyph(item.icon, 18, 1.75)}
|
|
571
645
|
<span className="truncate">{item.label}</span>
|
|
646
|
+
{badged ? (
|
|
647
|
+
<NavBadge
|
|
648
|
+
badge={item.badge as number | string}
|
|
649
|
+
active={active}
|
|
650
|
+
/>
|
|
651
|
+
) : null}
|
|
572
652
|
</a>
|
|
573
653
|
);
|
|
574
654
|
}
|
|
@@ -583,18 +663,32 @@ export const SidebarMobile = React.forwardRef<HTMLDivElement, SidebarMobileProps
|
|
|
583
663
|
size="rail"
|
|
584
664
|
aria-expanded={expanded}
|
|
585
665
|
aria-controls={subId}
|
|
666
|
+
aria-label={
|
|
667
|
+
badged
|
|
668
|
+
? rowAccessibleName(item.label, item.badge)
|
|
669
|
+
: undefined
|
|
670
|
+
}
|
|
586
671
|
data-active={active}
|
|
587
672
|
onClick={() => toggleExpanded(item.id)}
|
|
588
673
|
className="px-md"
|
|
589
674
|
leadingIcon={glyph(item.icon, 18, 1.75)}
|
|
590
675
|
trailingIcon={
|
|
591
|
-
<span
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
676
|
+
<span className="flex items-center gap-xs">
|
|
677
|
+
{badged ? (
|
|
678
|
+
<NavBadge
|
|
679
|
+
badge={item.badge as number | string}
|
|
680
|
+
active={active}
|
|
681
|
+
/>
|
|
682
|
+
) : null}
|
|
683
|
+
<span
|
|
684
|
+
aria-hidden="true"
|
|
685
|
+
className={cn(
|
|
686
|
+
"flex shrink-0 items-center transition-transform duration-200 ease-out",
|
|
687
|
+
expanded ? "rotate-180" : "rotate-0",
|
|
688
|
+
)}
|
|
689
|
+
>
|
|
690
|
+
{glyph("chevron-down", 18, 2)}
|
|
691
|
+
</span>
|
|
598
692
|
</span>
|
|
599
693
|
}
|
|
600
694
|
>
|
|
@@ -659,6 +753,7 @@ export const SidebarMobile = React.forwardRef<HTMLDivElement, SidebarMobileProps
|
|
|
659
753
|
<nav aria-label="Secondary" className="flex flex-col gap-xxs">
|
|
660
754
|
{secondaryNav.map((item) => {
|
|
661
755
|
const active = item.id === secondaryActiveId;
|
|
756
|
+
const badged = hasBadge(item.badge);
|
|
662
757
|
|
|
663
758
|
return (
|
|
664
759
|
<a
|
|
@@ -666,10 +761,21 @@ export const SidebarMobile = React.forwardRef<HTMLDivElement, SidebarMobileProps
|
|
|
666
761
|
href={item.href ?? `#${item.id}`}
|
|
667
762
|
onClick={navigate({ id: item.id, href: item.href })}
|
|
668
763
|
aria-current={active ? "page" : undefined}
|
|
764
|
+
aria-label={
|
|
765
|
+
badged
|
|
766
|
+
? rowAccessibleName(item.label, item.badge)
|
|
767
|
+
: undefined
|
|
768
|
+
}
|
|
669
769
|
className={rowClass(active)}
|
|
670
770
|
>
|
|
671
771
|
{glyph(item.icon, 18, 1.75)}
|
|
672
772
|
<span className="truncate">{item.label}</span>
|
|
773
|
+
{badged ? (
|
|
774
|
+
<NavBadge
|
|
775
|
+
badge={item.badge as number | string}
|
|
776
|
+
active={active}
|
|
777
|
+
/>
|
|
778
|
+
) : null}
|
|
673
779
|
</a>
|
|
674
780
|
);
|
|
675
781
|
})}
|