@whity/ui 0.0.0-stage → 1.0.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 +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -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 +604 -0
- package/src/approval-queue.tsx +109 -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-pattern.ts +138 -0
- package/src/avatar.tsx +125 -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 +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -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/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -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 +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -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/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -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 +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -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 +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -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 +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -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/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -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/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -0
- package/src/plugin-card.tsx +931 -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 +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -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/search-field.tsx +65 -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/stepper.tsx +85 -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/system-state.tsx +55 -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-grid.tsx +163 -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,150 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { IconCheck, IconCopy, IconDeviceDesktop, IconMail } from "@tabler/icons-react"
|
|
5
|
+
|
|
6
|
+
import { Button } from "./button"
|
|
7
|
+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "./sheet"
|
|
8
|
+
import { cn } from "./utils"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Phone web, read-only builders (PwBuilders): the two canvases that are not
|
|
12
|
+
* worth squeezing (a route's flow, a role's permission grid) are read on a
|
|
13
|
+
* phone, and changed on a computer. These are the two parts that say so: a
|
|
14
|
+
* note on why, and a bottom bar whose one button opens a sheet with the link.
|
|
15
|
+
*
|
|
16
|
+
* Domain-free: every word comes in through `labels`, so the app translates.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export interface PhoneReadOnlyNoteProps extends React.ComponentProps<"div"> {
|
|
20
|
+
children: React.ReactNode
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** "You can read this route here. To change it, open it on a computer." */
|
|
24
|
+
function PhoneReadOnlyNote({ className, children, ...props }: PhoneReadOnlyNoteProps) {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
role="note"
|
|
28
|
+
data-slot="phone-read-only-note"
|
|
29
|
+
className={cn(
|
|
30
|
+
"flex items-start gap-3 rounded-card bg-muted px-4 py-3 text-sm text-foreground",
|
|
31
|
+
className
|
|
32
|
+
)}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
<IconDeviceDesktop aria-hidden="true" className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
|
|
36
|
+
<span>{children}</span>
|
|
37
|
+
</div>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface OpenOnComputerLabels {
|
|
42
|
+
/** The button and the sheet's title. */
|
|
43
|
+
open: string
|
|
44
|
+
/** What the sheet says: why the link, and what to do with it. */
|
|
45
|
+
description: string
|
|
46
|
+
copy: string
|
|
47
|
+
copied: string
|
|
48
|
+
email: string
|
|
49
|
+
notNow: string
|
|
50
|
+
close: string
|
|
51
|
+
/** The email's subject line. */
|
|
52
|
+
emailSubject: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface OpenOnComputerBarProps {
|
|
56
|
+
labels: OpenOnComputerLabels
|
|
57
|
+
/** The page to open on the computer. Defaults to this page's address. */
|
|
58
|
+
href?: string
|
|
59
|
+
className?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The bottom bar (phones only) and its sheet. The bar sticks to the bottom of
|
|
64
|
+
* the page's scroll area, which on a phone ends right above the tab bar.
|
|
65
|
+
*
|
|
66
|
+
* "Email me the link" opens the person's own mail app with the link filled in,
|
|
67
|
+
* because the server cannot know which address to send to from here; copying
|
|
68
|
+
* the link is the other way out.
|
|
69
|
+
*/
|
|
70
|
+
function OpenOnComputerBar({ labels, href, className }: OpenOnComputerBarProps) {
|
|
71
|
+
const [open, setOpen] = React.useState(false)
|
|
72
|
+
const [copied, setCopied] = React.useState(false)
|
|
73
|
+
const [link, setLink] = React.useState(href ?? "")
|
|
74
|
+
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
if (href === undefined) setLink(window.location.href)
|
|
77
|
+
}, [href])
|
|
78
|
+
|
|
79
|
+
const copy = async () => {
|
|
80
|
+
try {
|
|
81
|
+
await navigator.clipboard.writeText(link)
|
|
82
|
+
setCopied(true)
|
|
83
|
+
} catch {
|
|
84
|
+
// No clipboard (an insecure origin): the link is shown in full to copy by hand.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const mailto = `mailto:?subject=${encodeURIComponent(labels.emailSubject)}&body=${encodeURIComponent(link)}`
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<div
|
|
93
|
+
data-slot="open-on-computer-bar"
|
|
94
|
+
className={cn(
|
|
95
|
+
"sticky bottom-0 z-10 -mx-4 mt-4 border-t border-border bg-background px-4 py-3 sm:hidden",
|
|
96
|
+
className
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
<Button variant="outline" size="lg" className="min-h-11" onClick={() => setOpen(true)}>
|
|
100
|
+
<IconDeviceDesktop aria-hidden="true" />
|
|
101
|
+
{labels.open}
|
|
102
|
+
</Button>
|
|
103
|
+
</div>
|
|
104
|
+
<Sheet
|
|
105
|
+
open={open}
|
|
106
|
+
onOpenChange={(next) => {
|
|
107
|
+
setOpen(next)
|
|
108
|
+
if (!next) setCopied(false)
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<SheetContent
|
|
112
|
+
side="bottom"
|
|
113
|
+
closeLabel={labels.close}
|
|
114
|
+
className="gap-3 rounded-t-2xl pb-[calc(1.25rem+env(safe-area-inset-bottom))] text-sm"
|
|
115
|
+
data-testid="open-on-computer-sheet"
|
|
116
|
+
>
|
|
117
|
+
<div aria-hidden className="mx-auto h-1 w-10 rounded-full bg-border" />
|
|
118
|
+
<SheetHeader>
|
|
119
|
+
<SheetTitle className="text-lg font-semibold">{labels.open}</SheetTitle>
|
|
120
|
+
<SheetDescription>{labels.description}</SheetDescription>
|
|
121
|
+
</SheetHeader>
|
|
122
|
+
<div className="flex items-center gap-2 rounded-card bg-muted px-3 py-2">
|
|
123
|
+
<span dir="ltr" className="min-w-0 flex-1 break-all font-mono text-xs text-foreground">
|
|
124
|
+
{link}
|
|
125
|
+
</span>
|
|
126
|
+
<Button
|
|
127
|
+
variant="ghost"
|
|
128
|
+
size="icon-lg"
|
|
129
|
+
aria-label={copied ? labels.copied : labels.copy}
|
|
130
|
+
onClick={() => void copy()}
|
|
131
|
+
>
|
|
132
|
+
{copied ? <IconCheck /> : <IconCopy />}
|
|
133
|
+
</Button>
|
|
134
|
+
</div>
|
|
135
|
+
<Button size="lg" className="min-h-11 w-full" asChild>
|
|
136
|
+
<a href={mailto}>
|
|
137
|
+
<IconMail aria-hidden="true" />
|
|
138
|
+
{labels.email}
|
|
139
|
+
</a>
|
|
140
|
+
</Button>
|
|
141
|
+
<Button variant="outline" size="lg" className="min-h-11 w-full" onClick={() => setOpen(false)}>
|
|
142
|
+
{labels.notNow}
|
|
143
|
+
</Button>
|
|
144
|
+
</SheetContent>
|
|
145
|
+
</Sheet>
|
|
146
|
+
</>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { PhoneReadOnlyNote, OpenOnComputerBar }
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "./utils"
|
|
6
|
+
|
|
7
|
+
const ARABIC_INDIC = "٠١٢٣٤٥٦٧٨٩"
|
|
8
|
+
const EXTENDED_INDIC = "۰۱۲۳۴۵۶۷۸۹"
|
|
9
|
+
|
|
10
|
+
/** Western digits only: Arabic-Indic and extended Arabic-Indic digits are converted. */
|
|
11
|
+
function toDigits(raw: string): string {
|
|
12
|
+
return raw
|
|
13
|
+
.replace(/[٠-٩]/g, (d) => String(ARABIC_INDIC.indexOf(d)))
|
|
14
|
+
.replace(/[۰-۹]/g, (d) => String(EXTENDED_INDIC.indexOf(d)))
|
|
15
|
+
.replace(/\D/g, "")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface OtpInputProps {
|
|
19
|
+
label: string
|
|
20
|
+
/** Number of boxes; split in two halves for reading. */
|
|
21
|
+
length?: number
|
|
22
|
+
value?: string
|
|
23
|
+
defaultValue?: string
|
|
24
|
+
onChange?: (value: string) => void
|
|
25
|
+
/** Called once every box is filled. */
|
|
26
|
+
onComplete?: (value: string) => void
|
|
27
|
+
helperText?: string
|
|
28
|
+
/** What went wrong and what to do next. */
|
|
29
|
+
errorText?: string
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
autoFocus?: boolean
|
|
32
|
+
id?: string
|
|
33
|
+
className?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Six boxes for a one-time code (docs/design/components/OtpInput). Typing moves
|
|
38
|
+
* on, Backspace goes back, a pasted code fills every box. The first box asks
|
|
39
|
+
* the browser for SMS autofill. Digits only, always left to right.
|
|
40
|
+
*/
|
|
41
|
+
function OtpInput({
|
|
42
|
+
label,
|
|
43
|
+
length = 6,
|
|
44
|
+
value,
|
|
45
|
+
defaultValue = "",
|
|
46
|
+
onChange,
|
|
47
|
+
onComplete,
|
|
48
|
+
helperText,
|
|
49
|
+
errorText,
|
|
50
|
+
disabled,
|
|
51
|
+
autoFocus,
|
|
52
|
+
id,
|
|
53
|
+
className,
|
|
54
|
+
}: OtpInputProps) {
|
|
55
|
+
const reactId = React.useId()
|
|
56
|
+
const baseId = id ?? reactId
|
|
57
|
+
const [inner, setInner] = React.useState(() => toDigits(defaultValue).slice(0, length))
|
|
58
|
+
const current = (value ?? inner).slice(0, length)
|
|
59
|
+
const refs = React.useRef<Array<HTMLInputElement | null>>([])
|
|
60
|
+
|
|
61
|
+
const commit = (next: string) => {
|
|
62
|
+
const digits = next.slice(0, length)
|
|
63
|
+
if (value === undefined) setInner(digits)
|
|
64
|
+
onChange?.(digits)
|
|
65
|
+
if (digits.length === length) onComplete?.(digits)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const focusAt = (index: number) => refs.current[Math.max(0, Math.min(length - 1, index))]?.focus()
|
|
69
|
+
|
|
70
|
+
const onType = (index: number, raw: string) => {
|
|
71
|
+
const typed = toDigits(raw)
|
|
72
|
+
if (!typed) return
|
|
73
|
+
const before = current.slice(0, index)
|
|
74
|
+
const next = (before + typed + current.slice(index + typed.length)).slice(0, length)
|
|
75
|
+
commit(next)
|
|
76
|
+
focusAt(Math.min(index + typed.length, length - 1))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const onKeyDown = (index: number, event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
80
|
+
if (event.key === "Backspace") {
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
if (current[index]) {
|
|
83
|
+
commit(current.slice(0, index) + current.slice(index + 1))
|
|
84
|
+
} else if (index > 0) {
|
|
85
|
+
commit(current.slice(0, index - 1) + current.slice(index))
|
|
86
|
+
focusAt(index - 1)
|
|
87
|
+
}
|
|
88
|
+
} else if (event.key === "ArrowLeft") {
|
|
89
|
+
event.preventDefault()
|
|
90
|
+
focusAt(index - 1)
|
|
91
|
+
} else if (event.key === "ArrowRight") {
|
|
92
|
+
event.preventDefault()
|
|
93
|
+
focusAt(index + 1)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const onPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
|
|
98
|
+
const pasted = toDigits(event.clipboardData.getData("text"))
|
|
99
|
+
if (!pasted) return
|
|
100
|
+
event.preventDefault()
|
|
101
|
+
commit(pasted.slice(0, length))
|
|
102
|
+
focusAt(Math.min(pasted.length, length - 1))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const half = Math.ceil(length / 2)
|
|
106
|
+
const describedBy = errorText ? `${baseId}-error` : helperText ? `${baseId}-help` : undefined
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div className={cn("space-y-2", className)}>
|
|
110
|
+
<span id={`${baseId}-label`} className="block text-sm font-medium text-foreground">
|
|
111
|
+
{label}
|
|
112
|
+
</span>
|
|
113
|
+
<div dir="ltr" role="group" aria-labelledby={`${baseId}-label`} aria-describedby={describedBy} className="flex items-center justify-center gap-2">
|
|
114
|
+
{Array.from({ length }, (_, index) => (
|
|
115
|
+
<React.Fragment key={index}>
|
|
116
|
+
{index === half && (
|
|
117
|
+
<span aria-hidden="true" className="text-muted-foreground">
|
|
118
|
+
-
|
|
119
|
+
</span>
|
|
120
|
+
)}
|
|
121
|
+
<input
|
|
122
|
+
ref={(node) => {
|
|
123
|
+
refs.current[index] = node
|
|
124
|
+
}}
|
|
125
|
+
type="text"
|
|
126
|
+
inputMode="numeric"
|
|
127
|
+
pattern="[0-9]*"
|
|
128
|
+
autoComplete={index === 0 ? "one-time-code" : "off"}
|
|
129
|
+
maxLength={length}
|
|
130
|
+
disabled={disabled}
|
|
131
|
+
autoFocus={autoFocus && index === 0}
|
|
132
|
+
aria-label={`${label} ${index + 1} / ${length}`}
|
|
133
|
+
aria-invalid={errorText ? true : undefined}
|
|
134
|
+
value={current[index] ?? ""}
|
|
135
|
+
onChange={(event) => onType(index, event.target.value)}
|
|
136
|
+
onKeyDown={(event) => onKeyDown(index, event)}
|
|
137
|
+
onPaste={onPaste}
|
|
138
|
+
onFocus={(event) => event.target.select()}
|
|
139
|
+
className={cn(
|
|
140
|
+
"h-12 w-11 rounded-control border bg-card text-center font-mono text-xl text-foreground outline-none",
|
|
141
|
+
"focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
|
|
142
|
+
errorText ? "border-destructive" : "border-input"
|
|
143
|
+
)}
|
|
144
|
+
/>
|
|
145
|
+
</React.Fragment>
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
{errorText ? (
|
|
149
|
+
<p id={`${baseId}-error`} role="alert" className="text-sm text-destructive">
|
|
150
|
+
{errorText}
|
|
151
|
+
</p>
|
|
152
|
+
) : helperText ? (
|
|
153
|
+
<p id={`${baseId}-help`} className="text-sm text-muted-foreground">
|
|
154
|
+
{helperText}
|
|
155
|
+
</p>
|
|
156
|
+
) : null}
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { OtpInput }
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { IconDownload, IconPlus, IconUsers } from "@tabler/icons-react"
|
|
3
|
+
|
|
4
|
+
import { PageHeader } from "./page-header"
|
|
5
|
+
import { Button } from "./button"
|
|
6
|
+
import { Breadcrumb } from "./breadcrumb"
|
|
7
|
+
import { Badge } from "./badge"
|
|
8
|
+
import { Tabs, TabsList, TabsTrigger } from "./tabs"
|
|
9
|
+
|
|
10
|
+
const meta = {
|
|
11
|
+
title: "Layout/PageHeader",
|
|
12
|
+
component: PageHeader,
|
|
13
|
+
tags: ["autodocs"],
|
|
14
|
+
args: {
|
|
15
|
+
title: "Team Members",
|
|
16
|
+
description: "Manage who has access to this workspace and configure permission roles.",
|
|
17
|
+
},
|
|
18
|
+
} satisfies Meta<typeof PageHeader>
|
|
19
|
+
|
|
20
|
+
export default meta
|
|
21
|
+
type Story = StoryObj<typeof meta>
|
|
22
|
+
|
|
23
|
+
export const Default: Story = {}
|
|
24
|
+
|
|
25
|
+
export const WithAction: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
action: (
|
|
28
|
+
<div className="flex items-center gap-2">
|
|
29
|
+
<Button variant="outline" size="sm">
|
|
30
|
+
<IconDownload className="size-3.5" />
|
|
31
|
+
Export CSV
|
|
32
|
+
</Button>
|
|
33
|
+
<Button size="sm">
|
|
34
|
+
<IconPlus className="size-3.5" />
|
|
35
|
+
Invite Member
|
|
36
|
+
</Button>
|
|
37
|
+
</div>
|
|
38
|
+
),
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const RichHeaderWithIconAndBadge: Story = {
|
|
43
|
+
args: {
|
|
44
|
+
icon: <IconUsers />,
|
|
45
|
+
badge: <Badge variant="secondary">24 Active</Badge>,
|
|
46
|
+
breadcrumb: <Breadcrumb items={[{ label: "Organization", href: "#" }, { label: "Team Members" }]} />,
|
|
47
|
+
action: (
|
|
48
|
+
<Button size="sm">
|
|
49
|
+
<IconPlus className="size-3.5" />
|
|
50
|
+
Invite Member
|
|
51
|
+
</Button>
|
|
52
|
+
),
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const CardVariant: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
variant: "card",
|
|
59
|
+
icon: <IconUsers />,
|
|
60
|
+
badge: <Badge variant="outline">Enterprise</Badge>,
|
|
61
|
+
breadcrumb: <Breadcrumb items={[{ label: "Dashboard", href: "#" }, { label: "Settings" }, { label: "Team" }]} />,
|
|
62
|
+
action: (
|
|
63
|
+
<Button size="sm">
|
|
64
|
+
<IconPlus className="size-3.5" />
|
|
65
|
+
Add Member
|
|
66
|
+
</Button>
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const WithEmbeddedTabs: Story = {
|
|
72
|
+
render: () => (
|
|
73
|
+
<PageHeader
|
|
74
|
+
title="User Management"
|
|
75
|
+
description="View, edit, and audit system users and role permissions."
|
|
76
|
+
icon={<IconUsers />}
|
|
77
|
+
badge={<Badge variant="secondary">v2.4.0</Badge>}
|
|
78
|
+
breadcrumb={<Breadcrumb items={[{ label: "Admin", href: "#" }, { label: "Users" }]} />}
|
|
79
|
+
action={
|
|
80
|
+
<Button size="sm">
|
|
81
|
+
<IconPlus className="size-3.5" />
|
|
82
|
+
New User
|
|
83
|
+
</Button>
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<Tabs defaultValue="all" className="w-full">
|
|
87
|
+
<TabsList>
|
|
88
|
+
<TabsTrigger value="all">All Users</TabsTrigger>
|
|
89
|
+
<TabsTrigger value="admins">Administrators</TabsTrigger>
|
|
90
|
+
<TabsTrigger value="pending">Pending Invites</TabsTrigger>
|
|
91
|
+
</TabsList>
|
|
92
|
+
</Tabs>
|
|
93
|
+
</PageHeader>
|
|
94
|
+
),
|
|
95
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils"
|
|
4
|
+
|
|
5
|
+
export interface PageHeaderProps {
|
|
6
|
+
/**
|
|
7
|
+
* Main page title text or node.
|
|
8
|
+
*/
|
|
9
|
+
title: React.ReactNode
|
|
10
|
+
/**
|
|
11
|
+
* Subtitle or description explaining the page context.
|
|
12
|
+
*/
|
|
13
|
+
description?: React.ReactNode
|
|
14
|
+
/**
|
|
15
|
+
* Optional icon displayed in a rounded container next to the title.
|
|
16
|
+
*/
|
|
17
|
+
icon?: React.ReactNode
|
|
18
|
+
/**
|
|
19
|
+
* Optional status or version badge node displayed next to the title.
|
|
20
|
+
*/
|
|
21
|
+
badge?: React.ReactNode
|
|
22
|
+
/**
|
|
23
|
+
* Action buttons or controls rendered on the right side of the header.
|
|
24
|
+
*/
|
|
25
|
+
action?: React.ReactNode
|
|
26
|
+
/**
|
|
27
|
+
* Breadcrumb navigation trail rendered above the title.
|
|
28
|
+
*/
|
|
29
|
+
breadcrumb?: React.ReactNode
|
|
30
|
+
/**
|
|
31
|
+
* Secondary controls rendered below the header (e.g. tabs, search bar, filters).
|
|
32
|
+
*/
|
|
33
|
+
children?: React.ReactNode
|
|
34
|
+
/**
|
|
35
|
+
* Visual layout style: "default" (clean section with border) or "card" (elevated card container).
|
|
36
|
+
*/
|
|
37
|
+
variant?: "default" | "card"
|
|
38
|
+
className?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function PageHeader({
|
|
42
|
+
title,
|
|
43
|
+
description,
|
|
44
|
+
icon,
|
|
45
|
+
badge,
|
|
46
|
+
action,
|
|
47
|
+
breadcrumb,
|
|
48
|
+
children,
|
|
49
|
+
variant = "default",
|
|
50
|
+
className,
|
|
51
|
+
}: PageHeaderProps) {
|
|
52
|
+
if (variant === "card") {
|
|
53
|
+
return (
|
|
54
|
+
<div
|
|
55
|
+
data-slot="page-header"
|
|
56
|
+
className={cn(
|
|
57
|
+
"mb-6 flex flex-col gap-4 rounded-xl border border-border bg-card p-5 md:p-6 shadow-2xs transition-colors",
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
{breadcrumb && <div className="text-xs text-muted-foreground">{breadcrumb}</div>}
|
|
62
|
+
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
|
63
|
+
<div className="flex items-start gap-3.5 min-w-0">
|
|
64
|
+
{icon && (
|
|
65
|
+
<div className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary shadow-2xs">
|
|
66
|
+
<span className="[&_svg]:size-5">{icon}</span>
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
<div className="flex flex-col gap-1 min-w-0">
|
|
70
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
71
|
+
<h1 className="text-xl md:text-2xl font-semibold tracking-tight text-foreground break-words md:truncate">
|
|
72
|
+
{title}
|
|
73
|
+
</h1>
|
|
74
|
+
{badge && <div className="shrink-0">{badge}</div>}
|
|
75
|
+
</div>
|
|
76
|
+
{description && (
|
|
77
|
+
<p className="text-xs md:text-sm text-muted-foreground leading-relaxed max-w-3xl">
|
|
78
|
+
{description}
|
|
79
|
+
</p>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
{action && <div className="flex min-w-0 flex-wrap items-center gap-2 self-start md:shrink-0 md:self-center">{action}</div>}
|
|
84
|
+
</div>
|
|
85
|
+
{children && <div className="pt-2 border-t border-border/50">{children}</div>}
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div
|
|
92
|
+
data-slot="page-header"
|
|
93
|
+
className={cn("mb-6 flex flex-col gap-3.5 border-b border-border pb-5", className)}
|
|
94
|
+
>
|
|
95
|
+
{breadcrumb && <div className="text-xs text-muted-foreground">{breadcrumb}</div>}
|
|
96
|
+
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
|
97
|
+
<div className="flex items-start gap-3.5 min-w-0">
|
|
98
|
+
{icon && (
|
|
99
|
+
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary shadow-2xs mt-0.5">
|
|
100
|
+
<span className="[&_svg]:size-4.5">{icon}</span>
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
<div className="flex flex-col gap-1 min-w-0">
|
|
104
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
105
|
+
<h1 className="text-xl md:text-2xl font-semibold tracking-tight text-foreground break-words md:truncate">
|
|
106
|
+
{title}
|
|
107
|
+
</h1>
|
|
108
|
+
{badge && <div className="shrink-0">{badge}</div>}
|
|
109
|
+
</div>
|
|
110
|
+
{description && (
|
|
111
|
+
<p className="text-xs md:text-sm text-muted-foreground leading-relaxed max-w-3xl">
|
|
112
|
+
{description}
|
|
113
|
+
</p>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
{action && <div className="flex min-w-0 flex-wrap items-center gap-2 self-start md:shrink-0 md:self-center">{action}</div>}
|
|
118
|
+
</div>
|
|
119
|
+
{children && <div className="pt-2">{children}</div>}
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
|
|
3
|
+
import { PageShell } from "./page-shell"
|
|
4
|
+
|
|
5
|
+
const DemoSidebar = () => (
|
|
6
|
+
<div className="w-56 shrink-0 border-e border-sidebar-border bg-sidebar p-4 text-sm text-sidebar-foreground">
|
|
7
|
+
Sidebar
|
|
8
|
+
</div>
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const DemoTopBar = () => (
|
|
12
|
+
<div className="flex h-12 items-center border-b border-border px-4 text-sm text-foreground">Top bar</div>
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const meta = {
|
|
16
|
+
title: "Layout/PageShell",
|
|
17
|
+
component: PageShell,
|
|
18
|
+
tags: ["autodocs"],
|
|
19
|
+
args: {
|
|
20
|
+
sidebar: <DemoSidebar />,
|
|
21
|
+
className: "h-full min-h-0",
|
|
22
|
+
children: <p className="text-sm text-foreground">Page content goes here.</p>,
|
|
23
|
+
},
|
|
24
|
+
// The shell fills its parent, so every story is framed by a fixed-height box
|
|
25
|
+
// the way a real app viewport frames it.
|
|
26
|
+
decorators: [
|
|
27
|
+
(Story) => (
|
|
28
|
+
<div className="h-80 overflow-hidden rounded-lg border border-border">
|
|
29
|
+
<Story />
|
|
30
|
+
</div>
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
} satisfies Meta<typeof PageShell>
|
|
34
|
+
|
|
35
|
+
export default meta
|
|
36
|
+
type Story = StoryObj<typeof meta>
|
|
37
|
+
|
|
38
|
+
export const Default: Story = {}
|
|
39
|
+
|
|
40
|
+
export const WithTopBar: Story = {
|
|
41
|
+
args: { topBar: <DemoTopBar /> },
|
|
42
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* PRESENTATIONAL application-frame layout only — slots for a sidebar, an
|
|
7
|
+
* optional top bar, and a content region. No auth/redirect/onboarding logic
|
|
8
|
+
* (that's the app-specific route layout wrapping this, e.g.
|
|
9
|
+
* web/app/(protected)/layout.tsx) — this component only owns the chrome
|
|
10
|
+
* arrangement so every client's "logged-in app frame" matches without
|
|
11
|
+
* re-implementing the flex/scroll layout by hand.
|
|
12
|
+
*/
|
|
13
|
+
export interface PageShellProps {
|
|
14
|
+
sidebar: React.ReactNode
|
|
15
|
+
topBar?: React.ReactNode
|
|
16
|
+
children: React.ReactNode
|
|
17
|
+
className?: string
|
|
18
|
+
/** Class applied to the scrollable content region (defaults to standard page padding). */
|
|
19
|
+
contentClassName?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function PageShell({ sidebar, topBar, children, className, contentClassName }: PageShellProps) {
|
|
23
|
+
return (
|
|
24
|
+
<div data-slot="page-shell" className={cn("flex min-h-screen bg-background", className)}>
|
|
25
|
+
{sidebar}
|
|
26
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
27
|
+
{topBar}
|
|
28
|
+
<main className={cn("flex-1 overflow-y-auto p-6", contentClassName)}>{children}</main>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|