@spunto/design-system 0.70.0 → 0.72.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/README.md +9 -0
- package/package.json +1 -1
- package/src/components/sidebar-menus.tsx +211 -0
- package/src/components/sidebar.test.tsx +61 -0
- package/src/components/sidebar.tsx +755 -0
- package/src/components/tasks/index.ts +2 -2
- package/src/components/tasks/machine.tsx +108 -75
- package/src/components/tasks/task-details.tsx +53 -11
- package/src/components/tasks/tasks.test.tsx +39 -1
- package/src/index.ts +43 -0
package/README.md
CHANGED
|
@@ -115,6 +115,15 @@ const nextConfig = { transpilePackages: ["@spunto/design-system"] }
|
|
|
115
115
|
presentational: it never knows what an entry *does*. For what a list can't say (a
|
|
116
116
|
submenu, a checkbox item), compose Base UI directly — that's what `WorkerCard`'s
|
|
117
117
|
`actions` slot is for.
|
|
118
|
+
- _Sidebar_ — the app shell's rail: `SidebarProvider` (open state, ⌘B, cookie, sheet on
|
|
119
|
+
mobile; `mobileCloseKey={pathname}` closes it on navigation) + `Sidebar`
|
|
120
|
+
(`collapsible` offcanvas / icon / none, `variant` sidebar / floating / inset) and its
|
|
121
|
+
parts (`SidebarHeader`/`Content`/`Footer`, `SidebarGroup*`, `SidebarMenu*`,
|
|
122
|
+
`SidebarMenuSub*`, `SidebarTrigger`, `SidebarRail`, `SidebarInset`, `useSidebar`), plus its
|
|
123
|
+
ends: `SidebarBrand` (logo, « Spunto », the product as subtitle), `SidebarOrgSwitcher` (header) and `SidebarUserMenu` (footer: avatar + a menu of entries,
|
|
124
|
+
e.g. account settings and sign out).
|
|
125
|
+
Router-agnostic: a link is `render={<Link />}` on `SidebarMenuButton`. Colors come from
|
|
126
|
+
the `--sidebar*` tokens, so it follows `data-product`.
|
|
118
127
|
- _Sheet_ — `Sheet` (+`SheetTrigger`/`SheetClose`/`SheetContent`/`SheetHeader`/
|
|
119
128
|
`SheetFooter`/`SheetTitle`/`SheetDescription`), the same Base UI dialog entering from
|
|
120
129
|
an edge. `side` (4) decides the edge, `size` (`sm`…`full`) how far it comes in — two
|
package/package.json
CHANGED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { cloneElement, type ReactElement, type ReactNode } from "react"
|
|
4
|
+
import { CheckIcon, ChevronsUpDownIcon, PlusIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../utils"
|
|
7
|
+
import { ActionMenu, type ActionMenuEntry, type ActionMenuLinkRender } from "./action-menu"
|
|
8
|
+
import { SpuntoLogo } from "../brand/spunto-logo"
|
|
9
|
+
import { Avatar, AvatarFallback, AvatarImage } from "./avatar"
|
|
10
|
+
|
|
11
|
+
// The two controls every app puts at the ends of its sidebar: who the workspace is (top) and who
|
|
12
|
+
// is looking at it (bottom). Both are an `ActionMenu` behind a full-width button, so they inherit its
|
|
13
|
+
// contract: entries are data, `href` entries are real anchors, the app's router link comes in through
|
|
14
|
+
// `render.link`, and nothing here knows what an entry does.
|
|
15
|
+
|
|
16
|
+
function Monogram({ name, className }: { name: string; className?: string }) {
|
|
17
|
+
return (
|
|
18
|
+
<span
|
|
19
|
+
className={cn(
|
|
20
|
+
"flex shrink-0 items-center justify-center rounded-md bg-linear-to-br from-primary/25 to-primary/5 font-display font-bold text-primary ring-1 ring-primary/15",
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
aria-hidden
|
|
24
|
+
>
|
|
25
|
+
{name.slice(0, 1).toUpperCase()}
|
|
26
|
+
</span>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SidebarOrg {
|
|
31
|
+
id: string
|
|
32
|
+
name: string
|
|
33
|
+
/** Shown under the name of the current org (`owner`, `admin`…). */
|
|
34
|
+
role?: string
|
|
35
|
+
/** Where picking this org goes. */
|
|
36
|
+
href: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SidebarOrgSwitcherProps {
|
|
40
|
+
orgs: SidebarOrg[]
|
|
41
|
+
/** Id of the org the sidebar is showing. */
|
|
42
|
+
currentId: string
|
|
43
|
+
/** Adds a « New organization » entry under the list. */
|
|
44
|
+
newOrg?: { href: string; label?: string }
|
|
45
|
+
/** Role line when the current org has none. @default "organization" */
|
|
46
|
+
fallbackRole?: string
|
|
47
|
+
render?: { link?: ActionMenuLinkRender }
|
|
48
|
+
className?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The organization at the top of the sidebar: its monogram, name and role, and the list of the
|
|
53
|
+
* others behind it. Meant for `SidebarHeader`.
|
|
54
|
+
*/
|
|
55
|
+
export function SidebarOrgSwitcher({
|
|
56
|
+
orgs,
|
|
57
|
+
currentId,
|
|
58
|
+
newOrg,
|
|
59
|
+
fallbackRole = "organization",
|
|
60
|
+
render,
|
|
61
|
+
className,
|
|
62
|
+
}: SidebarOrgSwitcherProps) {
|
|
63
|
+
const current = orgs.find((o) => o.id === currentId)
|
|
64
|
+
if (!current) return null
|
|
65
|
+
|
|
66
|
+
const items: ActionMenuEntry[] = [
|
|
67
|
+
...orgs.map((org) => ({
|
|
68
|
+
key: org.id,
|
|
69
|
+
href: org.href,
|
|
70
|
+
label: (
|
|
71
|
+
<span className="flex items-center gap-2.5">
|
|
72
|
+
<Monogram name={org.name} className="size-6 text-[10px]" />
|
|
73
|
+
<span className="truncate font-medium">{org.name}</span>
|
|
74
|
+
</span>
|
|
75
|
+
),
|
|
76
|
+
shortcut: org.id === currentId ? <CheckIcon className="size-3.5 text-primary" /> : undefined,
|
|
77
|
+
})),
|
|
78
|
+
newOrg && "separator",
|
|
79
|
+
newOrg && { key: "new-org", href: newOrg.href, icon: PlusIcon, label: newOrg.label ?? "New organization" },
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<ActionMenu
|
|
84
|
+
items={items}
|
|
85
|
+
align="start"
|
|
86
|
+
side="bottom"
|
|
87
|
+
sideOffset={6}
|
|
88
|
+
className="w-60"
|
|
89
|
+
render={render}
|
|
90
|
+
trigger={
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
data-slot="sidebar-org-switcher"
|
|
94
|
+
className={cn(
|
|
95
|
+
"group flex w-full items-center gap-2.5 rounded-md border border-sidebar-border bg-sidebar-accent/40 px-2.5 py-2 text-left outline-none transition-colors hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-sidebar-ring",
|
|
96
|
+
className
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
<Monogram name={current.name} className="size-7 text-xs" />
|
|
100
|
+
<span className="min-w-0 flex-1">
|
|
101
|
+
<span className="block truncate text-[13px] leading-tight font-semibold text-sidebar-foreground">{current.name}</span>
|
|
102
|
+
<span className="mt-0.5 block font-mono text-[9px] leading-tight tracking-[0.16em] text-muted-foreground/60 uppercase">
|
|
103
|
+
{current.role ?? fallbackRole}
|
|
104
|
+
</span>
|
|
105
|
+
</span>
|
|
106
|
+
<ChevronsUpDownIcon className="size-3.5 shrink-0 text-muted-foreground/50" />
|
|
107
|
+
</button>
|
|
108
|
+
}
|
|
109
|
+
/>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SidebarUser {
|
|
114
|
+
name?: string | null
|
|
115
|
+
email?: string | null
|
|
116
|
+
picture?: string | null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SidebarUserMenuProps {
|
|
120
|
+
user: SidebarUser
|
|
121
|
+
/** The menu: account settings, theme, sign out… A destructive last entry is the convention. */
|
|
122
|
+
items: ActionMenuEntry[]
|
|
123
|
+
render?: { link?: ActionMenuLinkRender }
|
|
124
|
+
/** Replaces the default « name / email » block when the sidebar has no room for it. */
|
|
125
|
+
children?: ReactNode
|
|
126
|
+
className?: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The signed-in member at the bottom of the sidebar — avatar, name and email — opening a menu of
|
|
131
|
+
* what they can do with their account. Meant for `SidebarFooter`.
|
|
132
|
+
*/
|
|
133
|
+
export function SidebarUserMenu({ user, items, render, children, className }: SidebarUserMenuProps) {
|
|
134
|
+
const label = user.name || user.email || ""
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<ActionMenu
|
|
138
|
+
items={items}
|
|
139
|
+
align="start"
|
|
140
|
+
side="top"
|
|
141
|
+
sideOffset={6}
|
|
142
|
+
className="w-60"
|
|
143
|
+
render={render}
|
|
144
|
+
trigger={
|
|
145
|
+
<button
|
|
146
|
+
type="button"
|
|
147
|
+
data-slot="sidebar-user-menu"
|
|
148
|
+
className={cn(
|
|
149
|
+
"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-left outline-none transition-colors hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-sidebar-ring data-popup-open:bg-sidebar-accent",
|
|
150
|
+
className
|
|
151
|
+
)}
|
|
152
|
+
>
|
|
153
|
+
<Avatar size="sm" className="shrink-0">
|
|
154
|
+
<AvatarImage src={user.picture ?? undefined} alt="" />
|
|
155
|
+
<AvatarFallback className="bg-primary/15 font-semibold text-primary">{label.slice(0, 2).toUpperCase()}</AvatarFallback>
|
|
156
|
+
</Avatar>
|
|
157
|
+
{children ?? (
|
|
158
|
+
<span className="min-w-0 flex-1">
|
|
159
|
+
<span className="block truncate text-xs leading-none font-medium text-sidebar-foreground">{user.name ?? user.email}</span>
|
|
160
|
+
{user.name && user.email && (
|
|
161
|
+
<span className="mt-1 block truncate text-[11px] text-muted-foreground/70">{user.email}</span>
|
|
162
|
+
)}
|
|
163
|
+
</span>
|
|
164
|
+
)}
|
|
165
|
+
<ChevronsUpDownIcon className="size-3.5 shrink-0 text-muted-foreground/50" />
|
|
166
|
+
</button>
|
|
167
|
+
}
|
|
168
|
+
/>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface SidebarBrandProps {
|
|
173
|
+
/** The product this app is — « Cloud », « CMS », « Lite »… — as the subtitle under the name. */
|
|
174
|
+
product?: string
|
|
175
|
+
/** The company line. @default "Spunto" */
|
|
176
|
+
name?: string
|
|
177
|
+
/** Replaces the default logo (`SpuntoLogo` in the product's colours). */
|
|
178
|
+
logo?: ReactNode
|
|
179
|
+
/** Makes the whole block a link (to the marketing site, the app's home…). */
|
|
180
|
+
href?: string
|
|
181
|
+
/** Renders the link with the app's router link; without it, a plain anchor. */
|
|
182
|
+
render?: (props: { href: string }) => ReactElement
|
|
183
|
+
className?: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The very top of a sidebar: the Spunto mark, « Spunto », and which product this is underneath
|
|
188
|
+
* (`product="Cloud"`, `"CMS"`…) — so every app of the family opens the same way and only the
|
|
189
|
+
* subtitle (and the `data-product` colours) change. Meant for the top of `SidebarHeader`, above the
|
|
190
|
+
* org switcher.
|
|
191
|
+
*/
|
|
192
|
+
export function SidebarBrand({ product, name = "Spunto", logo, href, render, className }: SidebarBrandProps) {
|
|
193
|
+
const content = (
|
|
194
|
+
<>
|
|
195
|
+
{logo ?? <SpuntoLogo tone="product" title={name} className="size-8 shrink-0 rounded-lg ring-1 ring-sidebar-border" />}
|
|
196
|
+
<span className="min-w-0">
|
|
197
|
+
<span className="block truncate font-display text-[15px] leading-none tracking-tight text-sidebar-foreground">{name}</span>
|
|
198
|
+
{product && (
|
|
199
|
+
<span className="mt-1 block truncate font-mono text-[10px] leading-none tracking-[0.18em] text-muted-foreground uppercase">
|
|
200
|
+
{product}
|
|
201
|
+
</span>
|
|
202
|
+
)}
|
|
203
|
+
</span>
|
|
204
|
+
</>
|
|
205
|
+
)
|
|
206
|
+
const classes = cn("flex items-center gap-2.5 px-2 py-1 text-left", className)
|
|
207
|
+
|
|
208
|
+
if (!href) return <div data-slot="sidebar-brand" className={classes}>{content}</div>
|
|
209
|
+
const link = render?.({ href }) ?? <a href={href} />
|
|
210
|
+
return cloneElement(link as ReactElement<Record<string, unknown>>, { "data-slot": "sidebar-brand", className: cn(classes, "outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring rounded-md") }, content)
|
|
211
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, render, screen } from "@testing-library/react"
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest"
|
|
4
|
+
import {
|
|
5
|
+
Sidebar,
|
|
6
|
+
SidebarContent,
|
|
7
|
+
SidebarMenu,
|
|
8
|
+
SidebarMenuButton,
|
|
9
|
+
SidebarMenuItem,
|
|
10
|
+
SidebarProvider,
|
|
11
|
+
useSidebar,
|
|
12
|
+
} from "./sidebar"
|
|
13
|
+
|
|
14
|
+
afterEach(cleanup)
|
|
15
|
+
|
|
16
|
+
function State() {
|
|
17
|
+
const { state, toggleSidebar } = useSidebar()
|
|
18
|
+
return <button onClick={toggleSidebar}>{state}</button>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function App({ cookieName }: { cookieName?: string | null }) {
|
|
22
|
+
return (
|
|
23
|
+
<SidebarProvider cookieName={cookieName}>
|
|
24
|
+
<Sidebar collapsible="none">
|
|
25
|
+
<SidebarContent>
|
|
26
|
+
<SidebarMenu>
|
|
27
|
+
<SidebarMenuItem>
|
|
28
|
+
<SidebarMenuButton isActive render={<a href="/agents" />}>
|
|
29
|
+
Agents
|
|
30
|
+
</SidebarMenuButton>
|
|
31
|
+
</SidebarMenuItem>
|
|
32
|
+
</SidebarMenu>
|
|
33
|
+
</SidebarContent>
|
|
34
|
+
</Sidebar>
|
|
35
|
+
<State />
|
|
36
|
+
</SidebarProvider>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("Sidebar", () => {
|
|
41
|
+
it("renders a menu button as the link it is given", () => {
|
|
42
|
+
render(<App />)
|
|
43
|
+
const link = screen.getByRole("link", { name: "Agents" })
|
|
44
|
+
expect(link.tagName).toBe("A")
|
|
45
|
+
expect(link.hasAttribute("data-active")).toBe(true)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("toggles and remembers the state in its cookie, unless told not to", () => {
|
|
49
|
+
document.cookie = "sidebar_state=; max-age=0"
|
|
50
|
+
render(<App />)
|
|
51
|
+
act(() => screen.getByRole("button", { name: "expanded" }).click())
|
|
52
|
+
expect(screen.getByRole("button", { name: "collapsed" })).toBeTruthy()
|
|
53
|
+
expect(document.cookie).toContain("sidebar_state=false")
|
|
54
|
+
|
|
55
|
+
cleanup()
|
|
56
|
+
document.cookie = "sidebar_state=; max-age=0"
|
|
57
|
+
render(<App cookieName={null} />)
|
|
58
|
+
act(() => screen.getByRole("button", { name: "expanded" }).click())
|
|
59
|
+
expect(document.cookie).not.toContain("sidebar_state")
|
|
60
|
+
})
|
|
61
|
+
})
|