@whity/ui 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +107 -3
  2. package/package.json +192 -6
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +302 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +500 -0
  16. package/src/approval-queue.tsx +108 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar.tsx +83 -0
  22. package/src/badge.stories.tsx +105 -0
  23. package/src/badge.tsx +68 -0
  24. package/src/beta-warning.stories.tsx +79 -0
  25. package/src/beta-warning.tsx +189 -0
  26. package/src/bilingual-input.stories.tsx +82 -0
  27. package/src/bilingual-input.tsx +183 -0
  28. package/src/breadcrumb.stories.tsx +51 -0
  29. package/src/breadcrumb.tsx +90 -0
  30. package/src/button.stories.tsx +87 -0
  31. package/src/button.tsx +118 -0
  32. package/src/card.stories.tsx +423 -0
  33. package/src/card.tsx +180 -0
  34. package/src/chart.stories.tsx +66 -0
  35. package/src/chart.tsx +228 -0
  36. package/src/checkbox.stories.tsx +62 -0
  37. package/src/checkbox.tsx +54 -0
  38. package/src/collapsible.stories.tsx +48 -0
  39. package/src/collapsible.tsx +34 -0
  40. package/src/color-card.stories.tsx +61 -0
  41. package/src/color-card.tsx +270 -0
  42. package/src/color-picker.stories.tsx +65 -0
  43. package/src/color-picker.tsx +425 -0
  44. package/src/command-palette.tsx +306 -0
  45. package/src/copy-block.stories.tsx +38 -0
  46. package/src/copy-block.tsx +85 -0
  47. package/src/data-table.stories.tsx +200 -0
  48. package/src/data-table.tsx +1106 -0
  49. package/src/date-picker.stories.tsx +61 -0
  50. package/src/date-picker.tsx +422 -0
  51. package/src/design-cards.stories.tsx +458 -0
  52. package/src/dialog.stories.tsx +48 -0
  53. package/src/dialog.tsx +166 -0
  54. package/src/documents/barcode-svg.stories.tsx +72 -0
  55. package/src/documents/barcode-svg.tsx +79 -0
  56. package/src/dropdown-menu.stories.tsx +77 -0
  57. package/src/dropdown-menu.tsx +271 -0
  58. package/src/editor/behaviour.ts +279 -0
  59. package/src/editor/block-ids.ts +44 -0
  60. package/src/editor/block-list.tsx +101 -0
  61. package/src/editor/block-toolbar.tsx +477 -0
  62. package/src/editor/bubble.tsx +93 -0
  63. package/src/editor/catalogue.ts +103 -0
  64. package/src/editor/collab-rail.tsx +746 -0
  65. package/src/editor/collab.stories.tsx +207 -0
  66. package/src/editor/collab.ts +87 -0
  67. package/src/editor/contract.ts +408 -0
  68. package/src/editor/convert.ts +362 -0
  69. package/src/editor/doc-editor.stories.tsx +98 -0
  70. package/src/editor/doc-editor.tsx +1287 -0
  71. package/src/editor/editor.css +536 -0
  72. package/src/editor/extensions.ts +86 -0
  73. package/src/editor/field-picker.tsx +107 -0
  74. package/src/editor/fields.ts +100 -0
  75. package/src/editor/gutter.tsx +367 -0
  76. package/src/editor/index.ts +22 -0
  77. package/src/editor/label-sheet.tsx +289 -0
  78. package/src/editor/labels.ts +310 -0
  79. package/src/editor/link-tools.tsx +141 -0
  80. package/src/editor/node-views.tsx +450 -0
  81. package/src/editor/page-view.tsx +353 -0
  82. package/src/editor/publish-check.tsx +182 -0
  83. package/src/editor/rich-blocks.stories.tsx +146 -0
  84. package/src/editor/sample.ts +40 -0
  85. package/src/editor/schema-rich.ts +150 -0
  86. package/src/editor/schema.ts +315 -0
  87. package/src/editor/services.tsx +127 -0
  88. package/src/editor/slash.ts +64 -0
  89. package/src/editor/suggesting.ts +372 -0
  90. package/src/editor/suggestions.ts +763 -0
  91. package/src/editor/table-keys.ts +66 -0
  92. package/src/editor/templates.stories.tsx +324 -0
  93. package/src/editor/toolbar.tsx +358 -0
  94. package/src/empty-state.stories.tsx +51 -0
  95. package/src/empty-state.tsx +100 -0
  96. package/src/empty-state.usage-notes.md +30 -0
  97. package/src/form.stories.tsx +112 -0
  98. package/src/form.tsx +176 -0
  99. package/src/globals.css +20 -0
  100. package/src/icon-button.tsx +85 -0
  101. package/src/icon-map.ts +244 -0
  102. package/src/icon.tsx +41 -0
  103. package/src/index.ts +67 -0
  104. package/src/input.stories.tsx +157 -0
  105. package/src/input.tsx +759 -0
  106. package/src/locked-screen.stories.tsx +29 -0
  107. package/src/locked-screen.tsx +61 -0
  108. package/src/mark.tsx +62 -0
  109. package/src/math-text.stories.tsx +33 -0
  110. package/src/math-text.tsx +43 -0
  111. package/src/menu-bar.stories.tsx +198 -0
  112. package/src/menu-bar.tsx +373 -0
  113. package/src/money/currency.ts +230 -0
  114. package/src/page-header.stories.tsx +95 -0
  115. package/src/page-header.tsx +122 -0
  116. package/src/page-shell.stories.tsx +42 -0
  117. package/src/page-shell.tsx +32 -0
  118. package/src/pagination.stories.tsx +45 -0
  119. package/src/pagination.tsx +98 -0
  120. package/src/plugin-card.stories.tsx +180 -0
  121. package/src/plugin-card.tsx +848 -0
  122. package/src/popover.stories.tsx +48 -0
  123. package/src/popover.tsx +55 -0
  124. package/src/radio-group.stories.tsx +26 -0
  125. package/src/radio-group.tsx +44 -0
  126. package/src/route-flow/editor.tsx +1014 -0
  127. package/src/route-flow/model.ts +716 -0
  128. package/src/scope-grant.tsx +139 -0
  129. package/src/screen-too-small.stories.tsx +61 -0
  130. package/src/screen-too-small.tsx +104 -0
  131. package/src/select.stories.tsx +44 -0
  132. package/src/select.tsx +197 -0
  133. package/src/separator.stories.tsx +34 -0
  134. package/src/separator.tsx +34 -0
  135. package/src/sheet.stories.tsx +49 -0
  136. package/src/sheet.tsx +168 -0
  137. package/src/skeleton.stories.tsx +28 -0
  138. package/src/skeleton.tsx +19 -0
  139. package/src/slider.stories.tsx +78 -0
  140. package/src/slider.tsx +300 -0
  141. package/src/spinner.stories.tsx +33 -0
  142. package/src/spinner.tsx +55 -0
  143. package/src/switch.stories.tsx +42 -0
  144. package/src/switch.tsx +41 -0
  145. package/src/switcher.stories.tsx +111 -0
  146. package/src/switcher.tsx +131 -0
  147. package/src/table.stories.tsx +48 -0
  148. package/src/table.tsx +121 -0
  149. package/src/tabs.stories.tsx +74 -0
  150. package/src/tabs.tsx +90 -0
  151. package/src/tag-input.stories.tsx +67 -0
  152. package/src/tag-input.tsx +117 -0
  153. package/src/tenant-logo.tsx +63 -0
  154. package/src/tenant-switcher.stories.tsx +38 -0
  155. package/src/tenant-switcher.tsx +164 -0
  156. package/src/textarea.stories.tsx +27 -0
  157. package/src/textarea.tsx +18 -0
  158. package/src/theme-mode.ts +52 -0
  159. package/src/time-picker.stories.tsx +62 -0
  160. package/src/time-picker.tsx +615 -0
  161. package/src/toggle-group.tsx +138 -0
  162. package/src/tooltip.stories.tsx +43 -0
  163. package/src/tooltip.tsx +73 -0
  164. package/src/top-nav.stories.tsx +58 -0
  165. package/src/top-nav.tsx +324 -0
  166. package/src/undo-bar.tsx +107 -0
  167. package/src/utils.ts +45 -0
  168. package/src/view-toggle.stories.tsx +84 -0
  169. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,67 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import { fn } from "storybook/test"
