@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.
- package/README.md +107 -3
- package/package.json +192 -6
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +302 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +500 -0
- package/src/approval-queue.tsx +108 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar.tsx +83 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +183 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +118 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/command-palette.tsx +306 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1106 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +422 -0
- package/src/design-cards.stories.tsx +458 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +166 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +101 -0
- package/src/editor/block-toolbar.tsx +477 -0
- package/src/editor/bubble.tsx +93 -0
- package/src/editor/catalogue.ts +103 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +408 -0
- package/src/editor/convert.ts +362 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1287 -0
- package/src/editor/editor.css +536 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-picker.tsx +107 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +367 -0
- package/src/editor/index.ts +22 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +310 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +450 -0
- package/src/editor/page-view.tsx +353 -0
- package/src/editor/publish-check.tsx +182 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/schema-rich.ts +150 -0
- package/src/editor/schema.ts +315 -0
- package/src/editor/services.tsx +127 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +358 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +100 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +244 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +67 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +759 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +61 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/money/currency.ts +230 -0
- package/src/page-header.stories.tsx +95 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/plugin-card.stories.tsx +180 -0
- package/src/plugin-card.tsx +848 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1014 -0
- package/src/route-flow/model.ts +716 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- package/src/view-toggle.tsx +110 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
IconAlertCircle,
|
|
4
|
+
IconAlertTriangle,
|
|
5
|
+
IconArrowRight,
|
|
6
|
+
IconCircleCheck,
|
|
7
|
+
IconFileText,
|
|
8
|
+
IconLock,
|
|
9
|
+
IconSearch,
|
|
10
|
+
IconTools,
|
|
11
|
+
} from "@tabler/icons-react"
|
|
12
|
+
|
|
13
|
+
import { cn } from "./utils"
|
|
14
|
+
import { Button } from "./button"
|
|
15
|
+
import { Input } from "./input"
|
|
16
|
+
import { Badge } from "./badge"
|
|
17
|
+
|
|
18
|
+
export type AccessDeniedVariant =
|
|
19
|
+
| "forbidden"
|
|
20
|
+
| "unauthorized"
|
|
21
|
+
| "not-found"
|
|
22
|
+
| "error"
|
|
23
|
+
| "success"
|
|
24
|
+
| "maintenance"
|
|
25
|
+
|
|
26
|
+
export interface ActionConfig {
|
|
27
|
+
label: string
|
|
28
|
+
onClick?: () => void
|
|
29
|
+
href?: string
|
|
30
|
+
icon?: React.ReactNode
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SearchResultItem {
|
|
34
|
+
id: string
|
|
35
|
+
title: string
|
|
36
|
+
description?: string
|
|
37
|
+
href: string
|
|
38
|
+
category?: string
|
|
39
|
+
icon?: React.ReactNode
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AccessDeniedProps extends Omit<React.ComponentProps<"div">, "title"> {
|
|
43
|
+
/** Visual & semantic state variant. Defaults to "forbidden". */
|
|
44
|
+
variant?: AccessDeniedVariant
|
|
45
|
+
icon?: React.ReactNode
|
|
46
|
+
title?: React.ReactNode
|
|
47
|
+
description: React.ReactNode
|
|
48
|
+
/** Enable an inline site search form (automatically true for "not-found"). */
|
|
49
|
+
showSearch?: boolean
|
|
50
|
+
/** Placeholder text for the search input. */
|
|
51
|
+
searchPlaceholder?: string
|
|
52
|
+
/** Text of the search submit button. Defaults to "Search". */
|
|
53
|
+
searchButtonLabel?: string
|
|
54
|
+
/** Callback fired when search form is submitted or query changes. */
|
|
55
|
+
onSearch?: (query: string) => void
|
|
56
|
+
/** Optional pre-populated or filtered search results list. */
|
|
57
|
+
searchResults?: SearchResultItem[]
|
|
58
|
+
/** Primary action (the one filled, large button on the plane). */
|
|
59
|
+
primaryAction?: ActionConfig | React.ReactNode
|
|
60
|
+
/** Secondary action (rendered as a larger outline button). */
|
|
61
|
+
secondaryAction?: ActionConfig | React.ReactNode
|
|
62
|
+
/** Legacy action slot for custom action rendering. */
|
|
63
|
+
action?: React.ReactNode
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const VARIANT_CONFIGS: Record<
|
|
67
|
+
AccessDeniedVariant,
|
|
68
|
+
{
|
|
69
|
+
title: string
|
|
70
|
+
defaultIcon: React.ReactNode
|
|
71
|
+
iconWrapper: string
|
|
72
|
+
}
|
|
73
|
+
> = {
|
|
74
|
+
forbidden: {
|
|
75
|
+
title: "Access Denied",
|
|
76
|
+
defaultIcon: <IconAlertCircle />,
|
|
77
|
+
iconWrapper: "bg-error-tint text-error-text",
|
|
78
|
+
},
|
|
79
|
+
unauthorized: {
|
|
80
|
+
title: "Authentication Required",
|
|
81
|
+
defaultIcon: <IconLock />,
|
|
82
|
+
iconWrapper: "bg-warning-tint text-warning-text",
|
|
83
|
+
},
|
|
84
|
+
"not-found": {
|
|
85
|
+
title: "Page Not Found",
|
|
86
|
+
defaultIcon: <IconSearch />,
|
|
87
|
+
iconWrapper: "bg-primary-tint text-primary-tint-foreground",
|
|
88
|
+
},
|
|
89
|
+
error: {
|
|
90
|
+
title: "System Error",
|
|
91
|
+
defaultIcon: <IconAlertTriangle />,
|
|
92
|
+
iconWrapper: "bg-error-tint text-error-text",
|
|
93
|
+
},
|
|
94
|
+
success: {
|
|
95
|
+
title: "Action Complete",
|
|
96
|
+
defaultIcon: <IconCircleCheck />,
|
|
97
|
+
iconWrapper: "bg-success-tint text-success-text",
|
|
98
|
+
},
|
|
99
|
+
maintenance: {
|
|
100
|
+
title: "Under Maintenance",
|
|
101
|
+
defaultIcon: <IconTools />,
|
|
102
|
+
iconWrapper: "bg-primary-tint text-primary-tint-foreground",
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function renderAction(
|
|
107
|
+
action: ActionConfig | React.ReactNode,
|
|
108
|
+
defaultButtonVariant: "default" | "outline",
|
|
109
|
+
key: string
|
|
110
|
+
) {
|
|
111
|
+
if (!action) return null
|
|
112
|
+
|
|
113
|
+
if (React.isValidElement(action)) {
|
|
114
|
+
return action
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const config = action as ActionConfig
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Button
|
|
121
|
+
key={key}
|
|
122
|
+
asChild={Boolean(config.href)}
|
|
123
|
+
size="lg"
|
|
124
|
+
variant={defaultButtonVariant}
|
|
125
|
+
onClick={config.onClick}
|
|
126
|
+
>
|
|
127
|
+
{config.href ? (
|
|
128
|
+
<a href={config.href}>
|
|
129
|
+
{config.icon && <span data-icon="inline-start">{config.icon}</span>}
|
|
130
|
+
{config.label}
|
|
131
|
+
</a>
|
|
132
|
+
) : (
|
|
133
|
+
<>
|
|
134
|
+
{config.icon && <span data-icon="inline-start">{config.icon}</span>}
|
|
135
|
+
{config.label}
|
|
136
|
+
</>
|
|
137
|
+
)}
|
|
138
|
+
</Button>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generic full-screen status and permission-denied feedback screen (AccessDenied / StatusPage).
|
|
144
|
+
* Supports semantic variants (forbidden, unauthorized, not-found, error, success, maintenance),
|
|
145
|
+
* integrated site search for Page Not Found (404), live search results list, and matching color larger action buttons.
|
|
146
|
+
*/
|
|
147
|
+
function AccessDenied({
|
|
148
|
+
className,
|
|
149
|
+
variant = "forbidden",
|
|
150
|
+
icon,
|
|
151
|
+
title,
|
|
152
|
+
description,
|
|
153
|
+
showSearch = variant === "not-found",
|
|
154
|
+
searchPlaceholder = "Search site pages, resources, or docs...",
|
|
155
|
+
searchButtonLabel = "Search",
|
|
156
|
+
onSearch,
|
|
157
|
+
searchResults,
|
|
158
|
+
primaryAction,
|
|
159
|
+
secondaryAction,
|
|
160
|
+
action,
|
|
161
|
+
...props
|
|
162
|
+
}: AccessDeniedProps) {
|
|
163
|
+
const [searchQuery, setSearchQuery] = React.useState("")
|
|
164
|
+
const [hasSearched, setHasSearched] = React.useState(false)
|
|
165
|
+
const config = VARIANT_CONFIGS[variant] ?? VARIANT_CONFIGS.forbidden
|
|
166
|
+
const resolvedTitle = title ?? config.title
|
|
167
|
+
const resolvedIcon = icon ?? config.defaultIcon
|
|
168
|
+
|
|
169
|
+
const handleSearchSubmit = (e: React.FormEvent) => {
|
|
170
|
+
e.preventDefault()
|
|
171
|
+
if (searchQuery.trim()) {
|
|
172
|
+
setHasSearched(true)
|
|
173
|
+
if (onSearch) {
|
|
174
|
+
onSearch(searchQuery.trim())
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
180
|
+
const val = e.target.value
|
|
181
|
+
setSearchQuery(val)
|
|
182
|
+
if (!val.trim()) {
|
|
183
|
+
setHasSearched(false)
|
|
184
|
+
} else if (onSearch) {
|
|
185
|
+
onSearch(val)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const activeResults = searchResults ?? []
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div
|
|
193
|
+
data-slot="access-denied"
|
|
194
|
+
data-variant={variant}
|
|
195
|
+
role="alert"
|
|
196
|
+
className={cn(
|
|
197
|
+
"flex min-h-[420px] w-full flex-col items-center justify-center rounded-2xl border border-border bg-card p-8 text-center shadow-xs transition-all",
|
|
198
|
+
className
|
|
199
|
+
)}
|
|
200
|
+
{...props}
|
|
201
|
+
>
|
|
202
|
+
<div
|
|
203
|
+
data-slot="access-denied-icon"
|
|
204
|
+
aria-hidden="true"
|
|
205
|
+
className={cn(
|
|
206
|
+
"mb-5 flex items-center justify-center rounded-full p-4 [&>svg]:size-10 md:[&>svg]:size-12 transition-all",
|
|
207
|
+
config.iconWrapper
|
|
208
|
+
)}
|
|
209
|
+
>
|
|
210
|
+
{resolvedIcon}
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<h2 data-slot="access-denied-title" className="mb-2 text-xl font-semibold tracking-tight text-foreground md:text-2xl">
|
|
214
|
+
{resolvedTitle}
|
|
215
|
+
</h2>
|
|
216
|
+
|
|
217
|
+
<div
|
|
218
|
+
data-slot="access-denied-description"
|
|
219
|
+
className="mb-6 max-w-md text-xs/relaxed text-muted-foreground md:text-sm/relaxed"
|
|
220
|
+
>
|
|
221
|
+
{description}
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
{showSearch && (
|
|
225
|
+
<div className="mb-6 flex w-full max-w-md flex-col gap-3">
|
|
226
|
+
<form onSubmit={handleSearchSubmit} className="flex w-full items-center gap-2">
|
|
227
|
+
<div className="relative flex-1">
|
|
228
|
+
<Input
|
|
229
|
+
type="search"
|
|
230
|
+
placeholder={searchPlaceholder}
|
|
231
|
+
value={searchQuery}
|
|
232
|
+
onChange={handleInputChange}
|
|
233
|
+
className="h-8 text-xs"
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
<Button type="submit" size="default" variant="default">
|
|
237
|
+
<IconSearch data-icon="inline-start" />
|
|
238
|
+
{searchButtonLabel}
|
|
239
|
+
</Button>
|
|
240
|
+
</form>
|
|
241
|
+
|
|
242
|
+
{/* Inline Search Results List */}
|
|
243
|
+
{(activeResults.length > 0 || (hasSearched && searchQuery.trim())) && (
|
|
244
|
+
<div className="flex flex-col gap-2 rounded-xl border border-border/80 bg-muted/30 p-3 text-start transition-all">
|
|
245
|
+
<div className="flex items-center justify-between px-1 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
|
246
|
+
<span>Search Results ({activeResults.length})</span>
|
|
247
|
+
{searchQuery && <span className="normal-case italic opacity-80">"{searchQuery}"</span>}
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
|
+
{activeResults.length > 0 ? (
|
|
251
|
+
<div className="flex flex-col gap-1.5">
|
|
252
|
+
{activeResults.map((result) => (
|
|
253
|
+
<a
|
|
254
|
+
key={result.id}
|
|
255
|
+
href={result.href}
|
|
256
|
+
className="group/res flex items-center justify-between gap-3 rounded-lg border border-border/50 bg-card p-2.5 transition-all hover:border-primary/40 hover:bg-card hover:shadow-2xs active:scale-[0.99]"
|
|
257
|
+
>
|
|
258
|
+
<div className="flex items-start gap-2.5 min-w-0">
|
|
259
|
+
<div className="mt-0.5 shrink-0 text-muted-foreground group-hover/res:text-primary [&_svg]:size-4">
|
|
260
|
+
{result.icon ?? <IconFileText />}
|
|
261
|
+
</div>
|
|
262
|
+
<div className="space-y-0.5 min-w-0">
|
|
263
|
+
<div className="flex items-center gap-2">
|
|
264
|
+
<span className="font-semibold text-xs text-foreground group-hover/res:text-primary truncate">
|
|
265
|
+
{result.title}
|
|
266
|
+
</span>
|
|
267
|
+
{result.category && (
|
|
268
|
+
<Badge variant="outline" className="text-[9px] px-1.5 py-0">
|
|
269
|
+
{result.category}
|
|
270
|
+
</Badge>
|
|
271
|
+
)}
|
|
272
|
+
</div>
|
|
273
|
+
{result.description && (
|
|
274
|
+
<p className="text-[11px] text-muted-foreground truncate">
|
|
275
|
+
{result.description}
|
|
276
|
+
</p>
|
|
277
|
+
)}
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
<IconArrowRight className="size-4 shrink-0 text-muted-foreground/60 transition-transform group-hover/res:translate-x-0.5 group-hover/res:text-primary rtl:rotate-180" />
|
|
281
|
+
</a>
|
|
282
|
+
))}
|
|
283
|
+
</div>
|
|
284
|
+
) : (
|
|
285
|
+
<p className="py-2 text-center text-xs text-muted-foreground">
|
|
286
|
+
No matching pages or resources found for "{searchQuery}".
|
|
287
|
+
</p>
|
|
288
|
+
)}
|
|
289
|
+
</div>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
{(primaryAction || secondaryAction || action) && (
|
|
295
|
+
<div className="flex flex-wrap items-center justify-center gap-3">
|
|
296
|
+
{renderAction(primaryAction, "default", "primary")}
|
|
297
|
+
{renderAction(secondaryAction, "outline", "secondary")}
|
|
298
|
+
{action}
|
|
299
|
+
</div>
|
|
300
|
+
)}
|
|
301
|
+
</div>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { AccessDenied }
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { ActorChip } from "./actor-chip"
|
|
6
|
+
import { Badge } from "./badge"
|
|
7
|
+
import { Button } from "./button"
|
|
8
|
+
import { Icon } from "./icon"
|
|
9
|
+
import { cn } from "./utils"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The approve-before-act card (docs/design/components/ActionProposal; register
|
|
13
|
+
* 7.5a, 5.4, 4.3). A waiting proposal is a loose sheet: dashed and flat,
|
|
14
|
+
* because nothing has happened yet. Approving sets it down on the plane (solid
|
|
15
|
+
* brand edge, 200 ms); declined goes grey with the title struck through;
|
|
16
|
+
* expired goes grey with Ask again; undone is dashed again and says by whom.
|
|
17
|
+
* The plane never sits under something that has not happened.
|
|
18
|
+
*
|
|
19
|
+
* Summary first: the title says what will happen and how much, then at most
|
|
20
|
+
* two changes and "Show all" past three. The footer always names the
|
|
21
|
+
* permissions used and whether, and for how long, it can be undone.
|
|
22
|
+
*
|
|
23
|
+
* Controlled: `status` is whatever the server says. Every visible string is a
|
|
24
|
+
* label with an English default.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export type ActionProposalStatus = "waiting" | "approved" | "declined" | "expired" | "undone"
|
|
28
|
+
|
|
29
|
+
export interface ActionProposalChange {
|
|
30
|
+
label: string
|
|
31
|
+
/** The value now; omitted for something new. */
|
|
32
|
+
before?: React.ReactNode
|
|
33
|
+
after: React.ReactNode
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ActionProposalLabels {
|
|
37
|
+
for?: string
|
|
38
|
+
waiting?: string
|
|
39
|
+
approved?: string
|
|
40
|
+
declined?: string
|
|
41
|
+
expired?: string
|
|
42
|
+
/** `{name}` is who undid it. */
|
|
43
|
+
undoneBy?: string
|
|
44
|
+
undone?: string
|
|
45
|
+
approve?: string
|
|
46
|
+
decline?: string
|
|
47
|
+
edit?: string
|
|
48
|
+
undo?: string
|
|
49
|
+
askAgain?: string
|
|
50
|
+
uses?: string
|
|
51
|
+
reversible?: string
|
|
52
|
+
/** `{window}` is the undo window, e.g. "30 minutes". */
|
|
53
|
+
reversibleFor?: string
|
|
54
|
+
irreversible?: string
|
|
55
|
+
before?: string
|
|
56
|
+
after?: string
|
|
57
|
+
/** `{count}` is the number of changes. */
|
|
58
|
+
showAll?: string
|
|
59
|
+
showLess?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ActionProposalProps {
|
|
63
|
+
/** The agent's role name ("Billing assistant"). */
|
|
64
|
+
agent: string
|
|
65
|
+
/** The person it acts for. */
|
|
66
|
+
onBehalfOf?: string
|
|
67
|
+
title: string
|
|
68
|
+
summary?: React.ReactNode
|
|
69
|
+
changes?: ActionProposalChange[]
|
|
70
|
+
/** The permissions it uses (`resource:action`). */
|
|
71
|
+
scope?: string[]
|
|
72
|
+
/** False when it can't be undone; then there is no undo window. */
|
|
73
|
+
reversible?: boolean
|
|
74
|
+
/** How long it can be undone for, already worded ("30 minutes"). */
|
|
75
|
+
undoWindow?: string
|
|
76
|
+
status?: ActionProposalStatus
|
|
77
|
+
/** When it was decided, already formatted ("14:02"). */
|
|
78
|
+
decidedAt?: string
|
|
79
|
+
undoneBy?: string
|
|
80
|
+
/** Disables the actions while a decision is on its way. */
|
|
81
|
+
busy?: boolean
|
|
82
|
+
onApprove?: () => void
|
|
83
|
+
onDecline?: () => void
|
|
84
|
+
onEdit?: () => void
|
|
85
|
+
onUndo?: () => void
|
|
86
|
+
onAskAgain?: () => void
|
|
87
|
+
labels?: ActionProposalLabels
|
|
88
|
+
className?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const DEFAULT_LABELS: Required<ActionProposalLabels> = {
|
|
92
|
+
for: "for",
|
|
93
|
+
waiting: "Waiting for your approval",
|
|
94
|
+
approved: "Approved",
|
|
95
|
+
declined: "Declined",
|
|
96
|
+
expired: "Expired",
|
|
97
|
+
undoneBy: "Undone by {name}",
|
|
98
|
+
undone: "Undone",
|
|
99
|
+
approve: "Approve",
|
|
100
|
+
decline: "Decline",
|
|
101
|
+
edit: "Edit",
|
|
102
|
+
undo: "Undo",
|
|
103
|
+
askAgain: "Ask again",
|
|
104
|
+
uses: "Uses",
|
|
105
|
+
reversible: "Can be undone",
|
|
106
|
+
reversibleFor: "Can be undone for {window}",
|
|
107
|
+
irreversible: "Can't be undone",
|
|
108
|
+
before: "Now",
|
|
109
|
+
after: "After",
|
|
110
|
+
showAll: "Show all {count} changes",
|
|
111
|
+
showLess: "Show less",
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const NEUTRAL_BADGE = "bg-muted text-muted-foreground"
|
|
115
|
+
|
|
116
|
+
function ActionProposal({
|
|
117
|
+
agent,
|
|
118
|
+
onBehalfOf,
|
|
119
|
+
title,
|
|
120
|
+
summary,
|
|
121
|
+
changes = [],
|
|
122
|
+
scope = [],
|
|
123
|
+
reversible = true,
|
|
124
|
+
undoWindow,
|
|
125
|
+
status = "waiting",
|
|
126
|
+
decidedAt,
|
|
127
|
+
undoneBy,
|
|
128
|
+
busy = false,
|
|
129
|
+
onApprove,
|
|
130
|
+
onDecline,
|
|
131
|
+
onEdit,
|
|
132
|
+
onUndo,
|
|
133
|
+
onAskAgain,
|
|
134
|
+
labels,
|
|
135
|
+
className,
|
|
136
|
+
}: ActionProposalProps) {
|
|
137
|
+
const L = { ...DEFAULT_LABELS, ...labels }
|
|
138
|
+
const [showAll, setShowAll] = React.useState(false)
|
|
139
|
+
const folded = changes.length > 3 && !showAll
|
|
140
|
+
const shown = folded ? changes.slice(0, 2) : changes
|
|
141
|
+
const titleId = React.useId()
|
|
142
|
+
|
|
143
|
+
const badge = {
|
|
144
|
+
waiting: (
|
|
145
|
+
<Badge variant="outline">
|
|
146
|
+
<span aria-hidden="true" className="size-2 rounded-full border-[1.5px] border-dashed border-brand" />
|
|
147
|
+
{L.waiting}
|
|
148
|
+
</Badge>
|
|
149
|
+
),
|
|
150
|
+
approved: (
|
|
151
|
+
<Badge variant="success" icon="check">
|
|
152
|
+
{decidedAt ? `${L.approved} · ${decidedAt}` : L.approved}
|
|
153
|
+
</Badge>
|
|
154
|
+
),
|
|
155
|
+
declined: (
|
|
156
|
+
<Badge icon="close" className={NEUTRAL_BADGE}>
|
|
157
|
+
{L.declined}
|
|
158
|
+
</Badge>
|
|
159
|
+
),
|
|
160
|
+
expired: (
|
|
161
|
+
<Badge icon="clock" className={NEUTRAL_BADGE}>
|
|
162
|
+
{L.expired}
|
|
163
|
+
</Badge>
|
|
164
|
+
),
|
|
165
|
+
undone: (
|
|
166
|
+
<Badge icon="undo" className={NEUTRAL_BADGE}>
|
|
167
|
+
{undoneBy ? L.undoneBy.replace("{name}", undoneBy) : L.undone}
|
|
168
|
+
</Badge>
|
|
169
|
+
),
|
|
170
|
+
}[status]
|
|
171
|
+
|
|
172
|
+
const undoText = !reversible
|
|
173
|
+
? L.irreversible
|
|
174
|
+
: undoWindow
|
|
175
|
+
? L.reversibleFor.replace("{window}", undoWindow)
|
|
176
|
+
: L.reversible
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<article
|
|
180
|
+
data-slot="action-proposal"
|
|
181
|
+
data-status={status}
|
|
182
|
+
aria-labelledby={titleId}
|
|
183
|
+
className={cn(
|
|
184
|
+
"grid max-w-[560px] gap-3 rounded-card border-[1.5px] bg-card p-4 text-card-foreground",
|
|
185
|
+
"transition-[box-shadow,border-color,margin] duration-200 ease-out-whity",
|
|
186
|
+
status === "waiting" && "border-dashed border-brand/60",
|
|
187
|
+
// Set down: solid brand edge on the plane (4.3). The plane never mirrors.
|
|
188
|
+
status === "approved" && "mb-(--plane-offset) ml-(--plane-offset) border-solid border-brand shadow-plane",
|
|
189
|
+
status === "declined" && "border-solid border-border",
|
|
190
|
+
status === "expired" && "border-solid border-border bg-muted",
|
|
191
|
+
status === "undone" && "border-dashed border-input",
|
|
192
|
+
className
|
|
193
|
+
)}
|
|
194
|
+
>
|
|
195
|
+
<header className="flex flex-wrap items-center justify-between gap-2">
|
|
196
|
+
<ActorChip kind="agent" name={agent} onBehalfOf={onBehalfOf} labels={{ for: L.for }} />
|
|
197
|
+
{badge}
|
|
198
|
+
</header>
|
|
199
|
+
<h3
|
|
200
|
+
id={titleId}
|
|
201
|
+
className={cn(
|
|
202
|
+
"m-0 text-base leading-snug font-semibold text-balance",
|
|
203
|
+
(status === "declined" || status === "expired") && "text-muted-foreground",
|
|
204
|
+
status === "declined" && "line-through decoration-1"
|
|
205
|
+
)}
|
|
206
|
+
>
|
|
207
|
+
{title}
|
|
208
|
+
</h3>
|
|
209
|
+
{summary && <p className="m-0 text-sm text-muted-foreground">{summary}</p>}
|
|
210
|
+
{shown.length > 0 && (
|
|
211
|
+
<dl className="m-0 grid overflow-hidden rounded-control border border-divider">
|
|
212
|
+
{shown.map((change, index) => (
|
|
213
|
+
<div
|
|
214
|
+
key={index}
|
|
215
|
+
className="grid grid-cols-[minmax(96px,30%)_1fr] gap-3 border-t border-border px-3 py-2 first:border-t-0"
|
|
216
|
+
>
|
|
217
|
+
<dt className="text-muted-foreground">{change.label}</dt>
|
|
218
|
+
<dd className="m-0 flex min-w-0 flex-wrap items-center gap-1.5 tabular-nums">
|
|
219
|
+
{change.before != null && (
|
|
220
|
+
<>
|
|
221
|
+
<span className="text-muted-foreground line-through">
|
|
222
|
+
<span className="sr-only">{L.before}: </span>
|
|
223
|
+
{change.before}
|
|
224
|
+
</span>
|
|
225
|
+
<Icon name="arrow-right" size={12} className="text-muted-foreground rtl:-scale-x-100" />
|
|
226
|
+
</>
|
|
227
|
+
)}
|
|
228
|
+
<span className="min-w-0 font-semibold break-words">
|
|
229
|
+
{change.before != null && <span className="sr-only">{L.after}: </span>}
|
|
230
|
+
{change.after}
|
|
231
|
+
</span>
|
|
232
|
+
</dd>
|
|
233
|
+
</div>
|
|
234
|
+
))}
|
|
235
|
+
</dl>
|
|
236
|
+
)}
|
|
237
|
+
{changes.length > 3 && (
|
|
238
|
+
<button
|
|
239
|
+
type="button"
|
|
240
|
+
aria-expanded={showAll}
|
|
241
|
+
onClick={() => setShowAll(!showAll)}
|
|
242
|
+
className="justify-self-start border-0 bg-transparent p-0 text-[0.8125rem] font-medium text-primary outline-none focus-visible:underline"
|
|
243
|
+
>
|
|
244
|
+
{showAll ? L.showLess : L.showAll.replace("{count}", String(changes.length))}
|
|
245
|
+
</button>
|
|
246
|
+
)}
|
|
247
|
+
<footer className="flex flex-wrap items-center justify-between gap-3">
|
|
248
|
+
<div className="grid min-w-0 gap-0.5 text-sm text-muted-foreground">
|
|
249
|
+
{scope.length > 0 && (
|
|
250
|
+
<span>
|
|
251
|
+
{L.uses}{" "}
|
|
252
|
+
{scope.map((permission) => (
|
|
253
|
+
<code
|
|
254
|
+
key={permission}
|
|
255
|
+
className="me-1 rounded-sm bg-muted px-[5px] py-px font-mono text-xs text-foreground"
|
|
256
|
+
>
|
|
257
|
+
{permission}
|
|
258
|
+
</code>
|
|
259
|
+
))}
|
|
260
|
+
</span>
|
|
261
|
+
)}
|
|
262
|
+
<span>{undoText}</span>
|
|
263
|
+
</div>
|
|
264
|
+
{status === "waiting" && (
|
|
265
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
266
|
+
{onDecline && (
|
|
267
|
+
<Button variant="ghost" size="sm" disabled={busy} onClick={onDecline}>
|
|
268
|
+
{L.decline}
|
|
269
|
+
</Button>
|
|
270
|
+
)}
|
|
271
|
+
{onEdit && (
|
|
272
|
+
<Button variant="outline" size="sm" disabled={busy} onClick={onEdit}>
|
|
273
|
+
<Icon name="edit" size={16} />
|
|
274
|
+
{L.edit}
|
|
275
|
+
</Button>
|
|
276
|
+
)}
|
|
277
|
+
{onApprove && (
|
|
278
|
+
<Button size="sm" disabled={busy} onClick={onApprove}>
|
|
279
|
+
<Icon name="check" size={16} />
|
|
280
|
+
{L.approve}
|
|
281
|
+
</Button>
|
|
282
|
+
)}
|
|
283
|
+
</div>
|
|
284
|
+
)}
|
|
285
|
+
{status === "approved" && reversible && onUndo && (
|
|
286
|
+
<Button variant="ghost" size="sm" disabled={busy} onClick={onUndo}>
|
|
287
|
+
<Icon name="undo" size={16} />
|
|
288
|
+
{L.undo}
|
|
289
|
+
</Button>
|
|
290
|
+
)}
|
|
291
|
+
{status === "expired" && onAskAgain && (
|
|
292
|
+
<Button variant="outline" size="sm" disabled={busy} onClick={onAskAgain}>
|
|
293
|
+
<Icon name="sync" size={16} />
|
|
294
|
+
{L.askAgain}
|
|
295
|
+
</Button>
|
|
296
|
+
)}
|
|
297
|
+
</footer>
|
|
298
|
+
</article>
|
|
299
|
+
)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export { ActionProposal }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { initials, type ActorKind } from "./avatar"
|
|
2
|
+
import { Icon } from "./icon"
|
|
3
|
+
import { Mark } from "./mark"
|
|
4
|
+
import { cn } from "./utils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Names who did something, on everything an agent did or proposes (stage 7).
|
|
8
|
+
* A person: initials. An agent: the robot face on the tint, a dashed border,
|
|
9
|
+
* its role name and the person it acts "for", because an agent never holds more permission
|
|
10
|
+
* than the person who granted it. The system: the mark. Shape and words carry
|
|
11
|
+
* the difference, never colour alone; a hidden word says which it is. The
|
|
12
|
+
* reference is docs/design/components/ActorChip (`.wy-actor`).
|
|
13
|
+
*/
|
|
14
|
+
function ActorChip({
|
|
15
|
+
kind = "person",
|
|
16
|
+
name,
|
|
17
|
+
onBehalfOf,
|
|
18
|
+
labels,
|
|
19
|
+
className,
|
|
20
|
+
}: {
|
|
21
|
+
kind?: ActorKind
|
|
22
|
+
/** A person's name, or an agent's role name ("Billing assistant"). */
|
|
23
|
+
name: string
|
|
24
|
+
/** For agents: the person it acts for. */
|
|
25
|
+
onBehalfOf?: string
|
|
26
|
+
/** Overrides for every visible and hidden word, e.g. Arabic. */
|
|
27
|
+
labels?: { for?: string; person?: string; agent?: string; system?: string }
|
|
28
|
+
className?: string
|
|
29
|
+
}) {
|
|
30
|
+
const L = { for: "for", person: "person", agent: "agent", system: "system", ...labels }
|
|
31
|
+
return (
|
|
32
|
+
<span
|
|
33
|
+
data-slot="actor-chip"
|
|
34
|
+
data-kind={kind}
|
|
35
|
+
className={cn(
|
|
36
|
+
"inline-flex h-6 max-w-full items-center gap-1.5 rounded-full border border-transparent bg-muted pe-2 text-[0.8125rem] font-medium whitespace-nowrap",
|
|
37
|
+
// An agent's chip is dashed (the ActorChip card); people and the system stay borderless.
|
|
38
|
+
kind === "agent" ? "border-dashed border-input ps-[3px]" : "ps-1",
|
|
39
|
+
className
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
{kind === "agent" ? (
|
|
43
|
+
<span
|
|
44
|
+
aria-hidden="true"
|
|
45
|
+
className="grid size-[18px] shrink-0 place-items-center rounded-full bg-primary-tint text-primary-tint-foreground"
|
|
46
|
+
>
|
|
47
|
+
<Icon name="robot" size={12} />
|
|
48
|
+
</span>
|
|
49
|
+
) : kind === "system" ? (
|
|
50
|
+
<Mark size={16} cut="c16" label="" />
|
|
51
|
+
) : (
|
|
52
|
+
// 11px is the floor (decision 3.5a); the reference card's 10px initials follow it.
|
|
53
|
+
<span
|
|
54
|
+
aria-hidden="true"
|
|
55
|
+
className="grid size-[18px] shrink-0 place-items-center rounded-full bg-card text-2xs leading-none font-semibold text-foreground"
|
|
56
|
+
>
|
|
57
|
+
{initials(name)}
|
|
58
|
+
</span>
|
|
59
|
+
)}
|
|
60
|
+
<span className="truncate">{name}</span>
|
|
61
|
+
{kind === "agent" && onBehalfOf && (
|
|
62
|
+
<span className="font-normal text-muted-foreground">
|
|
63
|
+
{L.for} {onBehalfOf}
|
|
64
|
+
</span>
|
|
65
|
+
)}
|
|
66
|
+
<span className="sr-only"> ({L[kind]})</span>
|
|
67
|
+
</span>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { ActorChip }
|