@whity/ui 0.0.0-stage → 0.5.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.
Files changed (169) hide show
  1. package/README.md +107 -3
  2. package/package.json +192 -6
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +302 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +500 -0
  16. package/src/approval-queue.tsx +108 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar.tsx +83 -0
  22. package/src/badge.stories.tsx +105 -0
  23. package/src/badge.tsx +68 -0
  24. package/src/beta-warning.stories.tsx +79 -0
  25. package/src/beta-warning.tsx +189 -0
  26. package/src/bilingual-input.stories.tsx +82 -0
  27. package/src/bilingual-input.tsx +183 -0
  28. package/src/breadcrumb.stories.tsx +51 -0
  29. package/src/breadcrumb.tsx +90 -0
  30. package/src/button.stories.tsx +87 -0
  31. package/src/button.tsx +118 -0
  32. package/src/card.stories.tsx +423 -0
  33. package/src/card.tsx +180 -0
  34. package/src/chart.stories.tsx +66 -0
  35. package/src/chart.tsx +228 -0
  36. package/src/checkbox.stories.tsx +62 -0
  37. package/src/checkbox.tsx +54 -0
  38. package/src/collapsible.stories.tsx +48 -0
  39. package/src/collapsible.tsx +34 -0
  40. package/src/color-card.stories.tsx +61 -0
  41. package/src/color-card.tsx +270 -0
  42. package/src/color-picker.stories.tsx +65 -0
  43. package/src/color-picker.tsx +425 -0
  44. package/src/command-palette.tsx +306 -0
  45. package/src/copy-block.stories.tsx +38 -0
  46. package/src/copy-block.tsx +85 -0
  47. package/src/data-table.stories.tsx +200 -0
  48. package/src/data-table.tsx +1106 -0
  49. package/src/date-picker.stories.tsx +61 -0
  50. package/src/date-picker.tsx +422 -0
  51. package/src/design-cards.stories.tsx +458 -0
  52. package/src/dialog.stories.tsx +48 -0
  53. package/src/dialog.tsx +166 -0
  54. package/src/documents/barcode-svg.stories.tsx +72 -0
  55. package/src/documents/barcode-svg.tsx +79 -0
  56. package/src/dropdown-menu.stories.tsx +77 -0
  57. package/src/dropdown-menu.tsx +271 -0
  58. package/src/editor/behaviour.ts +279 -0
  59. package/src/editor/block-ids.ts +44 -0
  60. package/src/editor/block-list.tsx +101 -0
  61. package/src/editor/block-toolbar.tsx +477 -0
  62. package/src/editor/bubble.tsx +93 -0
  63. package/src/editor/catalogue.ts +103 -0
  64. package/src/editor/collab-rail.tsx +746 -0
  65. package/src/editor/collab.stories.tsx +207 -0
  66. package/src/editor/collab.ts +87 -0
  67. package/src/editor/contract.ts +408 -0
  68. package/src/editor/convert.ts +362 -0
  69. package/src/editor/doc-editor.stories.tsx +98 -0
  70. package/src/editor/doc-editor.tsx +1287 -0
  71. package/src/editor/editor.css +536 -0
  72. package/src/editor/extensions.ts +86 -0
  73. package/src/editor/field-picker.tsx +107 -0
  74. package/src/editor/fields.ts +100 -0
  75. package/src/editor/gutter.tsx +367 -0
  76. package/src/editor/index.ts +22 -0
  77. package/src/editor/label-sheet.tsx +289 -0
  78. package/src/editor/labels.ts +310 -0
  79. package/src/editor/link-tools.tsx +141 -0
  80. package/src/editor/node-views.tsx +450 -0
  81. package/src/editor/page-view.tsx +353 -0
  82. package/src/editor/publish-check.tsx +182 -0
  83. package/src/editor/rich-blocks.stories.tsx +146 -0
  84. package/src/editor/sample.ts +40 -0
  85. package/src/editor/schema-rich.ts +150 -0
  86. package/src/editor/schema.ts +315 -0
  87. package/src/editor/services.tsx +127 -0
  88. package/src/editor/slash.ts +64 -0
  89. package/src/editor/suggesting.ts +372 -0
  90. package/src/editor/suggestions.ts +763 -0
  91. package/src/editor/table-keys.ts +66 -0
  92. package/src/editor/templates.stories.tsx +324 -0
  93. package/src/editor/toolbar.tsx +358 -0
  94. package/src/empty-state.stories.tsx +51 -0
  95. package/src/empty-state.tsx +100 -0
  96. package/src/empty-state.usage-notes.md +30 -0
  97. package/src/form.stories.tsx +112 -0
  98. package/src/form.tsx +176 -0
  99. package/src/globals.css +20 -0
  100. package/src/icon-button.tsx +85 -0
  101. package/src/icon-map.ts +244 -0
  102. package/src/icon.tsx +41 -0
  103. package/src/index.ts +67 -0
  104. package/src/input.stories.tsx +157 -0
  105. package/src/input.tsx +759 -0
  106. package/src/locked-screen.stories.tsx +29 -0
  107. package/src/locked-screen.tsx +61 -0
  108. package/src/mark.tsx +62 -0
  109. package/src/math-text.stories.tsx +33 -0
  110. package/src/math-text.tsx +43 -0
  111. package/src/menu-bar.stories.tsx +198 -0
  112. package/src/menu-bar.tsx +373 -0
  113. package/src/money/currency.ts +230 -0
  114. package/src/page-header.stories.tsx +95 -0
  115. package/src/page-header.tsx +122 -0
  116. package/src/page-shell.stories.tsx +42 -0
  117. package/src/page-shell.tsx +32 -0
  118. package/src/pagination.stories.tsx +45 -0
  119. package/src/pagination.tsx +98 -0
  120. package/src/plugin-card.stories.tsx +180 -0
  121. package/src/plugin-card.tsx +848 -0
  122. package/src/popover.stories.tsx +48 -0
  123. package/src/popover.tsx +55 -0
  124. package/src/radio-group.stories.tsx +26 -0
  125. package/src/radio-group.tsx +44 -0
  126. package/src/route-flow/editor.tsx +1014 -0
  127. package/src/route-flow/model.ts +716 -0
  128. package/src/scope-grant.tsx +139 -0
  129. package/src/screen-too-small.stories.tsx +61 -0
  130. package/src/screen-too-small.tsx +104 -0
  131. package/src/select.stories.tsx +44 -0
  132. package/src/select.tsx +197 -0
  133. package/src/separator.stories.tsx +34 -0
  134. package/src/separator.tsx +34 -0
  135. package/src/sheet.stories.tsx +49 -0
  136. package/src/sheet.tsx +168 -0
  137. package/src/skeleton.stories.tsx +28 -0
  138. package/src/skeleton.tsx +19 -0
  139. package/src/slider.stories.tsx +78 -0
  140. package/src/slider.tsx +300 -0
  141. package/src/spinner.stories.tsx +33 -0
  142. package/src/spinner.tsx +55 -0
  143. package/src/switch.stories.tsx +42 -0
  144. package/src/switch.tsx +41 -0
  145. package/src/switcher.stories.tsx +111 -0
  146. package/src/switcher.tsx +131 -0
  147. package/src/table.stories.tsx +48 -0
  148. package/src/table.tsx +121 -0
  149. package/src/tabs.stories.tsx +74 -0
  150. package/src/tabs.tsx +90 -0
  151. package/src/tag-input.stories.tsx +67 -0
  152. package/src/tag-input.tsx +117 -0
  153. package/src/tenant-logo.tsx +63 -0
  154. package/src/tenant-switcher.stories.tsx +38 -0
  155. package/src/tenant-switcher.tsx +164 -0
  156. package/src/textarea.stories.tsx +27 -0
  157. package/src/textarea.tsx +18 -0
  158. package/src/theme-mode.ts +52 -0
  159. package/src/time-picker.stories.tsx +62 -0
  160. package/src/time-picker.tsx +615 -0
  161. package/src/toggle-group.tsx +138 -0
  162. package/src/tooltip.stories.tsx +43 -0
  163. package/src/tooltip.tsx +73 -0
  164. package/src/top-nav.stories.tsx +58 -0
  165. package/src/top-nav.tsx +324 -0
  166. package/src/undo-bar.tsx +107 -0
  167. package/src/utils.ts +45 -0
  168. package/src/view-toggle.stories.tsx +84 -0
  169. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,163 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { ActorChip } from "./actor-chip"
