@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,117 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { IconX } from "@tabler/icons-react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "./utils"
|
|
6
|
+
import { Badge } from "./badge"
|
|
7
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select"
|
|
8
|
+
|
|
9
|
+
/** One selectable option — the API-backed collection this input binds to. */
|
|
10
|
+
export interface TagOption {
|
|
11
|
+
value: string
|
|
12
|
+
label: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TagInputProps {
|
|
16
|
+
id?: string
|
|
17
|
+
/**
|
|
18
|
+
* The full option collection to pick from (already fetched by the caller —
|
|
19
|
+
* this primitive does no data-fetching of its own, matching every other
|
|
20
|
+
* `@whity/ui` input).
|
|
21
|
+
*/
|
|
22
|
+
options: TagOption[]
|
|
23
|
+
/** Selected option values, in selection order. */
|
|
24
|
+
value: string[]
|
|
25
|
+
onChange: (value: string[]) => void
|
|
26
|
+
placeholder?: string
|
|
27
|
+
/** Shown when nothing is selected. Defaults to "No tags selected". */
|
|
28
|
+
emptyLabel?: string
|
|
29
|
+
/**
|
|
30
|
+
* Accessible name for a chip's remove button.
|
|
31
|
+
*
|
|
32
|
+
* A function, not a string, because the tag's name sits INSIDE the
|
|
33
|
+
* phrase and languages put it in different places — a caller given only
|
|
34
|
+
* the word "Remove" could not move it.
|
|
35
|
+
*/
|
|
36
|
+
removeLabel?: (label: string) => string
|
|
37
|
+
disabled?: boolean
|
|
38
|
+
className?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tag/chips multi-select bound to an API-backed collection (WC-532 #7):
|
|
43
|
+
* selected options render as removable chips; an "add" select (reusing the
|
|
44
|
+
* existing single-value `Select`) lists only the NOT-yet-selected options —
|
|
45
|
+
* picking one adds it and the select resets to its placeholder, ready to add
|
|
46
|
+
* another.
|
|
47
|
+
*/
|
|
48
|
+
export function TagInput({
|
|
49
|
+
id,
|
|
50
|
+
options,
|
|
51
|
+
value,
|
|
52
|
+
onChange,
|
|
53
|
+
placeholder = "Add…",
|
|
54
|
+
emptyLabel = "No tags selected",
|
|
55
|
+
removeLabel = (label: string) => `Remove ${label}`,
|
|
56
|
+
disabled = false,
|
|
57
|
+
className,
|
|
58
|
+
}: TagInputProps) {
|
|
59
|
+
const selectedSet = new Set(value)
|
|
60
|
+
const selectedOptions = value
|
|
61
|
+
.map((tagValue) => options.find((option) => option.value === tagValue))
|
|
62
|
+
.filter((option): option is TagOption => option !== undefined)
|
|
63
|
+
const availableOptions = options.filter((option) => !selectedSet.has(option.value))
|
|
64
|
+
|
|
65
|
+
const addTag = (tagValue: string) => {
|
|
66
|
+
if (!selectedSet.has(tagValue)) {
|
|
67
|
+
onChange([...value, tagValue])
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const removeTag = (tagValue: string) => {
|
|
72
|
+
onChange(value.filter((existing) => existing !== tagValue))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div data-slot="tag-input" className={cn("space-y-2", className)}>
|
|
77
|
+
<div className="flex flex-wrap gap-1.5" data-testid="tag-input-chips">
|
|
78
|
+
{selectedOptions.length === 0 ? (
|
|
79
|
+
<span className="text-xs text-muted-foreground">{emptyLabel}</span>
|
|
80
|
+
) : (
|
|
81
|
+
selectedOptions.map((option) => (
|
|
82
|
+
<Badge key={option.value} variant="secondary" className="gap-1 pe-1">
|
|
83
|
+
{option.label}
|
|
84
|
+
{!disabled && (
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
aria-label={removeLabel(option.label)}
|
|
88
|
+
onClick={() => removeTag(option.value)}
|
|
89
|
+
className="rounded-full p-0.5 outline-none hover:bg-muted-foreground/20 focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
90
|
+
>
|
|
91
|
+
<IconX className="size-2.5" />
|
|
92
|
+
</button>
|
|
93
|
+
)}
|
|
94
|
+
</Badge>
|
|
95
|
+
))
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
{!disabled && availableOptions.length > 0 && (
|
|
100
|
+
// Always controlled to "" — there is never a persisted selection here,
|
|
101
|
+
// only a one-shot pick that immediately becomes a chip and resets.
|
|
102
|
+
<Select value="" onValueChange={addTag}>
|
|
103
|
+
<SelectTrigger id={id} aria-label={placeholder} className="w-full">
|
|
104
|
+
<SelectValue placeholder={placeholder} />
|
|
105
|
+
</SelectTrigger>
|
|
106
|
+
<SelectContent>
|
|
107
|
+
{availableOptions.map((option) => (
|
|
108
|
+
<SelectItem key={option.value} value={option.value}>
|
|
109
|
+
{option.label}
|
|
110
|
+
</SelectItem>
|
|
111
|
+
))}
|
|
112
|
+
</SelectContent>
|
|
113
|
+
</Select>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { initials } from "./avatar"
|
|
2
|
+
import { cn } from "./utils"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The slot where a tenant's own brand appears (docs/design/components/TenantLogo):
|
|
6
|
+
* an uploaded logo in a framed square, or the initials on the tenant's main
|
|
7
|
+
* colour (one letter below 32px, two from 32px). Corners are 29% of the size.
|
|
8
|
+
* `showName={false}` keeps only the mark and moves the name to its label.
|
|
9
|
+
* `shape="wide"` shows a wide logo (a wordmark) unframed at `size` high and
|
|
10
|
+
* up to four times as wide; it carries the name, so the name moves to its label.
|
|
11
|
+
*/
|
|
12
|
+
function TenantLogo({
|
|
13
|
+
name,
|
|
14
|
+
src,
|
|
15
|
+
size = 24,
|
|
16
|
+
showName = true,
|
|
17
|
+
shape = "square",
|
|
18
|
+
className,
|
|
19
|
+
}: {
|
|
20
|
+
name: string
|
|
21
|
+
src?: string | null
|
|
22
|
+
size?: number
|
|
23
|
+
showName?: boolean
|
|
24
|
+
shape?: "square" | "wide"
|
|
25
|
+
className?: string
|
|
26
|
+
}) {
|
|
27
|
+
const radius = Math.round(size * 0.29)
|
|
28
|
+
if (src && shape === "wide") {
|
|
29
|
+
return (
|
|
30
|
+
<span data-slot="tenant-logo" data-shape="wide" role="img" aria-label={name} className={cn("inline-flex min-w-0 items-center", className)}>
|
|
31
|
+
<img src={src} alt="" className="block w-auto object-contain" style={{ height: size, maxWidth: size * 4 }} />
|
|
32
|
+
</span>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
<span
|
|
37
|
+
data-slot="tenant-logo"
|
|
38
|
+
role={showName ? undefined : "img"}
|
|
39
|
+
aria-label={showName ? undefined : name}
|
|
40
|
+
className={cn("inline-flex min-w-0 items-center gap-2 text-sm font-semibold text-foreground", className)}
|
|
41
|
+
>
|
|
42
|
+
{src ? (
|
|
43
|
+
<span
|
|
44
|
+
className="grid shrink-0 place-items-center overflow-hidden bg-card shadow-[inset_0_0_0_1px_var(--border)]"
|
|
45
|
+
style={{ width: size, height: size, borderRadius: radius }}
|
|
46
|
+
>
|
|
47
|
+
<img src={src} alt="" className="size-full object-contain" />
|
|
48
|
+
</span>
|
|
49
|
+
) : (
|
|
50
|
+
<span
|
|
51
|
+
aria-hidden="true"
|
|
52
|
+
className="grid shrink-0 place-items-center bg-primary leading-none font-semibold text-primary-foreground"
|
|
53
|
+
style={{ width: size, height: size, borderRadius: radius, fontSize: Math.max(11, Math.round(size * 0.42)) }}
|
|
54
|
+
>
|
|
55
|
+
{initials(name).slice(0, size < 32 ? 1 : 2)}
|
|
56
|
+
</span>
|
|
57
|
+
)}
|
|
58
|
+
{showName && <span className="min-w-0 truncate">{name}</span>}
|
|
59
|
+
</span>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { TenantLogo }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { fn } from "storybook/test"
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { TenantSwitcher, type TenantSwitcherWorkspace } from "./tenant-switcher"
|
|
6
|
+
|
|
7
|
+
const WORKSPACES: TenantSwitcherWorkspace[] = [
|
|
8
|
+
{ id: "1", name: "Example Bakery", role: "Owner" },
|
|
9
|
+
{ id: "2", name: "Example Clinic", role: "Accountant" },
|
|
10
|
+
{ id: "3", name: "Example Hotel", role: "Viewer" },
|
|
11
|
+
{ id: "4", name: "Example Trading", role: "Admin" },
|
|
12
|
+
{ id: "5", name: "Example Office", role: "Accountant" },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const meta = {
|
|
16
|
+
title: "Layout/TenantSwitcher",
|
|
17
|
+
component: TenantSwitcher,
|
|
18
|
+
tags: ["autodocs"],
|
|
19
|
+
args: { workspaces: WORKSPACES, currentId: "1", onChange: fn(), onCreate: fn() },
|
|
20
|
+
decorators: [(Story) => <div style={{ width: 216 }}><Story /></div>],
|
|
21
|
+
} satisfies Meta<typeof TenantSwitcher>
|
|
22
|
+
|
|
23
|
+
export default meta
|
|
24
|
+
type Story = StoryObj<typeof meta>
|
|
25
|
+
|
|
26
|
+
function Controlled({ currentId, onChange, ...props }: React.ComponentProps<typeof TenantSwitcher>) {
|
|
27
|
+
const [current, setCurrent] = React.useState(currentId)
|
|
28
|
+
return <TenantSwitcher {...props} currentId={current} onChange={(id) => { setCurrent(id); onChange(id) }} />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Five workspaces: the search box shows, and "Create workspace" sits at the foot. */
|
|
32
|
+
export const Default: Story = { render: (args) => <Controlled {...args} /> }
|
|
33
|
+
|
|
34
|
+
/** Two workspaces: no search box. */
|
|
35
|
+
export const Few: Story = { args: { workspaces: WORKSPACES.slice(0, 2) }, render: (args) => <Controlled {...args} /> }
|
|
36
|
+
|
|
37
|
+
/** The 56px rail: the logo alone. */
|
|
38
|
+
export const Collapsed: Story = { args: { collapsed: true }, render: (args) => <Controlled {...args} /> }
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { IconCheck, IconPlus, IconSearch, IconSelector } from "@tabler/icons-react"
|
|
5
|
+
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
7
|
+
import { TenantLogo } from "./tenant-logo"
|
|
8
|
+
import { cn } from "./utils"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The workspace switcher at the top of the sidebar (docs/design/components/
|
|
12
|
+
* TenantSwitcher): the current workspace's logo and name, opening a list of
|
|
13
|
+
* every workspace the person belongs to with their role there. A search box
|
|
14
|
+
* appears above more than four; "Create workspace" sits at the foot when the
|
|
15
|
+
* caller passes `onCreate`. The current one is on the tint and ticked (7.3).
|
|
16
|
+
*
|
|
17
|
+
* Presentational: switching (and reloading in the new tenant's brand) is the
|
|
18
|
+
* caller's job. Every visible string is a prop with an English default.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export interface TenantSwitcherWorkspace {
|
|
22
|
+
id: string
|
|
23
|
+
name: string
|
|
24
|
+
/** The person's role in this workspace, shown under its name. */
|
|
25
|
+
role?: string
|
|
26
|
+
logoUrl?: string | null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TenantSwitcherLabels {
|
|
30
|
+
/** Accessible name of the trigger; `{name}` is the current workspace. */
|
|
31
|
+
trigger?: string
|
|
32
|
+
find?: string
|
|
33
|
+
noResults?: string
|
|
34
|
+
create?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TenantSwitcherProps {
|
|
38
|
+
workspaces: TenantSwitcherWorkspace[]
|
|
39
|
+
currentId?: string
|
|
40
|
+
onChange: (id: string) => void
|
|
41
|
+
onCreate?: () => void
|
|
42
|
+
/** The 56px rail: the logo alone, with the name as its label. */
|
|
43
|
+
collapsed?: boolean
|
|
44
|
+
disabled?: boolean
|
|
45
|
+
labels?: TenantSwitcherLabels
|
|
46
|
+
className?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const SEARCH_FROM = 5
|
|
50
|
+
|
|
51
|
+
function TenantSwitcher({
|
|
52
|
+
workspaces,
|
|
53
|
+
currentId,
|
|
54
|
+
onChange,
|
|
55
|
+
onCreate,
|
|
56
|
+
collapsed = false,
|
|
57
|
+
disabled = false,
|
|
58
|
+
labels = {},
|
|
59
|
+
className,
|
|
60
|
+
}: TenantSwitcherProps) {
|
|
61
|
+
const [open, setOpen] = React.useState(false)
|
|
62
|
+
const [query, setQuery] = React.useState("")
|
|
63
|
+
const current = workspaces.find((workspace) => workspace.id === currentId) ?? workspaces[0]
|
|
64
|
+
const name = current?.name ?? ""
|
|
65
|
+
const triggerLabel = (labels.trigger ?? "Switch workspace, current: {name}").replace("{name}", name)
|
|
66
|
+
|
|
67
|
+
const normalized = query.trim().toLocaleLowerCase()
|
|
68
|
+
const shown = normalized === ""
|
|
69
|
+
? workspaces
|
|
70
|
+
: workspaces.filter((workspace) => workspace.name.toLocaleLowerCase().includes(normalized))
|
|
71
|
+
|
|
72
|
+
const choose = (id: string) => {
|
|
73
|
+
setOpen(false)
|
|
74
|
+
setQuery("")
|
|
75
|
+
if (id !== current?.id) onChange(id)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Popover open={open} onOpenChange={(next) => { setOpen(next); if (!next) setQuery("") }}>
|
|
80
|
+
<PopoverTrigger asChild>
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
data-slot="tenant-switcher"
|
|
84
|
+
disabled={disabled}
|
|
85
|
+
aria-label={triggerLabel}
|
|
86
|
+
title={collapsed ? name : undefined}
|
|
87
|
+
className={cn(
|
|
88
|
+
"flex min-h-10 w-full items-center gap-2 rounded-control-lg border border-border bg-card px-2 py-1.5 text-start text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
89
|
+
collapsed && "w-10 justify-center px-0",
|
|
90
|
+
className
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
<TenantLogo name={name} src={current?.logoUrl} size={22} showName={!collapsed} className="flex-1" />
|
|
94
|
+
{!collapsed && <IconSelector aria-hidden="true" className="size-4 shrink-0 text-muted-foreground" />}
|
|
95
|
+
</button>
|
|
96
|
+
</PopoverTrigger>
|
|
97
|
+
<PopoverContent
|
|
98
|
+
align="start"
|
|
99
|
+
side={collapsed ? "right" : "bottom"}
|
|
100
|
+
className="w-72 gap-0 p-1"
|
|
101
|
+
>
|
|
102
|
+
{workspaces.length >= SEARCH_FROM && (
|
|
103
|
+
<div className="-mx-1 -mt-1 mb-1 flex items-center gap-1.5 border-b border-divider px-3 py-1.5 text-muted-foreground">
|
|
104
|
+
<IconSearch aria-hidden="true" className="size-4 shrink-0" />
|
|
105
|
+
<input
|
|
106
|
+
type="search"
|
|
107
|
+
autoFocus
|
|
108
|
+
value={query}
|
|
109
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
110
|
+
placeholder={labels.find ?? "Find a workspace"}
|
|
111
|
+
aria-label={labels.find ?? "Find a workspace"}
|
|
112
|
+
className="h-7 min-w-0 flex-1 border-0 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
<ul role="listbox" aria-label={labels.find ?? "Find a workspace"} className="grid gap-px">
|
|
117
|
+
{shown.map((workspace) => {
|
|
118
|
+
const selected = workspace.id === current?.id
|
|
119
|
+
return (
|
|
120
|
+
<li key={workspace.id} role="option" aria-selected={selected}>
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
onClick={() => choose(workspace.id)}
|
|
124
|
+
className={cn(
|
|
125
|
+
"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start outline-none hover:bg-muted focus-visible:bg-muted",
|
|
126
|
+
selected && "bg-primary-tint text-primary-tint-foreground hover:bg-primary-tint focus-visible:bg-primary-tint"
|
|
127
|
+
)}
|
|
128
|
+
>
|
|
129
|
+
<TenantLogo name={workspace.name} src={workspace.logoUrl} size={24} showName={false} />
|
|
130
|
+
<span className="min-w-0 flex-1">
|
|
131
|
+
<span className={cn("block truncate text-sm", selected ? "text-primary-tint-foreground" : "text-foreground")}>
|
|
132
|
+
{workspace.name}
|
|
133
|
+
</span>
|
|
134
|
+
{workspace.role && (
|
|
135
|
+
<span className="block truncate text-xs text-muted-foreground">{workspace.role}</span>
|
|
136
|
+
)}
|
|
137
|
+
</span>
|
|
138
|
+
{selected && <IconCheck aria-hidden="true" className="size-4 shrink-0" />}
|
|
139
|
+
</button>
|
|
140
|
+
</li>
|
|
141
|
+
)
|
|
142
|
+
})}
|
|
143
|
+
</ul>
|
|
144
|
+
{shown.length === 0 && (
|
|
145
|
+
<p className="px-2 py-2 text-sm text-muted-foreground">{labels.noResults ?? "No workspace matches"}</p>
|
|
146
|
+
)}
|
|
147
|
+
{onCreate && (
|
|
148
|
+
<div className="-mx-1 mt-1 border-t border-divider px-1 pt-1">
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
onClick={() => { setOpen(false); onCreate() }}
|
|
152
|
+
className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-start text-sm text-foreground outline-none hover:bg-muted focus-visible:bg-muted"
|
|
153
|
+
>
|
|
154
|
+
<IconPlus aria-hidden="true" className="size-4 shrink-0 text-muted-foreground" />
|
|
155
|
+
{labels.create ?? "Create workspace"}
|
|
156
|
+
</button>
|
|
157
|
+
</div>
|
|
158
|
+
)}
|
|
159
|
+
</PopoverContent>
|
|
160
|
+
</Popover>
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { TenantSwitcher }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
|
|
3
|
+
import { Textarea } from "./textarea"
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Primitives/Textarea",
|
|
7
|
+
component: Textarea,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
args: { placeholder: "Write a note…" },
|
|
10
|
+
} satisfies Meta<typeof Textarea>
|
|
11
|
+
|
|
12
|
+
export default meta
|
|
13
|
+
type Story = StoryObj<typeof meta>
|
|
14
|
+
|
|
15
|
+
export const Playground: Story = {
|
|
16
|
+
render: (args) => <Textarea {...args} className="w-80" />,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const States: Story = {
|
|
20
|
+
render: () => (
|
|
21
|
+
<div className="flex w-80 flex-col gap-3">
|
|
22
|
+
<Textarea placeholder="Default" />
|
|
23
|
+
<Textarea placeholder="Disabled" disabled />
|
|
24
|
+
<Textarea aria-invalid defaultValue="Something is wrong here" />
|
|
25
|
+
</div>
|
|
26
|
+
),
|
|
27
|
+
}
|
package/src/textarea.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils"
|
|
4
|
+
|
|
5
|
+
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
6
|
+
return (
|
|
7
|
+
<textarea
|
|
8
|
+
data-slot="textarea"
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex min-h-[80px] w-full rounded-control border border-input bg-card px-3 py-2 text-sm transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-xs/relaxed dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { Textarea }
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared theme-mode contract every Whity client (web, desktop, Flutter)
|
|
3
|
+
* must follow for a toggle built in one client to look identical in another:
|
|
4
|
+
*
|
|
5
|
+
* - Strategy: a `.dark` class on the root element (`<html>` on web) — the
|
|
6
|
+
* exact selector `@custom-variant dark (&:is(.dark *));` (see
|
|
7
|
+
* @whity/tokens/css) and every `.dark { ... }` token block target.
|
|
8
|
+
* No class means light mode.
|
|
9
|
+
* - Persistence key: `whity.theme`, storing the raw preference —
|
|
10
|
+
* 'light' | 'dark' | 'system' — not the resolved value.
|
|
11
|
+
* - Default preference: 'system' (resolved against the OS/platform
|
|
12
|
+
* light-dark setting) when nothing is stored yet.
|
|
13
|
+
* - FOUC: a resolved-then-corrected color scheme is highly visible (a white
|
|
14
|
+
* flash for a dark-mode user), so the class must be applied synchronously
|
|
15
|
+
* before first paint — see buildThemeInitScript() below for the web
|
|
16
|
+
* version of that blocking step. A native client (desktop, Flutter)
|
|
17
|
+
* should apply the equivalent of resolveIsDark() as early as its own
|
|
18
|
+
* platform allows (e.g. before the first frame is composited).
|
|
19
|
+
*
|
|
20
|
+
* This module is the framework-agnostic (no React) half of the contract, so
|
|
21
|
+
* it can be imported by both the React provider (web/lib/theme-mode-context.tsx)
|
|
22
|
+
* and any other JS/TS client without pulling React in. Non-JS clients
|
|
23
|
+
* (Flutter) can't import this file directly — they must replicate the same
|
|
24
|
+
* key, values, and resolution rule by hand.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export type ThemeModePreference = 'light' | 'dark' | 'system';
|
|
28
|
+
export type ResolvedThemeMode = 'light' | 'dark';
|
|
29
|
+
|
|
30
|
+
export const THEME_STORAGE_KEY = 'whity.theme';
|
|
31
|
+
|
|
32
|
+
export function isThemeModePreference(value: unknown): value is ThemeModePreference {
|
|
33
|
+
return value === 'light' || value === 'dark' || value === 'system';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Resolve a stored preference (or its absence) against the OS/platform preference. */
|
|
37
|
+
export function resolveIsDark(preference: ThemeModePreference | null | undefined, systemPrefersDark: boolean): boolean {
|
|
38
|
+
return preference === 'dark' || (preference !== 'light' && systemPrefersDark);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Source for a blocking `<script>` that must run as early as possible in
|
|
43
|
+
* `<head>` (before any stylesheet / styled content) so `.dark` lands on
|
|
44
|
+
* `<html>` before the browser's first paint. Kept as a standalone string
|
|
45
|
+
* (rather than a function reference) since it has to execute before any
|
|
46
|
+
* bundle code — see web/lib/theme-mode-context.tsx's ThemeModeInitScript for
|
|
47
|
+
* the actual `<script>` element.
|
|
48
|
+
*/
|
|
49
|
+
export function buildThemeInitScript(): string {
|
|
50
|
+
const key = JSON.stringify(THEME_STORAGE_KEY);
|
|
51
|
+
return `(function(){try{var k=${key};var s=localStorage.getItem(k);var d=s==='dark'||(s!=='light'&&window.matchMedia('(prefers-color-scheme: dark)').matches);document.documentElement.classList.toggle('dark',d);}catch(e){}})();`;
|
|
52
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "./utils"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A day's time grid (docs/design/components/TplAppointments; `.wk-cal`,
|
|
9
|
+
* `.wk-appt`, `.wk-now` in bundle.css), for Appointments and the calendar.
|
|
10
|
+
*
|
|
11
|
+
* Columns are people and rooms; each block sits at its time. Booked is blue,
|
|
12
|
+
* checked in green, a request dashed amber ("needs your OK": not happened yet),
|
|
13
|
+
* blocked time grey. A red line marks now. Times are "HH:MM" in the day's own
|
|
14
|
+
* clock and always show in Western digits, left to right.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type TimeBlockState = "booked" | "checked-in" | "request" | "blocked"
|
|
18
|
+
|
|
19
|
+
export interface TimeGridColumn {
|
|
20
|
+
id: string
|
|
21
|
+
/** The column head: a person (Avatar and name) or a room. */
|
|
22
|
+
header: React.ReactNode
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TimeBlock {
|
|
26
|
+
id: string
|
|
27
|
+
column: string
|
|
28
|
+
/** "HH:MM". */
|
|
29
|
+
start: string
|
|
30
|
+
end: string
|
|
31
|
+
title: React.ReactNode
|
|
32
|
+
detail?: React.ReactNode
|
|
33
|
+
state?: TimeBlockState
|
|
34
|
+
onOpen?: () => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TimeGridProps {
|
|
38
|
+
columns: TimeGridColumn[]
|
|
39
|
+
blocks: TimeBlock[]
|
|
40
|
+
/** First and last whole hours shown. */
|
|
41
|
+
startHour?: number
|
|
42
|
+
endHour?: number
|
|
43
|
+
/** Pixels per hour. */
|
|
44
|
+
hourHeight?: number
|
|
45
|
+
/** "HH:MM", when today is shown. */
|
|
46
|
+
now?: string
|
|
47
|
+
/** The grid's accessible name ("Sunday 8 November, Abdoun branch"). */
|
|
48
|
+
label: string
|
|
49
|
+
className?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function toMinutes(time: string): number {
|
|
53
|
+
const [h, m] = time.split(":").map((part) => parseInt(part, 10))
|
|
54
|
+
return (Number.isFinite(h) ? h : 0) * 60 + (Number.isFinite(m) ? m : 0)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const STATE_CLASSES: Record<TimeBlockState, string> = {
|
|
58
|
+
booked: "bg-primary-tint text-primary-tint-foreground border-s-[3px] border-primary",
|
|
59
|
+
"checked-in": "bg-success-tint text-success-text border-s-[3px] border-success",
|
|
60
|
+
request: "bg-transparent text-warning-text border-[1.5px] border-dashed border-warning",
|
|
61
|
+
blocked: "bg-muted text-muted-foreground border-s-[3px] border-input",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function TimeGrid({
|
|
65
|
+
columns,
|
|
66
|
+
blocks,
|
|
67
|
+
startHour = 8,
|
|
68
|
+
endHour = 18,
|
|
69
|
+
hourHeight = 64,
|
|
70
|
+
now,
|
|
71
|
+
label,
|
|
72
|
+
className,
|
|
73
|
+
}: TimeGridProps) {
|
|
74
|
+
const hours = Array.from({ length: Math.max(0, endHour - startHour) }, (_, index) => startHour + index)
|
|
75
|
+
const top = (time: string) => ((toMinutes(time) - startHour * 60) / 60) * hourHeight
|
|
76
|
+
const height = hours.length * hourHeight
|
|
77
|
+
const nowTop = now != null ? top(now) : null
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
data-slot="time-grid"
|
|
82
|
+
role="group"
|
|
83
|
+
aria-label={label}
|
|
84
|
+
className={cn("overflow-x-auto rounded-card border border-border bg-card", className)}
|
|
85
|
+
>
|
|
86
|
+
<div
|
|
87
|
+
className="grid min-w-fit"
|
|
88
|
+
style={{ gridTemplateColumns: `64px repeat(${columns.length}, minmax(160px, 1fr))` }}
|
|
89
|
+
>
|
|
90
|
+
<div className="border-b border-border" />
|
|
91
|
+
{columns.map((column) => (
|
|
92
|
+
<div
|
|
93
|
+
key={column.id}
|
|
94
|
+
className="flex items-center gap-2 border-s border-b border-border px-3 py-2.5 text-sm font-semibold"
|
|
95
|
+
>
|
|
96
|
+
{column.header}
|
|
97
|
+
</div>
|
|
98
|
+
))}
|
|
99
|
+
<div aria-hidden="true">
|
|
100
|
+
{hours.map((hour) => (
|
|
101
|
+
<div
|
|
102
|
+
key={hour}
|
|
103
|
+
dir="ltr"
|
|
104
|
+
className="box-border border-t border-border px-2 py-1 font-mono text-xs text-muted-foreground"
|
|
105
|
+
style={{ height: hourHeight }}
|
|
106
|
+
>
|
|
107
|
+
{String(hour).padStart(2, "0")}:00
|
|
108
|
+
</div>
|
|
109
|
+
))}
|
|
110
|
+
</div>
|
|
111
|
+
{columns.map((column) => (
|
|
112
|
+
<div
|
|
113
|
+
key={column.id}
|
|
114
|
+
role="list"
|
|
115
|
+
className="relative border-s border-border"
|
|
116
|
+
style={{
|
|
117
|
+
height,
|
|
118
|
+
backgroundImage: `repeating-linear-gradient(to bottom, transparent 0 ${hourHeight - 1}px, var(--border) ${hourHeight - 1}px ${hourHeight}px)`,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{blocks
|
|
122
|
+
.filter((block) => block.column === column.id)
|
|
123
|
+
.map((block) => {
|
|
124
|
+
const state = block.state ?? "booked"
|
|
125
|
+
const blockTop = top(block.start)
|
|
126
|
+
const blockHeight = Math.max(20, top(block.end) - blockTop - 4)
|
|
127
|
+
const Element = block.onOpen ? "button" : "div"
|
|
128
|
+
return (
|
|
129
|
+
<Element
|
|
130
|
+
key={block.id}
|
|
131
|
+
role="listitem"
|
|
132
|
+
data-state={state}
|
|
133
|
+
{...(block.onOpen ? { type: "button" as const, onClick: block.onOpen } : {})}
|
|
134
|
+
className={cn(
|
|
135
|
+
"absolute inset-x-1.5 overflow-hidden rounded-[8px] px-2 py-1.5 text-start text-xs leading-snug outline-none focus-visible:ring-2 focus-visible:ring-ring/30",
|
|
136
|
+
STATE_CLASSES[state]
|
|
137
|
+
)}
|
|
138
|
+
style={{ top: blockTop + 2, height: blockHeight }}
|
|
139
|
+
>
|
|
140
|
+
<span className="block font-semibold text-foreground">{block.title}</span>
|
|
141
|
+
<span dir="ltr" className="sr-only">
|
|
142
|
+
{` ${block.start}–${block.end} `}
|
|
143
|
+
</span>
|
|
144
|
+
{block.detail}
|
|
145
|
+
</Element>
|
|
146
|
+
)
|
|
147
|
+
})}
|
|
148
|
+
{nowTop != null && nowTop >= 0 && nowTop <= height && (
|
|
149
|
+
<div
|
|
150
|
+
aria-hidden="true"
|
|
151
|
+
data-slot="time-grid-now"
|
|
152
|
+
className="absolute inset-x-0 z-[2] h-0.5 bg-destructive before:absolute before:-start-1 before:-top-1 before:size-2.5 before:rounded-full before:bg-destructive"
|
|
153
|
+
style={{ top: nowTop }}
|
|
154
|
+
/>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
))}
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { TimeGrid }
|