3
+ import * as React from "react"
4
+
5
+ import { TagInput, type TagOption } from "./tag-input"
6
+
7
+ const OPTIONS: TagOption[] = [
8
+ { value: "react", label: "React" },
9
+ { value: "typescript", label: "TypeScript" },
10
+ { value: "nextjs", label: "Next.js" },
11
+ { value: "tailwind", label: "Tailwind CSS" },
12
+ { value: "storybook", label: "Storybook" },
13
+ ]
14
+
15
+ const meta = {
16
+ title: "Primitives/TagInput",
17
+ component: TagInput,
18
+ tags: ["autodocs"],
19
+ args: {
20
+ options: OPTIONS,
21
+ value: [],
22
+ onChange: fn(),
23
+ },
24
+ } satisfies Meta<typeof TagInput>
25
+
26
+ export default meta
27
+ type Story = StoryObj<typeof meta>
28
+
29
+ /**
30
+ * `TagInput` is fully controlled, so the interactive stories drive it through
31
+ * this wrapper: the `value` arg seeds local state and the `onChange` arg still
32
+ * fires — so the Actions panel logs selections — while the field stays usable
33
+ * in the canvas.
34
+ */
35
+ function ControlledTagInput({ value, onChange, ...props }: React.ComponentProps<typeof TagInput>) {
36
+ const [current, setCurrent] = React.useState<string[]>(value)
37
+
38
+ return (
39
+ <TagInput
40
+ {...props}
41
+ value={current}
42
+ onChange={(next) => {
43
+ setCurrent(next)
44
+ onChange(next)
45
+ }}
46
+ />
47
+ )
48
+ }
49
+
50
+ export const Empty: Story = {
51
+ args: { id: "sb-tags-empty" },
52
+ render: (args) => <ControlledTagInput {...args} />,
53
+ }
54
+
55
+ export const SomeSelected: Story = {
56
+ args: { id: "sb-tags-some", value: ["typescript", "tailwind"] },
57
+ render: (args) => <ControlledTagInput {...args} />,
58
+ }
59
+
60
+ export const AllSelected: Story = {
61
+ args: { id: "sb-tags-all", value: OPTIONS.map((o) => o.value) },
62
+ render: (args) => <ControlledTagInput {...args} />,
63
+ }
64
+
65
+ export const Disabled: Story = {
66
+ args: { id: "sb-tags-disabled", value: ["react", "nextjs"], disabled: true },
67
+ }
@@ -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
+ }
@@ -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-md 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,62 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { TimePicker } from "./time-picker"
4
+
5
+ const meta = {
6
+ title: "Primitives/TimePicker",
7
+ component: TimePicker,
8
+ tags: ["autodocs"],
9
+ args: { placeholder: "Select time..." },
10
+ } satisfies Meta<typeof TimePicker>
11
+
12
+ export default meta
13
+ type Story = StoryObj<typeof meta>
14
+
15
+ export const Default: Story = {
16
+ render: () => (
17
+ <div className="w-72">
18
+ <TimePicker />
19
+ </div>
20
+ ),
21
+ }
22
+
23
+ export const WithLabelAndTooltip: Story = {
24
+ render: () => (
25
+ <div className="flex w-80 flex-col gap-4">
26
+ <TimePicker
27
+ label="Meeting Time (12-Hour)"
28
+ required
29
+ tooltip="Select the scheduled meeting start time."
30
+ helperText="Includes AM/PM toggle and scrollable hour/minute columns."
31
+ />
32
+ <TimePicker
33
+ label="Shift Start (24-Hour)"
34
+ format="24h"
35
+ defaultValue="14:30"
36
+ tooltip="24-hour military time format."
37
+ helperText="Pre-selected time with clear button."
38
+ />
39
+ </div>
40
+ ),
41
+ }
42
+
43
+ export const States: Story = {
44
+ render: () => (
45
+ <div className="flex w-72 flex-col gap-4">
46
+ <TimePicker
47
+ label="Active TimePicker"
48
+ placeholder="Pick a time"
49
+ />
50
+ <TimePicker
51
+ label="Disabled TimePicker"
52
+ disabled
53
+ defaultValue="09:00 AM"
54
+ helperText="Disabled state prevents opening popover."
55
+ />
56
+ <TimePicker
57
+ label="Invalid TimePicker"
58
+ errorText="Selected time is outside working hours."
59
+ />
60
+ </div>
61
+ ),
62
+ }