6
+ import type { ActorKind } from "./avatar"
7
+ import { Icon, type IconName } from "./icon"
8
+ import { cn } from "./utils"
9
+
10
+ /**
11
+ * What agents read, asked and did, as a timeline (docs/design/components/
12
+ * AgentActivity; 15-agents rule 1). `read` is quiet; `propose` is a dashed
13
+ * node, because it has not happened; `approve` is a person's decision; `act`
14
+ * is filled; `error` is red. Every row names its actor; agent rows show the
15
+ * tool they called in mono. `filter` adds chips to show one agent at a time.
16
+ *
17
+ * `extra` renders under a row, e.g. an UndoBar on something still undoable.
18
+ */
19
+
20
+ export type AgentActivityKind = "read" | "propose" | "approve" | "act" | "undo" | "error"
21
+
22
+ export interface AgentActivityItem {
23
+ id: string
24
+ kind: AgentActivityKind
25
+ actor: string
26
+ actorKind?: ActorKind
27
+ onBehalfOf?: string
28
+ text: React.ReactNode
29
+ /**
30
+ * Already formatted ("13:58") by the caller's date display, which honours a
31
+ * workspace that hides dates; empty when it does.
32
+ */
33
+ timeLabel: string
34
+ /** The wire timestamp, for the <time> element and ordering. */
35
+ dateTime?: string
36
+ tool?: string
37
+ extra?: React.ReactNode
38
+ }
39
+
40
+ export interface AgentActivityLabels {
41
+ all?: string
42
+ filter?: string
43
+ for?: string
44
+ }
45
+
46
+ export interface AgentActivityProps {
47
+ items: AgentActivityItem[]
48
+ /** Show chips to narrow the list to one agent (from two agents up). */
49
+ filter?: boolean
50
+ /** Accessible name of the list. */
51
+ label?: string
52
+ labels?: AgentActivityLabels
53
+ className?: string
54
+ }
55
+
56
+ const KIND_ICON: Record<AgentActivityKind, IconName> = {
57
+ read: "view",
58
+ propose: "edit",
59
+ act: "send",
60
+ approve: "check",
61
+ undo: "undo",
62
+ error: "alert",
63
+ }
64
+
65
+ /**
66
+ * The row's time, already formatted by the caller's date display (which
67
+ * returns nothing when the workspace hides dates), so nothing here formats
68
+ * or prints a raw timestamp.
69
+ */
70
+ function ActivityTime({ item }: { item: AgentActivityItem }) {
71
+ const { timeLabel, dateTime } = item
72
+ if (timeLabel === "") return null
73
+ return <time dateTime={dateTime}>{timeLabel}</time>
74
+ }
75
+
76
+ function AgentActivity({ items, filter = false, label = "Agent activity", labels, className }: AgentActivityProps) {
77
+ const L = { all: "All", filter: "Filter by agent", for: "for", ...labels }
78
+ const [agent, setAgent] = React.useState<string | null>(null)
79
+
80
+ const agents = React.useMemo(() => {
81
+ const names: string[] = []
82
+ for (const item of items) {
83
+ if ((item.actorKind ?? "agent") === "agent" && !names.includes(item.actor)) names.push(item.actor)
84
+ }
85
+ return names
86
+ }, [items])
87
+
88
+ const shown = agent ? items.filter((item) => item.actor === agent) : items
89
+
90
+ const list = (
91
+ <ol aria-label={label} className={cn("m-0 grid list-none p-0", !(filter && agents.length > 1) && className)}>
92
+ {shown.map((item) => (
93
+ <li
94
+ key={item.id}
95
+ data-kind={item.kind}
96
+ className="relative grid grid-cols-[24px_1fr] gap-3 pb-4 before:absolute before:start-[11px] before:top-6 before:bottom-0 before:w-px before:bg-border last:before:hidden"
97
+ >
98
+ <span
99
+ aria-hidden="true"
100
+ className={cn(
101
+ "grid size-6 place-items-center rounded-full bg-muted text-muted-foreground",
102
+ item.kind === "act" && "bg-primary text-primary-foreground",
103
+ item.kind === "approve" && "bg-success-tint text-success-text",
104
+ item.kind === "propose" && "border-[1.5px] border-dashed border-brand bg-card text-brand",
105
+ item.kind === "error" && "bg-error-tint text-error-text"
106
+ )}
107
+ >
108
+ <Icon name={KIND_ICON[item.kind]} size={12} />
109
+ </span>
110
+ <div className="grid min-w-0 gap-0.5 pt-px">
111
+ <div className="flex flex-wrap items-center gap-1.5">
112
+ <ActorChip
113
+ kind={item.actorKind ?? "agent"}
114
+ name={item.actor}
115
+ onBehalfOf={item.onBehalfOf}
116
+ labels={{ for: L.for }}
117
+ />
118
+ <span className={cn("text-sm", item.kind === "read" && "text-muted-foreground")}>{item.text}</span>
119
+ </div>
120
+ <div className="flex flex-wrap gap-2 text-muted-foreground tabular-nums">
121
+ <ActivityTime item={item} />
122
+ {item.tool && (
123
+ <code className="rounded-sm bg-muted px-[5px] py-px font-mono text-xs text-foreground">{item.tool}</code>
124
+ )}
125
+ </div>
126
+ {item.extra && <div className="mt-1.5">{item.extra}</div>}
127
+ </div>
128
+ </li>
129
+ ))}
130
+ </ol>
131
+ )
132
+
133
+ if (!filter || agents.length < 2) return list
134
+
135
+ return (
136
+ <div className={cn("grid gap-3", className)}>
137
+ <div role="radiogroup" aria-label={L.filter} className="flex flex-wrap gap-1.5">
138
+ {[null, ...agents].map((name) => {
139
+ const on = agent === name
140
+ return (
141
+ <button
142
+ key={name ?? "_all"}
143
+ type="button"
144
+ role="radio"
145
+ aria-checked={on}
146
+ onClick={() => setAgent(name)}
147
+ className={cn(
148
+ "inline-flex items-center gap-1.5 rounded-full border border-border bg-card px-2.5 py-[3px] text-xs font-medium text-foreground outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring",
149
+ on && "border-primary bg-primary-tint text-primary-tint-foreground hover:bg-primary-tint"
150
+ )}
151
+ >
152
+ {name && <Icon name="robot" size={12} />}
153
+ {name ?? L.all}
154
+ </button>
155
+ )
156
+ })}
157
+ </div>
158
+ {list}
159
+ </div>
160
+ )
161
+ }
162
+
163
+ export { AgentActivity }
@@ -0,0 +1,156 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import * as React from "react"
3
+
4
+ import { ActionProposal } from "./action-proposal"
5
+ import { AgentActivity } from "./agent-activity"
6
+ import { ApprovalQueue, type ApprovalQueueItem } from "./approval-queue"
7
+ import { ScopeGrant, type ScopeGrantMode } from "./scope-grant"
8
+ import { UndoBar } from "./undo-bar"
9
+
10
+ /**
11
+ * The agent collaboration components (WHIT-808) with the cards' example data,
12
+ * for comparing with docs/design/screenshots/<Card>-light.png and -dark.png.
13
+ */
14
+ const meta = {
15
+ title: "Agents/Collaboration",
16
+ parameters: { layout: "padded" },
17
+ } satisfies Meta
18
+
19
+ export default meta
20
+ type Story = StoryObj<typeof meta>
21
+
22
+ const reminders = {
23
+ agent: "Billing assistant",
24
+ onBehalfOf: "Rana",
25
+ title: "Send payment reminders to 12 customers",
26
+ summary: "These invoices are more than 14 days overdue. Each customer gets your standard reminder by email.",
27
+ changes: [
28
+ { label: "Invoices", after: "12 overdue · JOD 4,860" },
29
+ { label: "Status", before: "Overdue", after: "Reminder sent" },
30
+ ],
31
+ scope: ["invoice:read", "invoice:remind"],
32
+ undoWindow: "30 minutes",
33
+ }
34
+
35
+ export const Proposals: Story = {
36
+ render: () => (
37
+ <div style={{ display: "grid", gap: 16, maxWidth: 560 }}>
38
+ <ActionProposal {...reminders} onApprove={() => {}} onDecline={() => {}} onEdit={() => {}} />
39
+ <ActionProposal
40
+ agent="Billing assistant"
41
+ onBehalfOf="Rana"
42
+ title="Mark invoice INV-1042 as paid"
43
+ changes={[{ label: "INV-1042", before: "Unpaid", after: "Paid · JOD 320" }]}
44
+ scope={["invoice:update"]}
45
+ undoWindow="30 minutes"
46
+ status="approved"
47
+ decidedAt="14:02"
48
+ onUndo={() => {}}
49
+ />
50
+ <ActionProposal
51
+ agent="Front desk"
52
+ onBehalfOf="Omar"
53
+ title="Create a quote for Example Hotel"
54
+ changes={[{ label: "Total", after: "JOD 1,240.000" }]}
55
+ scope={["quote:create"]}
56
+ status="declined"
57
+ />
58
+ <ActionProposal
59
+ agent="HR assistant"
60
+ onBehalfOf="Rana"
61
+ title="Approve 2 days of leave for Lina"
62
+ changes={[{ label: "Leave", after: "3–4 Nov 2026" }]}
63
+ scope={["leave:approve"]}
64
+ status="expired"
65
+ onAskAgain={() => {}}
66
+ />
67
+ <ActionProposal
68
+ agent="Billing assistant"
69
+ onBehalfOf="Rana"
70
+ title="Email the October statement to Example Clinic"
71
+ changes={[{ label: "To", after: "clinic@example.jo" }]}
72
+ scope={["statement:send"]}
73
+ status="undone"
74
+ undoneBy="Rana Haddad"
75
+ />
76
+ </div>
77
+ ),
78
+ }
79
+
80
+ function Queue() {
81
+ const items: ApprovalQueueItem[] = [
82
+ { id: "1", ...reminders, onApprove: () => {}, onDecline: () => {}, onEdit: () => {} },
83
+ { id: "2", agent: "HR assistant", onBehalfOf: "Rana", title: "Approve 2 days of leave for Lina", scope: ["leave:approve"] },
84
+ { id: "3", agent: "Front desk", onBehalfOf: "Omar", title: "Create a quote for Example Hotel", scope: ["quote:create"] },
85
+ ]
86
+ const [current, setCurrent] = React.useState("1")
87
+ return <ApprovalQueue items={items} currentId={current} onCurrentChange={setCurrent} />
88
+ }
89
+
90
+ export const ApprovalsQueue: Story = { render: () => <Queue /> }
91
+
92
+ function Scope() {
93
+ const [modes, setModes] = React.useState<Record<string, ScopeGrantMode>>({
94
+ "invoice:read": "allow",
95
+ "invoice:remind": "ask",
96
+ "invoice:void": "off",
97
+ "customer:read": "allow",
98
+ "customer:update": "ask",
99
+ })
100
+ return (
101
+ <ScopeGrant
102
+ agent="Billing assistant"
103
+ onBehalfOf="Rana"
104
+ modes={modes}
105
+ onChange={(key, mode) => setModes({ ...modes, [key]: mode })}
106
+ groups={[
107
+ {
108
+ key: "invoice",
109
+ label: "Invoices",
110
+ actions: [
111
+ { key: "invoice:read", label: "See invoices" },
112
+ { key: "invoice:remind", label: "Send reminders" },
113
+ { key: "invoice:void", label: "Void an invoice" },
114
+ ],
115
+ },
116
+ {
117
+ key: "customer",
118
+ label: "Customers",
119
+ actions: [
120
+ { key: "customer:read", label: "See customers" },
121
+ { key: "customer:update", label: "Edit contact details" },
122
+ ],
123
+ },
124
+ ]}
125
+ />
126
+ )
127
+ }
128
+
129
+ export const Scopes: Story = { render: () => <Scope /> }
130
+
131
+ export const Activity: Story = {
132
+ render: () => (
133
+ <div style={{ display: "grid", gap: 24, maxWidth: 420 }}>
134
+ <AgentActivity
135
+ filter
136
+ items={[
137
+ { id: "1", kind: "read", actor: "Billing assistant", text: "Read 48 open invoices", timeLabel: "13:58", tool: "invoices.list" },
138
+ { id: "2", kind: "propose", actor: "Billing assistant", text: "Asked to send 12 reminders", timeLabel: "13:59", tool: "invoices.remind" },
139
+ { id: "3", kind: "approve", actor: "Rana Haddad", actorKind: "person", text: "Approved INV-1042 as paid", timeLabel: "11:20" },
140
+ {
141
+ id: "4",
142
+ kind: "act",
143
+ actor: "Billing assistant",
144
+ text: "Marked INV-1042 paid",
145
+ timeLabel: "11:20",
146
+ tool: "invoices.update",
147
+ extra: <UndoBar text="Marked INV-1042 paid" remainingLabel="24 minutes" remaining={24} total={30} onUndo={() => {}} />,
148
+ },
149
+ { id: "5", kind: "act", actor: "HR assistant", text: "Recorded leave for Lina", timeLabel: "10:02", tool: "leave.create" },
150
+ ]}
151
+ />
152
+ <UndoBar text="Emailed the statement" state="undone" undoneBy="Rana Haddad" />
153
+ <UndoBar text="Sent 12 reminders" state="expired" />
154
+ </div>
155
+ ),
156
+ }
@@ -0,0 +1,196 @@
1
+ import * as React from "react"
2
+
3
+ import { ActorChip } from "./actor-chip"
4
+ import { Button } from "./button"
5
+ import { Icon, type IconName } from "./icon"
6
+ import { cn } from "./utils"
7
+
8
+ export type AgentRunState = "running" | "waiting" | "done" | "failed"
9
+
10
+ const STATE_ICON: Record<Exclude<AgentRunState, "running">, IconName> = {
11
+ done: "success",
12
+ failed: "error",
13
+ waiting: "clock",
14
+ }
15
+
16
+ const BADGE: Record<AgentRunState, string> = {
17
+ running: "bg-info-tint text-info-text",
18
+ waiting: "bg-info-tint text-info-text",
19
+ done: "bg-success-tint text-success-text",
20
+ failed: "bg-error-tint text-error-text",
21
+ }
22
+
23
+ const DEFAULT_LABELS = {
24
+ running: "Running",
25
+ waiting: "Waiting for approval",
26
+ done: "Done",
27
+ failed: "Failed",
28
+ for: "for",
29
+ review: "Review",
30
+ retry: "Try again",
31
+ stop: "Stop",
32
+ /** "{done} of {total}" */
33
+ of: "{done} of {total}",
34
+ }
35
+
36
+ function Spinner({ className }: { className?: string }) {
37
+ return (
38
+ <span
39
+ aria-hidden="true"
40
+ className={cn(
41
+ "size-2.5 animate-spin rounded-full border-[1.5px] border-current border-e-transparent [animation-duration:2.4s] motion-reduce:animate-none",
42
+ className
43
+ )}
44
+ />
45
+ )
46
+ }
47
+
48
+ /**
49
+ * What an agent is doing now, in plain words (stage 7): Running ("Reading 48
50
+ * open invoices", with progress when the count is known and Stop), Waiting for
51
+ * approval (dashed, with Review, because nothing has happened yet), Done, and
52
+ * Failed (what went wrong and what to do next, with Try again). The agent
53
+ * comes first, then who it acts for, then the action; state is carried by the
54
+ * word and the icon, never colour alone. The reference is docs/design/
55
+ * components/AgentRunStatus (`.wy-run`).
56
+ */
57
+ function AgentRunStatus({
58
+ status,
59
+ agent,
60
+ onBehalfOf,
61
+ title,
62
+ progress,
63
+ detail,
64
+ next,
65
+ time,
66
+ compact = false,
67
+ onStop,
68
+ onReview,
69
+ onRetry,
70
+ actions,
71
+ labels,
72
+ className,
73
+ }: {
74
+ status: AgentRunState
75
+ /** The agent's role name. */
76
+ agent: string
77
+ onBehalfOf?: string
78
+ /** What it is doing or did, e.g. "Reading 48 open invoices". */
79
+ title: React.ReactNode
80
+ progress?: { done: number; total: number }
81
+ detail?: React.ReactNode
82
+ /** For `failed`: what to do next. */
83
+ next?: React.ReactNode
84
+ time?: React.ReactNode
85
+ /** A pill for the top bar or a table cell. */
86
+ compact?: boolean
87
+ onStop?: () => void
88
+ onReview?: () => void
89
+ onRetry?: () => void
90
+ actions?: React.ReactNode
91
+ /** Every string has an English default; pass Arabic here. */
92
+ labels?: Partial<typeof DEFAULT_LABELS>
93
+ className?: string
94
+ }) {
95
+ const L = { ...DEFAULT_LABELS, ...labels }
96
+ const glyph =
97
+ status === "running" ? <Spinner /> : <Icon name={STATE_ICON[status]} size={compact ? 14 : 12} />
98
+
99
+ if (compact) {
100
+ return (
101
+ <span
102
+ role="status"
103
+ data-slot="agent-run-status"
104
+ data-status={status}
105
+ className={cn(
106
+ "inline-flex min-h-7 items-center gap-1.5 rounded-full border border-border bg-card py-1 ps-2 pe-2.5 text-[0.8125rem]",
107
+ status === "running" && "border-transparent bg-primary-tint text-primary-tint-foreground",
108
+ status === "waiting" && "border-dashed border-input [&_svg]:text-muted-foreground",
109
+ status === "done" && "[&_svg]:text-success-text",
110
+ status === "failed" && "border-[color-mix(in_oklab,var(--error-text)_45%,var(--border))] [&_svg]:text-error-text",
111
+ className
112
+ )}
113
+ >
114
+ {glyph}
115
+ <span className="font-medium">{agent}</span>
116
+ <span className="text-muted-foreground">{title}</span>
117
+ </span>
118
+ )
119
+ }
120
+
121
+ const pct = progress && progress.total ? Math.round((100 * progress.done) / progress.total) : null
122
+ return (
123
+ <div
124
+ role={status === "failed" ? "alert" : "status"}
125
+ data-slot="agent-run-status"
126
+ data-status={status}
127
+ className={cn(
128
+ "grid gap-2 rounded-card border border-border bg-card p-4",
129
+ status === "waiting" && "border-dashed border-input",
130
+ status === "failed" && "border-[color-mix(in_oklab,var(--error-text)_45%,var(--border))]",
131
+ className
132
+ )}
133
+ >
134
+ <div className="flex flex-wrap items-center justify-between gap-2">
135
+ <ActorChip kind="agent" name={agent} onBehalfOf={onBehalfOf} labels={{ for: L.for }} />
136
+ <span
137
+ className={cn(
138
+ "inline-flex h-[22px] items-center gap-1 rounded-full px-[9px] text-xs leading-none font-medium whitespace-nowrap",
139
+ BADGE[status]
140
+ )}
141
+ >
142
+ {glyph}
143
+ {L[status]}
144
+ </span>
145
+ </div>
146
+ <div className="text-[0.9375rem] font-semibold">{title}</div>
147
+ {status === "running" && progress && (
148
+ <div className="flex items-center gap-3">
149
+ <div
150
+ role="progressbar"
151
+ aria-valuemin={0}
152
+ aria-valuemax={progress.total}
153
+ aria-valuenow={progress.done}
154
+ aria-label={typeof title === "string" ? title : undefined}
155
+ className="h-1 flex-1 overflow-hidden rounded-[2px] bg-muted"
156
+ >
157
+ <span
158
+ className="block h-full rounded-[2px] bg-primary transition-[width] duration-(--dur-base) ease-out-whity"
159
+ style={{ width: `${pct ?? 0}%` }}
160
+ />
161
+ </div>
162
+ <span className="text-xs whitespace-nowrap text-muted-foreground tabular-nums">
163
+ {L.of.replace("{done}", String(progress.done)).replace("{total}", String(progress.total))}
164
+ </span>
165
+ </div>
166
+ )}
167
+ {detail && <div className="text-[0.8125rem] text-muted-foreground">{detail}</div>}
168
+ {status === "failed" && next && (
169
+ <div className="rounded-control bg-error-tint px-2.5 py-2 text-[0.8125rem] text-foreground">{next}</div>
170
+ )}
171
+ <div className="flex min-h-7 items-center justify-between gap-2">
172
+ <span className="text-xs text-muted-foreground">{time}</span>
173
+ <div className="flex gap-2">
174
+ {status === "running" && onStop && (
175
+ <Button variant="ghost" size="sm" onClick={onStop}>
176
+ {L.stop}
177
+ </Button>
178
+ )}
179
+ {status === "waiting" && onReview && (
180
+ <Button variant="outline" size="sm" onClick={onReview}>
181
+ {L.review}
182
+ </Button>
183
+ )}
184
+ {status === "failed" && onRetry && (
185
+ <Button variant="outline" size="sm" icon="sync" onClick={onRetry}>
186
+ {L.retry}
187
+ </Button>
188
+ )}
189
+ {actions}
190
+ </div>
191
+ </div>
192
+ </div>
193
+ )
194
+ }
195
+
196
+ export { AgentRunStatus }
@@ -0,0 +1,45 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import {
4
+ AlertDialog,
5
+ AlertDialogTrigger,
6
+ AlertDialogContent,
7
+ AlertDialogHeader,
8
+ AlertDialogFooter,
9
+ AlertDialogTitle,
10
+ AlertDialogDescription,
11
+ AlertDialogAction,
12
+ AlertDialogCancel,
13
+ } from "./alert-dialog"
14
+ import { Button } from "./button"
15
+
16
+ const meta = {
17
+ title: "Overlays/AlertDialog",
18
+ component: AlertDialog,
19
+ tags: ["autodocs"],
20
+ } satisfies Meta<typeof AlertDialog>
21
+
22
+ export default meta
23
+ type Story = StoryObj<typeof meta>
24
+
25
+ export const Destructive: Story = {
26
+ render: () => (
27
+ <AlertDialog>
28
+ <AlertDialogTrigger asChild>
29
+ <Button variant="destructive">Delete tenant</Button>
30
+ </AlertDialogTrigger>
31
+ <AlertDialogContent>
32
+ <AlertDialogHeader>
33
+ <AlertDialogTitle>Delete this tenant?</AlertDialogTitle>
34
+ <AlertDialogDescription>
35
+ This permanently removes all data for the tenant. This action cannot be undone.
36
+ </AlertDialogDescription>
37
+ </AlertDialogHeader>
38
+ <AlertDialogFooter>
39
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
40
+ <AlertDialogAction>Delete</AlertDialogAction>
41
+ </AlertDialogFooter>
42
+ </AlertDialogContent>
43
+ </AlertDialog>
44
+ ),
45
+ }