@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,102 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { fn } from "storybook/test"
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AudiencePeoplePicker,
|
|
7
|
+
type AudiencePersonOption,
|
|
8
|
+
} from "./audience-people-picker"
|
|
9
|
+
|
|
10
|
+
const PEOPLE: AudiencePersonOption[] = [
|
|
11
|
+
{ id: 11, name: "Aisha Karim", secondary: "aisha@demo.example.com" },
|
|
12
|
+
{ id: 12, name: "Omar Haddad", secondary: "omar@demo.example.com" },
|
|
13
|
+
{ id: 13, name: "Lena Farouk", secondary: "lena@demo.example.com" },
|
|
14
|
+
{ id: 14, name: "Yusuf Nabil", secondary: "yusuf@demo.example.com" },
|
|
15
|
+
{ id: 15, name: "Rania Saleh", secondary: "rania@demo.example.com" },
|
|
16
|
+
{ id: 16, name: "Karim Aziz", secondary: "karim@demo.example.com" },
|
|
17
|
+
{ id: 17, name: "Nour Adel", secondary: "nour@demo.example.com" },
|
|
18
|
+
{ id: 18, name: "Sami Darwish", secondary: "sami@demo.example.com" },
|
|
19
|
+
{ id: 19, name: "Hana Mansour", secondary: "hana@demo.example.com" },
|
|
20
|
+
{ id: 20, name: "Tarek Amin", secondary: "tarek@demo.example.com" },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
const meta = {
|
|
24
|
+
title: "Primitives/AudiencePeoplePicker",
|
|
25
|
+
component: AudiencePeoplePicker,
|
|
26
|
+
tags: ["autodocs"],
|
|
27
|
+
args: {
|
|
28
|
+
people: PEOPLE,
|
|
29
|
+
value: [],
|
|
30
|
+
onChange: fn(),
|
|
31
|
+
},
|
|
32
|
+
} satisfies Meta<typeof AudiencePeoplePicker>
|
|
33
|
+
|
|
34
|
+
export default meta
|
|
35
|
+
type Story = StoryObj<typeof meta>
|
|
36
|
+
|
|
37
|
+
/** Fully controlled — the wrapper holds the selection so the canvas is usable. */
|
|
38
|
+
function ControlledPeoplePicker({
|
|
39
|
+
value,
|
|
40
|
+
onChange,
|
|
41
|
+
...props
|
|
42
|
+
}: React.ComponentProps<typeof AudiencePeoplePicker>) {
|
|
43
|
+
const [current, setCurrent] = React.useState<number[]>(value)
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<AudiencePeoplePicker
|
|
47
|
+
{...props}
|
|
48
|
+
value={current}
|
|
49
|
+
onChange={(next) => {
|
|
50
|
+
setCurrent(next)
|
|
51
|
+
onChange(next)
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The opening state: a search box and nothing else. Deliberately not the whole
|
|
59
|
+
* roster — this control is for naming a handful, and listing everybody invites
|
|
60
|
+
* the reading the `explicit` kind exists to avoid.
|
|
61
|
+
*/
|
|
62
|
+
export const Empty: Story = {
|
|
63
|
+
render: (args) => <ControlledPeoplePicker {...args} />,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Three people named: the tender-committee case, which no computed rule expresses. */
|
|
67
|
+
export const WithSelection: Story = {
|
|
68
|
+
args: { value: [11, 12, 13] },
|
|
69
|
+
render: (args) => <ControlledPeoplePicker {...args} />,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A chosen id the catalogue does not cover — shown by id, never as a blank. */
|
|
73
|
+
export const UnknownPersonChosen: Story = {
|
|
74
|
+
args: { value: [11, 999] },
|
|
75
|
+
render: (args) => <ControlledPeoplePicker {...args} />,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Read-only: the chips remain legible, the search and remove controls go. */
|
|
79
|
+
export const Disabled: Story = {
|
|
80
|
+
args: { value: [11, 12], disabled: true },
|
|
81
|
+
render: (args) => <ControlledPeoplePicker {...args} />,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A reason, never an empty search box. */
|
|
85
|
+
export const Unavailable: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
people: [],
|
|
88
|
+
unavailableReason:
|
|
89
|
+
"You cannot list people here, so a step cannot name one. An administrator would need to grant you users:read.",
|
|
90
|
+
},
|
|
91
|
+
render: (args) => <ControlledPeoplePicker {...args} />,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Right-to-left: chips, the remove control and the result rows all mirror. */
|
|
95
|
+
export const RightToLeft: Story = {
|
|
96
|
+
args: { value: [11, 12] },
|
|
97
|
+
render: (args) => (
|
|
98
|
+
<div dir="rtl">
|
|
99
|
+
<ControlledPeoplePicker {...args} />
|
|
100
|
+
</div>
|
|
101
|
+
),
|
|
102
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { IconX } from "@tabler/icons-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "./utils"
|
|
7
|
+
import { Badge } from "./badge"
|
|
8
|
+
import { Button } from "./button"
|
|
9
|
+
import { Input } from "./input"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Naming PEOPLE, one at a time, for the hand-picked case (#1015, over #999's
|
|
13
|
+
* `explicit` rule kind).
|
|
14
|
+
*
|
|
15
|
+
* WHY A ROSTER IS ALLOWED HERE AND NOWHERE ELSE
|
|
16
|
+
* ---------------------------------------------
|
|
17
|
+
* Everything else about document routing argues against enumerating people: a
|
|
18
|
+
* step names a rule, and a stored list of names is wrong the moment somebody is
|
|
19
|
+
* hired. `explicit` is the deliberate exception, and it is an exception with a
|
|
20
|
+
* meaning rather than an escape hatch — "the tender committee is Aisha, Omar and
|
|
21
|
+
* Lena" is a real requirement that no computed rule expresses, and it MEANS
|
|
22
|
+
* those three. A fourth person joining the department must not silently join the
|
|
23
|
+
* committee.
|
|
24
|
+
*
|
|
25
|
+
* So this control is for choosing a handful, and its shape says so: a search box
|
|
26
|
+
* and a bounded result list rather than a scrollable roster of the whole
|
|
27
|
+
* organisation. A picker that renders four thousand rows has rebuilt the problem
|
|
28
|
+
* user groups exist to remove — the thousand nodes standing in for the one that
|
|
29
|
+
* says "instructors" — on the screen where somebody is trying to name three
|
|
30
|
+
* people.
|
|
31
|
+
*
|
|
32
|
+
* NO CEILING IS MIRRORED HERE, ON PURPOSE
|
|
33
|
+
* ---------------------------------------
|
|
34
|
+
* The server refuses an `explicit` rule naming more people than it will accept,
|
|
35
|
+
* and its refusal names the number and says what to do instead. This component
|
|
36
|
+
* does not carry a copy of that number. A mirrored limit is a second copy of a
|
|
37
|
+
* value that only the server actually enforces: wrong on the first install that
|
|
38
|
+
* changes it, and wrong in the direction that blocks legitimate work. The same
|
|
39
|
+
* position the route composer already takes for the per-step recipient ceiling —
|
|
40
|
+
* limits are surfaced, not mirrored.
|
|
41
|
+
*
|
|
42
|
+
* FETCHES NOTHING, TRANSLATES NOTHING. People arrive as a prop and every visible
|
|
43
|
+
* string is a label prop with an English default, like every other
|
|
44
|
+
* `@whity/ui` input.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/** One person who may be named. */
|
|
48
|
+
export interface AudiencePersonOption {
|
|
49
|
+
/** Profile id — what the rule stores, and what survives a rename. */
|
|
50
|
+
id: number
|
|
51
|
+
name: string
|
|
52
|
+
/** An email or unit, shown to tell two people of the same name apart. */
|
|
53
|
+
secondary?: string | null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface AudiencePeoplePickerProps {
|
|
57
|
+
id?: string
|
|
58
|
+
/** The catalogue to search, already fetched by the caller. */
|
|
59
|
+
people: AudiencePersonOption[]
|
|
60
|
+
/** Chosen profile ids, in the order they were chosen. */
|
|
61
|
+
value: number[]
|
|
62
|
+
onChange: (profileIds: number[]) => void
|
|
63
|
+
/**
|
|
64
|
+
* Why there is nobody to choose from — typically a 403 on the people
|
|
65
|
+
* catalogue. Rendered instead of an empty search box, which would read as "this
|
|
66
|
+
* workspace has no people".
|
|
67
|
+
*/
|
|
68
|
+
unavailableReason?: string | null
|
|
69
|
+
/** Why the catalogue may be incomplete, when it loaded but only partly. */
|
|
70
|
+
incompleteReason?: string | null
|
|
71
|
+
/**
|
|
72
|
+
* How many matches to render at once. A bound, not a page: somebody who cannot
|
|
73
|
+
* find their person in this many should type more, not scroll further.
|
|
74
|
+
*/
|
|
75
|
+
maxResults?: number
|
|
76
|
+
disabled?: boolean
|
|
77
|
+
className?: string
|
|
78
|
+
|
|
79
|
+
// -- labels, English by default ------------------------------------------
|
|
80
|
+
|
|
81
|
+
searchPlaceholder?: string
|
|
82
|
+
/** No people in the catalogue at all. */
|
|
83
|
+
emptyLabel?: string
|
|
84
|
+
/** Nothing chosen yet. */
|
|
85
|
+
nothingSelectedLabel?: string
|
|
86
|
+
/** The query matched nobody. */
|
|
87
|
+
noMatchesLabel?: string
|
|
88
|
+
/** More matched than are being shown. */
|
|
89
|
+
moreMatchesLabel?: (shown: number, total: number) => string
|
|
90
|
+
/** Accessible name for a chip's remove button. */
|
|
91
|
+
removeLabel?: (name: string) => string
|
|
92
|
+
/** For a chosen id that is not in the catalogue the caller supplied. */
|
|
93
|
+
unknownPersonLabel?: (profileId: number) => string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A searchable multi-person picker.
|
|
98
|
+
*
|
|
99
|
+
* Controlled: `value` is the list of chosen profile ids, and an empty list is
|
|
100
|
+
* the state a caller must treat as "not configured yet" — the server refuses an
|
|
101
|
+
* `explicit` rule that names nobody rather than accepting it as "nobody".
|
|
102
|
+
*/
|
|
103
|
+
export function AudiencePeoplePicker({
|
|
104
|
+
id,
|
|
105
|
+
people,
|
|
106
|
+
value,
|
|
107
|
+
onChange,
|
|
108
|
+
unavailableReason = null,
|
|
109
|
+
incompleteReason = null,
|
|
110
|
+
maxResults = 8,
|
|
111
|
+
disabled = false,
|
|
112
|
+
className,
|
|
113
|
+
searchPlaceholder = "Search people by name",
|
|
114
|
+
emptyLabel = "There is nobody here to name.",
|
|
115
|
+
nothingSelectedLabel = "Nobody chosen yet.",
|
|
116
|
+
noMatchesLabel = "Nobody matches that.",
|
|
117
|
+
moreMatchesLabel = (shown: number, total: number) =>
|
|
118
|
+
`Showing ${shown} of ${total} matches — keep typing to narrow it down.`,
|
|
119
|
+
removeLabel = (name: string) => `Remove ${name}`,
|
|
120
|
+
unknownPersonLabel = (profileId: number) => `Profile #${profileId}`,
|
|
121
|
+
}: AudiencePeoplePickerProps) {
|
|
122
|
+
const [query, setQuery] = React.useState("")
|
|
123
|
+
|
|
124
|
+
const byId = React.useMemo(() => {
|
|
125
|
+
const map = new Map<number, AudiencePersonOption>()
|
|
126
|
+
for (const person of people) map.set(person.id, person)
|
|
127
|
+
return map
|
|
128
|
+
}, [people])
|
|
129
|
+
|
|
130
|
+
const chosen = React.useMemo(() => new Set(value), [value])
|
|
131
|
+
|
|
132
|
+
const matches = React.useMemo(() => {
|
|
133
|
+
const needle = query.trim().toLocaleLowerCase()
|
|
134
|
+
// An empty query shows nothing rather than everybody. This is a picker for
|
|
135
|
+
// naming a few, and opening it with the whole organisation already listed
|
|
136
|
+
// invites scrolling through it, which is the reading the `explicit` kind is
|
|
137
|
+
// deliberately not for.
|
|
138
|
+
if (needle === "") return []
|
|
139
|
+
return people.filter((person) => {
|
|
140
|
+
if (chosen.has(person.id)) return false
|
|
141
|
+
const secondary = person.secondary ?? ""
|
|
142
|
+
return (
|
|
143
|
+
person.name.toLocaleLowerCase().includes(needle) ||
|
|
144
|
+
secondary.toLocaleLowerCase().includes(needle)
|
|
145
|
+
)
|
|
146
|
+
})
|
|
147
|
+
}, [people, query, chosen])
|
|
148
|
+
|
|
149
|
+
if (unavailableReason !== null && unavailableReason !== "") {
|
|
150
|
+
return (
|
|
151
|
+
<p
|
|
152
|
+
data-slot="audience-people-picker-unavailable"
|
|
153
|
+
className={cn("text-xs text-muted-foreground", className)}
|
|
154
|
+
>
|
|
155
|
+
{unavailableReason}
|
|
156
|
+
</p>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (people.length === 0) {
|
|
161
|
+
return (
|
|
162
|
+
<p
|
|
163
|
+
data-slot="audience-people-picker-empty"
|
|
164
|
+
className={cn("text-xs text-muted-foreground", className)}
|
|
165
|
+
>
|
|
166
|
+
{emptyLabel}
|
|
167
|
+
</p>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const add = (profileId: number): void => {
|
|
172
|
+
if (chosen.has(profileId)) return
|
|
173
|
+
onChange([...value, profileId])
|
|
174
|
+
setQuery("")
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const remove = (profileId: number): void => {
|
|
178
|
+
onChange(value.filter((existing) => existing !== profileId))
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const shown = matches.slice(0, maxResults)
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div
|
|
185
|
+
data-slot="audience-people-picker"
|
|
186
|
+
className={cn("space-y-2", className)}
|
|
187
|
+
>
|
|
188
|
+
<div className="flex flex-wrap gap-1.5" data-slot="audience-people-picker-chosen">
|
|
189
|
+
{value.length === 0 ? (
|
|
190
|
+
<span className="text-xs text-muted-foreground">
|
|
191
|
+
{nothingSelectedLabel}
|
|
192
|
+
</span>
|
|
193
|
+
) : (
|
|
194
|
+
value.map((profileId) => {
|
|
195
|
+
const person = byId.get(profileId)
|
|
196
|
+
const name = person?.name ?? unknownPersonLabel(profileId)
|
|
197
|
+
return (
|
|
198
|
+
<Badge key={profileId} variant="secondary" className="gap-1 pe-1">
|
|
199
|
+
{name}
|
|
200
|
+
{!disabled && (
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
aria-label={removeLabel(name)}
|
|
204
|
+
onClick={() => remove(profileId)}
|
|
205
|
+
className="rounded-full p-0.5 outline-none hover:bg-muted-foreground/20 focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
206
|
+
>
|
|
207
|
+
<IconX className="size-2.5" />
|
|
208
|
+
</button>
|
|
209
|
+
)}
|
|
210
|
+
</Badge>
|
|
211
|
+
)
|
|
212
|
+
})
|
|
213
|
+
)}
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
{!disabled && (
|
|
217
|
+
<>
|
|
218
|
+
<Input
|
|
219
|
+
id={id}
|
|
220
|
+
type="search"
|
|
221
|
+
value={query}
|
|
222
|
+
aria-label={searchPlaceholder}
|
|
223
|
+
placeholder={searchPlaceholder}
|
|
224
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
225
|
+
/>
|
|
226
|
+
|
|
227
|
+
{query.trim() !== "" && (
|
|
228
|
+
<div data-slot="audience-people-picker-results">
|
|
229
|
+
{matches.length === 0 ? (
|
|
230
|
+
<p className="text-xs text-muted-foreground">{noMatchesLabel}</p>
|
|
231
|
+
) : (
|
|
232
|
+
<>
|
|
233
|
+
<ul className="space-y-1">
|
|
234
|
+
{shown.map((person) => (
|
|
235
|
+
<li key={person.id}>
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="sm"
|
|
239
|
+
// `justify-start` is a flex alignment on the writing
|
|
240
|
+
// axis, so it follows the document direction — the
|
|
241
|
+
// reason this is not `justify-left`.
|
|
242
|
+
className="w-full justify-start"
|
|
243
|
+
onClick={() => add(person.id)}
|
|
244
|
+
>
|
|
245
|
+
<span className="truncate">{person.name}</span>
|
|
246
|
+
{person.secondary !== undefined &&
|
|
247
|
+
person.secondary !== null &&
|
|
248
|
+
person.secondary !== "" && (
|
|
249
|
+
<span className="ms-2 truncate text-xs text-muted-foreground">
|
|
250
|
+
{person.secondary}
|
|
251
|
+
</span>
|
|
252
|
+
)}
|
|
253
|
+
</Button>
|
|
254
|
+
</li>
|
|
255
|
+
))}
|
|
256
|
+
</ul>
|
|
257
|
+
{matches.length > shown.length && (
|
|
258
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
259
|
+
{moreMatchesLabel(shown.length, matches.length)}
|
|
260
|
+
</p>
|
|
261
|
+
)}
|
|
262
|
+
</>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
)}
|
|
266
|
+
</>
|
|
267
|
+
)}
|
|
268
|
+
|
|
269
|
+
{incompleteReason !== null && incompleteReason !== "" && (
|
|
270
|
+
<p
|
|
271
|
+
data-slot="audience-people-picker-incomplete"
|
|
272
|
+
className="text-xs text-muted-foreground"
|
|
273
|
+
>
|
|
274
|
+
{incompleteReason}
|
|
275
|
+
</p>
|
|
276
|
+
)}
|
|
277
|
+
</div>
|
|
278
|
+
)
|
|
279
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seeded avatar patterns (M.34, docs/design/components/index.d.ts `avatarPattern`
|
|
3
|
+
* and `brandHue`, bundle.js). People without a photo get a small Whity pattern
|
|
4
|
+
* instead of bare initials: the same seed and hue always draw the same picture,
|
|
5
|
+
* on every device and in the phone app.
|
|
6
|
+
*
|
|
7
|
+
* Pass a stable seed (the Whity ID, or the person's id) and the hue of the
|
|
8
|
+
* installation colour where the account was created (`brandHue`).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A small deterministic random number generator, seeded by a string. */
|
|
12
|
+
export function seededRandom(seed: string): () => number {
|
|
13
|
+
let hash = 1779033703 ^ seed.length
|
|
14
|
+
for (let i = 0; i < seed.length; i++) {
|
|
15
|
+
hash = Math.imul(hash ^ seed.charCodeAt(i), 3432918353)
|
|
16
|
+
hash = (hash << 13) | (hash >>> 19)
|
|
17
|
+
}
|
|
18
|
+
let state = hash >>> 0
|
|
19
|
+
return () => {
|
|
20
|
+
state = (state + 0x6d2b79f5) >>> 0
|
|
21
|
+
let r = Math.imul(state ^ (state >>> 15), 1 | state)
|
|
22
|
+
r = (r + Math.imul(r ^ (r >>> 7), 61 | r)) ^ r
|
|
23
|
+
return ((r ^ (r >>> 14)) >>> 0) / 4294967296
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The OKLCH hue (0-360) of a brand colour, used to colour avatar patterns. */
|
|
28
|
+
export function brandHue(hex: string): number {
|
|
29
|
+
let m = String(hex || "#0961bb").replace("#", "")
|
|
30
|
+
if (m.length === 3) m = m.replace(/./g, "$&$&")
|
|
31
|
+
const [r, g, b] = [0, 2, 4].map((i) => {
|
|
32
|
+
const v = parseInt(m.substring(i, i + 2), 16) / 255
|
|
33
|
+
return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4)
|
|
34
|
+
})
|
|
35
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)
|
|
36
|
+
const mm = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)
|
|
37
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)
|
|
38
|
+
const a = 1.9779984951 * l - 2.428592205 * mm + 0.4505937099 * s
|
|
39
|
+
const bb = 0.0259040371 * l + 0.7827717662 * mm - 0.808675766 * s
|
|
40
|
+
const hue = (Math.atan2(bb, a) * 180) / Math.PI
|
|
41
|
+
const rounded = Math.round(hue < 0 ? hue + 360 : hue)
|
|
42
|
+
return Number.isFinite(rounded) ? rounded : 255
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type AvatarPatternShape =
|
|
46
|
+
| {
|
|
47
|
+
kind: "rect"
|
|
48
|
+
x: number
|
|
49
|
+
y: number
|
|
50
|
+
width: number
|
|
51
|
+
height: number
|
|
52
|
+
rx: number
|
|
53
|
+
fill: string
|
|
54
|
+
stroke?: string
|
|
55
|
+
dash?: boolean
|
|
56
|
+
rotate?: number
|
|
57
|
+
}
|
|
58
|
+
| { kind: "circle"; cx: number; cy: number; r: number; fill: string }
|
|
59
|
+
|
|
60
|
+
export interface AvatarPatternShapes {
|
|
61
|
+
background: string
|
|
62
|
+
rotate: number
|
|
63
|
+
shapes: AvatarPatternShape[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Only ever a number, whatever the caller passes. */
|
|
67
|
+
function safeHue(hue: unknown): number {
|
|
68
|
+
const value = Number(hue)
|
|
69
|
+
return Number.isFinite(value) ? Math.round(value) : 255
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The pattern as data: the mark's sheet and planes in one of four
|
|
74
|
+
* arrangements, tinted around `hue` (Whity Blue, 255, by default). The Avatar
|
|
75
|
+
* draws these as React SVG elements; `avatarPattern` writes them as markup.
|
|
76
|
+
*/
|
|
77
|
+
export function avatarPatternShapes(seed: string, hue: number = 255): AvatarPatternShapes {
|
|
78
|
+
const h = safeHue(hue)
|
|
79
|
+
const random = seededRandom(String(seed || "whity"))
|
|
80
|
+
const pick = <T,>(values: T[]): T => values[Math.floor(random() * values.length)]
|
|
81
|
+
const hb = h + pick([-36, -18, 0, 18, 36])
|
|
82
|
+
const ha = h + pick([-70, 70, 160])
|
|
83
|
+
const ink = `oklch(0.52 0.16 ${h})`
|
|
84
|
+
const deep = `oklch(0.3 0.1 ${h})`
|
|
85
|
+
const soft = `oklch(0.76 0.12 ${ha})`
|
|
86
|
+
const white = "#fff"
|
|
87
|
+
const layout = Math.floor(random() * 4)
|
|
88
|
+
const rotate = pick([0, 0, -10, 10, -18, 18])
|
|
89
|
+
const s = 15 + Math.floor(random() * 5)
|
|
90
|
+
const x = 12 + Math.floor(random() * 5)
|
|
91
|
+
const y = 9 + Math.floor(random() * 5)
|
|
92
|
+
const rect = (rx: number, ry: number, width: number, height: number, radius: number, fill: string): AvatarPatternShape => ({
|
|
93
|
+
kind: "rect",
|
|
94
|
+
x: rx,
|
|
95
|
+
y: ry,
|
|
96
|
+
width,
|
|
97
|
+
height,
|
|
98
|
+
rx: radius,
|
|
99
|
+
fill,
|
|
100
|
+
})
|
|
101
|
+
const shapes: AvatarPatternShape[] = []
|
|
102
|
+
if (layout === 0) {
|
|
103
|
+
shapes.push(rect(3, y + s - 1, 34, 8, 3, ink), rect(x - 3, y + 3, s, s, 3, deep), rect(x, y, s, s, 3, white))
|
|
104
|
+
} else if (layout === 1) {
|
|
105
|
+
shapes.push(rect(x - 7, y + 5, s, s, 3, soft), rect(x - 1, y + 2, s, s, 3, deep), rect(x + 2, y - 1, s, s, 3, ink))
|
|
106
|
+
} else if (layout === 2) {
|
|
107
|
+
const cx = pick([12, 28])
|
|
108
|
+
shapes.push(rect(4, 29, 32, 6, 3, soft), { kind: "circle", cx, cy: y + 4, r: 6, fill: ink }, {
|
|
109
|
+
...rect(cx === 12 ? 17 : 8, y + 2, s, s, 3, "none"),
|
|
110
|
+
stroke: deep,
|
|
111
|
+
dash: true,
|
|
112
|
+
} as AvatarPatternShape)
|
|
113
|
+
} else {
|
|
114
|
+
shapes.push(
|
|
115
|
+
{ ...rect(-12, 18, 64, 13, 0, ink), rotate: pick([-24, 24, -36, 36]) } as AvatarPatternShape,
|
|
116
|
+
rect(x - 3, y + 1, s, s, 3, deep),
|
|
117
|
+
rect(x, y - 2, s, s, 3, white)
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return { background: `oklch(0.93 0.045 ${hb})`, rotate, shapes }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** SVG markup for a seeded avatar pattern (M.34), for places outside React (emails, exports). */
|
|
124
|
+
export function avatarPattern(seed: string, hue: number = 255): string {
|
|
125
|
+
const { background, rotate, shapes } = avatarPatternShapes(seed, hue)
|
|
126
|
+
const body = shapes
|
|
127
|
+
.map((shape) => {
|
|
128
|
+
if (shape.kind === "circle") return `<circle cx="${shape.cx}" cy="${shape.cy}" r="${shape.r}" fill="${shape.fill}"/>`
|
|
129
|
+
const extra = shape.dash
|
|
130
|
+
? ` stroke="${shape.stroke}" stroke-width="2.6" stroke-dasharray="4.5 3"`
|
|
131
|
+
: shape.rotate != null
|
|
132
|
+
? ` transform="rotate(${shape.rotate} 20 24)"`
|
|
133
|
+
: ""
|
|
134
|
+
return `<rect x="${shape.x}" y="${shape.y}" width="${shape.width}" height="${shape.height}" rx="${shape.rx}" fill="${shape.fill}"${extra}/>`
|
|
135
|
+
})
|
|
136
|
+
.join("")
|
|
137
|
+
return `<svg viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect width="40" height="40" fill="${background}"/><g transform="rotate(${rotate} 20 20)">${body}</g></svg>`
|
|
138
|
+
}
|
package/src/avatar.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { avatarPatternShapes } from "./avatar-pattern"
|
|
2
|
+
import { Icon } from "./icon"
|
|
3
|
+
import { Mark } from "./mark"
|
|
4
|
+
import { cn } from "./utils"
|
|
5
|
+
|
|
6
|
+
/** The seeded pattern (M.34) as SVG elements: no markup is ever injected. */
|
|
7
|
+
function AvatarPattern({ seed, hue }: { seed: string; hue?: number }) {
|
|
8
|
+
const { background, rotate, shapes } = avatarPatternShapes(seed, hue)
|
|
9
|
+
return (
|
|
10
|
+
<svg data-slot="avatar-pattern" viewBox="0 0 40 40" aria-hidden="true" className="block size-full rounded-full">
|
|
11
|
+
<rect width="40" height="40" fill={background} />
|
|
12
|
+
<g transform={`rotate(${rotate} 20 20)`}>
|
|
13
|
+
{shapes.map((shape, index) =>
|
|
14
|
+
shape.kind === "circle" ? (
|
|
15
|
+
<circle key={index} cx={shape.cx} cy={shape.cy} r={shape.r} fill={shape.fill} />
|
|
16
|
+
) : (
|
|
17
|
+
<rect
|
|
18
|
+
key={index}
|
|
19
|
+
x={shape.x}
|
|
20
|
+
y={shape.y}
|
|
21
|
+
width={shape.width}
|
|
22
|
+
height={shape.height}
|
|
23
|
+
rx={shape.rx}
|
|
24
|
+
fill={shape.fill}
|
|
25
|
+
{...(shape.dash ? { stroke: shape.stroke, strokeWidth: 2.6, strokeDasharray: "4.5 3" } : {})}
|
|
26
|
+
{...(shape.rotate != null ? { transform: `rotate(${shape.rotate} 20 24)` } : {})}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
)}
|
|
30
|
+
</g>
|
|
31
|
+
</svg>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ActorKind = "person" | "agent" | "system"
|
|
36
|
+
|
|
37
|
+
/** Up to two initials, from the first letters of the first two words. */
|
|
38
|
+
function initials(name: string): string {
|
|
39
|
+
return (
|
|
40
|
+
name
|
|
41
|
+
.split(/\s+/)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.slice(0, 2)
|
|
44
|
+
.map((word) => word.charAt(0))
|
|
45
|
+
.join("")
|
|
46
|
+
.toUpperCase() || "?"
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Who did something, at a glance: people get their initials on grey (or a
|
|
52
|
+
* photo, or a seeded Whity pattern, M.34), agents the robot face on the tint,
|
|
53
|
+
* and the system the Whity mark.
|
|
54
|
+
* Agents never get a human face or a photo (stage 8). An optional dot shows
|
|
55
|
+
* presence. The reference is docs/design/components/Avatar (`.wy-avatar`).
|
|
56
|
+
*/
|
|
57
|
+
function Avatar({
|
|
58
|
+
name,
|
|
59
|
+
kind = "person",
|
|
60
|
+
src,
|
|
61
|
+
pattern,
|
|
62
|
+
hue,
|
|
63
|
+
size = 32,
|
|
64
|
+
status,
|
|
65
|
+
labels,
|
|
66
|
+
className,
|
|
67
|
+
}: {
|
|
68
|
+
name: string
|
|
69
|
+
kind?: ActorKind
|
|
70
|
+
/** A photo, for people only. */
|
|
71
|
+
src?: string
|
|
72
|
+
/**
|
|
73
|
+
* A stable seed (the Whity ID, or the person id): people without a photo get
|
|
74
|
+
* the seeded pattern instead of initials (M.34).
|
|
75
|
+
*/
|
|
76
|
+
pattern?: string
|
|
77
|
+
/** The hue of the installation colour where the account was made (`brandHue`); Whity Blue by default. */
|
|
78
|
+
hue?: number
|
|
79
|
+
size?: number
|
|
80
|
+
status?: "online" | "busy" | "offline"
|
|
81
|
+
/** Overrides for the accessible name suffixes, e.g. Arabic. */
|
|
82
|
+
labels?: { agent?: string }
|
|
83
|
+
className?: string
|
|
84
|
+
}) {
|
|
85
|
+
const L = { agent: "agent", ...labels }
|
|
86
|
+
return (
|
|
87
|
+
<span
|
|
88
|
+
data-slot="avatar"
|
|
89
|
+
data-kind={kind}
|
|
90
|
+
role="img"
|
|
91
|
+
aria-label={kind === "agent" ? `${name} (${L.agent})` : name}
|
|
92
|
+
style={{ width: size, height: size, fontSize: Math.max(11, Math.round(size * 0.36)) }}
|
|
93
|
+
className={cn(
|
|
94
|
+
"relative inline-grid shrink-0 place-items-center rounded-full leading-none font-semibold",
|
|
95
|
+
kind === "agent" && "bg-primary-tint text-primary-tint-foreground",
|
|
96
|
+
kind === "system" && "bg-card shadow-[inset_0_0_0_1px_var(--border)]",
|
|
97
|
+
kind === "person" && "bg-muted text-foreground",
|
|
98
|
+
className
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{kind === "agent" ? (
|
|
102
|
+
<Icon name="robot" size={Math.round(size * 0.56)} stroke={2} />
|
|
103
|
+
) : kind === "system" ? (
|
|
104
|
+
<Mark size={Math.round(size * 0.62)} label="" />
|
|
105
|
+
) : src ? (
|
|
106
|
+
<img src={src} alt="" className="size-full rounded-full object-cover" />
|
|
107
|
+
) : pattern != null ? (
|
|
108
|
+
<AvatarPattern seed={pattern} hue={hue} />
|
|
109
|
+
) : (
|
|
110
|
+
initials(name)
|
|
111
|
+
)}
|
|
112
|
+
{status && (
|
|
113
|
+
<span
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
className={cn(
|
|
116
|
+
"absolute -end-px -bottom-px box-border size-[32%] min-h-2 min-w-2 rounded-full border-2 border-card",
|
|
117
|
+
status === "online" ? "bg-success" : status === "busy" ? "bg-warning" : "bg-muted-foreground"
|
|
118
|
+
)}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</span>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { Avatar, initials }
|