@whity/ui 1.0.0 → 1.0.1
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/package.json +27 -25
- package/src/button.tsx +9 -7
- package/src/color-card.tsx +1 -1
- package/src/command-palette.tsx +1 -0
- package/src/data-table.tsx +2 -1
- package/src/date-picker.tsx +1 -0
- package/src/display-preferences.tsx +9 -0
- package/src/index.ts +2 -0
- package/src/input.tsx +1 -1
- package/src/otp-input.tsx +1 -1
- package/src/phone-input.tsx +252 -0
- package/src/role-summary.stories.tsx +143 -0
- package/src/role-summary.tsx +120 -0
- package/src/tenant-switcher.tsx +25 -4
- package/src/theme-mode.ts +23 -1
- package/src/time-picker.tsx +1 -0
- package/src/toggle-group.tsx +2 -1
- package/src/view-toggle.tsx +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whity/ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Shared UI primitives for Whity products",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"./search-field": "./src/search-field.tsx",
|
|
104
104
|
"./stepper": "./src/stepper.tsx",
|
|
105
105
|
"./otp-input": "./src/otp-input.tsx",
|
|
106
|
+
"./phone-input": "./src/phone-input.tsx",
|
|
106
107
|
"./system-state": "./src/system-state.tsx",
|
|
107
108
|
"./form": "./src/form.tsx",
|
|
108
109
|
"./globals.css": "./src/globals.css",
|
|
@@ -141,6 +142,7 @@
|
|
|
141
142
|
"./built-on-whity": "./src/built-on-whity.tsx",
|
|
142
143
|
"./paper-sheet": "./src/paper-sheet.tsx",
|
|
143
144
|
"./lockup": "./src/lockup.tsx",
|
|
145
|
+
"./role-summary": "./src/role-summary.tsx",
|
|
144
146
|
"./tenant-switcher": "./src/tenant-switcher.tsx",
|
|
145
147
|
"./textarea": "./src/textarea.tsx",
|
|
146
148
|
"./theme-mode": "./src/theme-mode.ts",
|
|
@@ -163,40 +165,40 @@
|
|
|
163
165
|
"react-hook-form": ">=7"
|
|
164
166
|
},
|
|
165
167
|
"dependencies": {
|
|
166
|
-
"@whity/tokens": "^1.
|
|
168
|
+
"@whity/tokens": "^1.2.0",
|
|
167
169
|
"@tanstack/react-table": "^9.2.4",
|
|
168
|
-
"@tiptap/core": "3.
|
|
169
|
-
"@tiptap/extension-blockquote": "3.
|
|
170
|
-
"@tiptap/extension-bold": "3.
|
|
171
|
-
"@tiptap/extension-bubble-menu": "3.
|
|
172
|
-
"@tiptap/extension-code": "3.
|
|
173
|
-
"@tiptap/extension-code-block": "3.
|
|
174
|
-
"@tiptap/extension-document": "3.
|
|
175
|
-
"@tiptap/extension-hard-break": "3.
|
|
176
|
-
"@tiptap/extension-heading": "3.
|
|
177
|
-
"@tiptap/extension-highlight": "3.
|
|
178
|
-
"@tiptap/extension-horizontal-rule": "3.
|
|
179
|
-
"@tiptap/extension-italic": "3.
|
|
180
|
-
"@tiptap/extension-link": "3.
|
|
181
|
-
"@tiptap/extension-paragraph": "3.
|
|
182
|
-
"@tiptap/extension-strike": "3.
|
|
183
|
-
"@tiptap/extension-text": "3.
|
|
184
|
-
"@tiptap/extension-underline": "3.
|
|
185
|
-
"@tiptap/extensions": "3.
|
|
186
|
-
"@tiptap/pm": "3.
|
|
187
|
-
"@tiptap/react": "3.
|
|
188
|
-
"@tiptap/suggestion": "3.
|
|
170
|
+
"@tiptap/core": "3.34.0",
|
|
171
|
+
"@tiptap/extension-blockquote": "3.34.0",
|
|
172
|
+
"@tiptap/extension-bold": "3.34.0",
|
|
173
|
+
"@tiptap/extension-bubble-menu": "3.34.0",
|
|
174
|
+
"@tiptap/extension-code": "3.34.0",
|
|
175
|
+
"@tiptap/extension-code-block": "3.34.0",
|
|
176
|
+
"@tiptap/extension-document": "3.34.0",
|
|
177
|
+
"@tiptap/extension-hard-break": "3.34.0",
|
|
178
|
+
"@tiptap/extension-heading": "3.34.0",
|
|
179
|
+
"@tiptap/extension-highlight": "3.34.0",
|
|
180
|
+
"@tiptap/extension-horizontal-rule": "3.34.0",
|
|
181
|
+
"@tiptap/extension-italic": "3.34.0",
|
|
182
|
+
"@tiptap/extension-link": "3.34.0",
|
|
183
|
+
"@tiptap/extension-paragraph": "3.34.0",
|
|
184
|
+
"@tiptap/extension-strike": "3.34.0",
|
|
185
|
+
"@tiptap/extension-text": "3.34.0",
|
|
186
|
+
"@tiptap/extension-underline": "3.34.0",
|
|
187
|
+
"@tiptap/extensions": "3.34.0",
|
|
188
|
+
"@tiptap/pm": "3.34.0",
|
|
189
|
+
"@tiptap/react": "3.34.0",
|
|
190
|
+
"@tiptap/suggestion": "3.34.0",
|
|
189
191
|
"@xyflow/react": "^12.12.1",
|
|
190
192
|
"bwip-js": "^4.11.3",
|
|
191
193
|
"class-variance-authority": "^0.7.1",
|
|
192
194
|
"clsx": "^2.1.1",
|
|
193
|
-
"recharts": "^3.
|
|
195
|
+
"recharts": "^3.11.0",
|
|
194
196
|
"tailwind-merge": "^3.7.0"
|
|
195
197
|
},
|
|
196
198
|
"devDependencies": {
|
|
197
199
|
"@storybook/addon-docs": "^10.6.7",
|
|
198
200
|
"@storybook/react-vite": "^10.4.6",
|
|
199
|
-
"@tabler/icons-react": "^3.
|
|
201
|
+
"@tabler/icons-react": "^3.52.0",
|
|
200
202
|
"@tailwindcss/vite": "^4.3.4",
|
|
201
203
|
"@types/katex": "^0.16.8",
|
|
202
204
|
"@types/node": "^26.6.6",
|
package/src/button.tsx
CHANGED
|
@@ -24,7 +24,9 @@ const buttonVariants = cva(
|
|
|
24
24
|
variants: {
|
|
25
25
|
variant: {
|
|
26
26
|
default:
|
|
27
|
-
|
|
27
|
+
// Shape morph (TH.18): pressed, the main button squares off when the
|
|
28
|
+
// theme morphs. The small and large sizes keep their own corner.
|
|
29
|
+
"mb-(--plane-offset) ml-(--plane-offset) bg-primary text-primary-foreground shadow-plane-primary [transition:box-shadow_var(--dur-fast)_var(--ease-out-whity),translate_var(--dur-fast)_var(--ease-out-whity),border-radius_var(--dur-morph)_var(--ease-out-whity)] hover:translate-x-px hover:-translate-y-px hover:shadow-plane-primary-hover active:-translate-x-[3px] active:translate-y-[3px] active:rounded-control-pressed active:shadow-none",
|
|
28
30
|
outline:
|
|
29
31
|
"border-input bg-card text-foreground hover:bg-muted aria-expanded:bg-muted",
|
|
30
32
|
secondary:
|
|
@@ -35,13 +37,13 @@ const buttonVariants = cva(
|
|
|
35
37
|
},
|
|
36
38
|
size: {
|
|
37
39
|
default: "h-10 px-3.5 [&_svg:not([class*='size-'])]:size-4",
|
|
38
|
-
xs: "h-8 gap-1 rounded-control-sm px-2.5 text-xs [&_svg:not([class*='size-'])]:size-4",
|
|
39
|
-
sm: "h-8 gap-1 rounded-control-sm px-2.5 text-xs [&_svg:not([class*='size-'])]:size-4",
|
|
40
|
-
lg: "h-11 rounded-control-lg px-4 [&_svg:not([class*='size-'])]:size-4",
|
|
40
|
+
xs: "h-8 gap-1 rounded-control-sm active:rounded-control-sm px-2.5 text-xs [&_svg:not([class*='size-'])]:size-4",
|
|
41
|
+
sm: "h-8 gap-1 rounded-control-sm active:rounded-control-sm px-2.5 text-xs [&_svg:not([class*='size-'])]:size-4",
|
|
42
|
+
lg: "h-11 rounded-control-lg active:rounded-control-lg px-4 [&_svg:not([class*='size-'])]:size-4",
|
|
41
43
|
icon: "size-10 px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
42
|
-
"icon-xs": "size-8 rounded-control-sm px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
43
|
-
"icon-sm": "size-8 rounded-control-sm px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
44
|
-
"icon-lg": "size-11 rounded-control-lg px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
44
|
+
"icon-xs": "size-8 rounded-control-sm active:rounded-control-sm px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
45
|
+
"icon-sm": "size-8 rounded-control-sm active:rounded-control-sm px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
46
|
+
"icon-lg": "size-11 rounded-control-lg active:rounded-control-lg px-0 [&_svg:not([class*='size-'])]:size-4",
|
|
45
47
|
},
|
|
46
48
|
},
|
|
47
49
|
compoundVariants: [
|
package/src/color-card.tsx
CHANGED
|
@@ -237,7 +237,7 @@ export function ColorCard({
|
|
|
237
237
|
{shade.isMain && (
|
|
238
238
|
<span
|
|
239
239
|
aria-label={mainShadeLabel}
|
|
240
|
-
className="absolute -top-2.5 left-1/2 -translate-x-1/2 z-30 text-xs font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded-full border-2 border-card shadow-2xs whitespace-nowrap leading-none select-none"
|
|
240
|
+
data-clip-ignore className="absolute -top-2.5 left-1/2 -translate-x-1/2 z-30 text-xs font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded-full border-2 border-card shadow-2xs whitespace-nowrap leading-none select-none"
|
|
241
241
|
style={{
|
|
242
242
|
backgroundColor: shade.hex,
|
|
243
243
|
color: shade.textColor,
|
package/src/command-palette.tsx
CHANGED
|
@@ -292,6 +292,7 @@ export function CommandPalette({
|
|
|
292
292
|
role="dialog"
|
|
293
293
|
aria-modal="true"
|
|
294
294
|
aria-label={label}
|
|
295
|
+
data-slot="command-palette"
|
|
295
296
|
className="w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-popover text-popover-foreground shadow-float"
|
|
296
297
|
onMouseDown={(e) => e.stopPropagation()}
|
|
297
298
|
onKeyDown={onKeyDown}
|
package/src/data-table.tsx
CHANGED
|
@@ -927,7 +927,7 @@ export function DataTable<TData>({
|
|
|
927
927
|
if (isLoading) {
|
|
928
928
|
const visibleCount = table.getVisibleLeafColumns().length
|
|
929
929
|
return (
|
|
930
|
-
<div className={cn("rounded-
|
|
930
|
+
<div data-slot="data-table" className={cn("overflow-hidden rounded-card border border-border bg-card", className)}>
|
|
931
931
|
{/* `aria-busy` marks this as the PLACEHOLDER, not the data.
|
|
932
932
|
It carries the same `aria-label` as the real table — deliberately,
|
|
933
933
|
so assistive technology names the region consistently while it
|
|
@@ -1112,6 +1112,7 @@ export function DataTable<TData>({
|
|
|
1112
1112
|
<EmptyState title={emptyStateTitle} {...emptyState} />
|
|
1113
1113
|
) : (
|
|
1114
1114
|
<div
|
|
1115
|
+
data-slot="data-table"
|
|
1115
1116
|
className={cn("rounded-card border border-border bg-card", maxHeight ? "overflow-auto" : "overflow-hidden")}
|
|
1116
1117
|
style={maxHeight ? { maxHeight } : undefined}
|
|
1117
1118
|
>
|
package/src/date-picker.tsx
CHANGED
|
@@ -226,6 +226,7 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
226
226
|
<button
|
|
227
227
|
type="button"
|
|
228
228
|
id={id}
|
|
229
|
+
data-slot="date-picker-trigger"
|
|
229
230
|
disabled={disabled}
|
|
230
231
|
className={cn(
|
|
231
232
|
"relative flex h-10 w-full items-center justify-start rounded-control border border-input bg-card ps-8 pe-8 py-0.5 text-sm text-foreground transition-colors outline-none 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",
|
|
@@ -16,11 +16,19 @@ export const TEXT_SIZE_STORAGE_KEY = "whity-text-size"
|
|
|
16
16
|
/** The localStorage key for Animations, applied as `<html data-motion>` before React runs. */
|
|
17
17
|
export const MOTION_STORAGE_KEY = "whity-motion"
|
|
18
18
|
|
|
19
|
+
/** Higher contrast (TH.12): text at 7:1 whatever the workspace's theme, as `<html data-contrast="high">`. */
|
|
20
|
+
export type Contrast = "standard" | "high"
|
|
21
|
+
|
|
22
|
+
/** The localStorage key for Higher contrast, applied before React runs. */
|
|
23
|
+
export const CONTRAST_STORAGE_KEY = "whity-contrast"
|
|
24
|
+
|
|
19
25
|
export interface DisplayPreferences {
|
|
20
26
|
textSize: TextSize
|
|
21
27
|
showTechnicalDetails: boolean
|
|
22
28
|
/** Full (default), Calm or Off (LT.4). The device's reduce motion means Off on top. */
|
|
23
29
|
animations: MotionMode
|
|
30
|
+
/** Standard (default) or high (TH.12). */
|
|
31
|
+
contrast?: Contrast
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
export interface DisplayPreferencesValue extends DisplayPreferences {
|
|
@@ -31,6 +39,7 @@ const DisplayPreferencesContext = React.createContext<DisplayPreferencesValue>({
|
|
|
31
39
|
textSize: "standard",
|
|
32
40
|
showTechnicalDetails: false,
|
|
33
41
|
animations: "full",
|
|
42
|
+
contrast: "standard",
|
|
34
43
|
update: () => {},
|
|
35
44
|
})
|
|
36
45
|
|
package/src/index.ts
CHANGED
|
@@ -64,6 +64,7 @@ export * from "./tenant-logo"
|
|
|
64
64
|
export * from "./built-on-whity"
|
|
65
65
|
export * from "./paper-sheet"
|
|
66
66
|
export * from "./lockup"
|
|
67
|
+
export * from "./role-summary"
|
|
67
68
|
export * from "./tenant-switcher"
|
|
68
69
|
export * from "./textarea"
|
|
69
70
|
export * from "./theme-mode"
|
|
@@ -87,4 +88,5 @@ export * from "./save-bar"
|
|
|
87
88
|
export * from "./search-field"
|
|
88
89
|
export * from "./stepper"
|
|
89
90
|
export * from "./otp-input"
|
|
91
|
+
export * from "./phone-input"
|
|
90
92
|
export * from "./system-state"
|
package/src/input.tsx
CHANGED
|
@@ -626,7 +626,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
626
626
|
return (
|
|
627
627
|
<div
|
|
628
628
|
className={cn(
|
|
629
|
-
"flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-control border border-input bg-card p-
|
|
629
|
+
"flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-control border border-input bg-card p-inset-control text-sm transition-colors focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/30",
|
|
630
630
|
disabled && "pointer-events-none opacity-50",
|
|
631
631
|
className
|
|
632
632
|
)}
|
package/src/otp-input.tsx
CHANGED
|
@@ -110,7 +110,7 @@ function OtpInput({
|
|
|
110
110
|
<span id={`${baseId}-label`} className="block text-sm font-medium text-foreground">
|
|
111
111
|
{label}
|
|
112
112
|
</span>
|
|
113
|
-
<div dir="ltr" role="group" aria-labelledby={`${baseId}-label`} aria-describedby={describedBy} className="flex items-center justify-center gap-2">
|
|
113
|
+
<div dir="ltr" role="group" data-slot="otp-input" aria-labelledby={`${baseId}-label`} aria-describedby={describedBy} className="flex items-center justify-center gap-2">
|
|
114
114
|
{Array.from({ length }, (_, index) => (
|
|
115
115
|
<React.Fragment key={index}>
|
|
116
116
|
{index === half && (
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { Icon } from "./icon"
|
|
6
|
+
import { cn } from "./utils"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A country in the phone input's list (docs/design/components/PhoneInput):
|
|
10
|
+
* its calling code, the national lengths it accepts, which numbers are
|
|
11
|
+
* mobiles, and how a national number is grouped when read.
|
|
12
|
+
*/
|
|
13
|
+
export interface PhoneCountry {
|
|
14
|
+
code: string
|
|
15
|
+
dial: string
|
|
16
|
+
name: string
|
|
17
|
+
ar: string
|
|
18
|
+
len: number[]
|
|
19
|
+
mobile: RegExp
|
|
20
|
+
group: number[] | ((digits: string) => number[])
|
|
21
|
+
sample: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The region, the UK and the US (decision 2.x "Inputs": +962 default, regional list). */
|
|
25
|
+
export const phoneCountries: PhoneCountry[] = [
|
|
26
|
+
{ code: "JO", dial: "962", name: "Jordan", ar: "الأردن", len: [8, 9], mobile: /^7[789]/, group: (d) => (/^7/.test(d) ? [2, 3, 4] : [1, 3, 4]), sample: "79 123 4567" },
|
|
27
|
+
{ code: "SA", dial: "966", name: "Saudi Arabia", ar: "السعودية", len: [9], mobile: /^5/, group: [2, 3, 4], sample: "50 123 4567" },
|
|
28
|
+
{ code: "AE", dial: "971", name: "United Arab Emirates", ar: "الإمارات", len: [9], mobile: /^5/, group: [2, 3, 4], sample: "50 123 4567" },
|
|
29
|
+
{ code: "PS", dial: "970", name: "Palestine", ar: "فلسطين", len: [9], mobile: /^5/, group: [2, 3, 4], sample: "59 123 4567" },
|
|
30
|
+
{ code: "IQ", dial: "964", name: "Iraq", ar: "العراق", len: [10], mobile: /^7/, group: [3, 3, 4], sample: "790 123 4567" },
|
|
31
|
+
{ code: "EG", dial: "20", name: "Egypt", ar: "مصر", len: [10], mobile: /^1/, group: [3, 3, 4], sample: "100 123 4567" },
|
|
32
|
+
{ code: "LB", dial: "961", name: "Lebanon", ar: "لبنان", len: [7, 8], mobile: /^(3|7|8)/, group: [2, 3, 3], sample: "71 123 456" },
|
|
33
|
+
{ code: "KW", dial: "965", name: "Kuwait", ar: "الكويت", len: [8], mobile: /^[569]/, group: [4, 4], sample: "5012 3456" },
|
|
34
|
+
{ code: "QA", dial: "974", name: "Qatar", ar: "قطر", len: [8], mobile: /^[3567]/, group: [4, 4], sample: "3312 3456" },
|
|
35
|
+
{ code: "BH", dial: "973", name: "Bahrain", ar: "البحرين", len: [8], mobile: /^3/, group: [4, 4], sample: "3612 3456" },
|
|
36
|
+
{ code: "OM", dial: "968", name: "Oman", ar: "عُمان", len: [8], mobile: /^9/, group: [4, 4], sample: "9212 3456" },
|
|
37
|
+
{ code: "GB", dial: "44", name: "United Kingdom", ar: "المملكة المتحدة", len: [10], mobile: /^7/, group: [4, 3, 3], sample: "7400 123 456" },
|
|
38
|
+
{ code: "US", dial: "1", name: "United States", ar: "الولايات المتحدة", len: [10], mobile: /^/, group: [3, 3, 4], sample: "201 555 0123" },
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
/** Any other country: the person types the whole number with its code. */
|
|
42
|
+
const OTHER = "OTHER"
|
|
43
|
+
|
|
44
|
+
const ARABIC_INDIC = "٠١٢٣٤٥٦٧٨٩"
|
|
45
|
+
const EXTENDED_INDIC = "۰۱۲۳۴۵۶۷۸۹"
|
|
46
|
+
|
|
47
|
+
function westernDigits(raw: string): string {
|
|
48
|
+
return raw
|
|
49
|
+
.replace(/[٠-٩]/g, (d) => String(ARABIC_INDIC.indexOf(d)))
|
|
50
|
+
.replace(/[۰-۹]/g, (d) => String(EXTENDED_INDIC.indexOf(d)))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function groupDigits(digits: string, group: number[]): string {
|
|
54
|
+
const out: string[] = []
|
|
55
|
+
let i = 0
|
|
56
|
+
group.forEach((n, k) => {
|
|
57
|
+
if (i < digits.length) {
|
|
58
|
+
out.push(digits.substr(i, k === group.length - 1 ? 99 : n))
|
|
59
|
+
i += n
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
return out.join(" ")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The listed country and national digits of an E.164 number, or OTHER with all its digits. */
|
|
66
|
+
export function splitE164(value: string | null | undefined, fallback = "JO"): { country: string; digits: string } {
|
|
67
|
+
const raw = westernDigits(value ?? "").trim()
|
|
68
|
+
if (!raw.startsWith("+")) {
|
|
69
|
+
return { country: fallback, digits: raw.replace(/\D/g, "").replace(/^0+/, "") }
|
|
70
|
+
}
|
|
71
|
+
const all = raw.replace(/\D/g, "")
|
|
72
|
+
const match = [...phoneCountries]
|
|
73
|
+
.sort((a, b) => b.dial.length - a.dial.length)
|
|
74
|
+
.find((c) => all.startsWith(c.dial) && c.len.includes(all.length - c.dial.length))
|
|
75
|
+
return match ? { country: match.code, digits: all.slice(match.dial.length) } : { country: OTHER, digits: all }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type PhoneInputLabels = Partial<Record<"country" | "other" | "otherSample" | "short" | "long" | "mobile" | "invalid", string>>
|
|
79
|
+
|
|
80
|
+
export interface PhoneInputProps {
|
|
81
|
+
label: React.ReactNode
|
|
82
|
+
/** ISO code of the country chosen first; Jordan by default. */
|
|
83
|
+
defaultCountry?: string
|
|
84
|
+
/** A number to start from: E.164, or a national number in `defaultCountry`. */
|
|
85
|
+
defaultValue?: string | null
|
|
86
|
+
/** Only mobiles (text messages and WhatsApp). */
|
|
87
|
+
mobileOnly?: boolean
|
|
88
|
+
/** Names the countries in Arabic. */
|
|
89
|
+
lang?: "en" | "ar"
|
|
90
|
+
labels?: PhoneInputLabels
|
|
91
|
+
helperText?: React.ReactNode
|
|
92
|
+
/** An error from the server; replaces the field's own. */
|
|
93
|
+
errorText?: React.ReactNode
|
|
94
|
+
disabled?: boolean
|
|
95
|
+
readOnly?: boolean
|
|
96
|
+
id?: string
|
|
97
|
+
className?: string
|
|
98
|
+
/**
|
|
99
|
+
* When the field is left, or the country changes: the number as E.164 (null
|
|
100
|
+
* when empty) and whether it is a whole number for its country.
|
|
101
|
+
*/
|
|
102
|
+
onChange?: (e164: string | null, valid: boolean) => void
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A phone number with its country code in the same control
|
|
107
|
+
* (docs/design/components/PhoneInput). Jordan (+962) first; the national
|
|
108
|
+
* number is grouped the way it is read, a leading 0 is dropped, Arabic-Indic
|
|
109
|
+
* digits are accepted. Left to right in both languages, like every number.
|
|
110
|
+
* Errors appear once the field is left, never while typing.
|
|
111
|
+
*/
|
|
112
|
+
function PhoneInput({
|
|
113
|
+
label,
|
|
114
|
+
defaultCountry = "JO",
|
|
115
|
+
defaultValue,
|
|
116
|
+
mobileOnly = false,
|
|
117
|
+
lang = "en",
|
|
118
|
+
labels,
|
|
119
|
+
helperText,
|
|
120
|
+
errorText,
|
|
121
|
+
disabled,
|
|
122
|
+
readOnly,
|
|
123
|
+
id,
|
|
124
|
+
className,
|
|
125
|
+
onChange,
|
|
126
|
+
}: PhoneInputProps) {
|
|
127
|
+
const reactId = React.useId()
|
|
128
|
+
const baseId = id ?? reactId
|
|
129
|
+
const L = {
|
|
130
|
+
country: "Country code",
|
|
131
|
+
other: "Other country",
|
|
132
|
+
otherSample: "+33 6 12 34 56 78",
|
|
133
|
+
short: "This number is too short for {country}.",
|
|
134
|
+
long: "This number is too long for {country}.",
|
|
135
|
+
mobile: "Use a mobile number for text messages.",
|
|
136
|
+
invalid: "Enter the number with its country code, such as +33 6 12 34 56 78.",
|
|
137
|
+
...labels,
|
|
138
|
+
}
|
|
139
|
+
const start = React.useMemo(() => splitE164(defaultValue, defaultCountry), [defaultValue, defaultCountry])
|
|
140
|
+
const [country, setCountry] = React.useState(start.country)
|
|
141
|
+
const [digits, setDigits] = React.useState(start.digits)
|
|
142
|
+
const [touched, setTouched] = React.useState(false)
|
|
143
|
+
|
|
144
|
+
const listed = phoneCountries.find((c) => c.code === country) ?? null
|
|
145
|
+
const name = listed ? (lang === "ar" ? listed.ar : listed.name) : L.other
|
|
146
|
+
|
|
147
|
+
const problem = (code: string, d: string): string | null => {
|
|
148
|
+
if (d === "") return null
|
|
149
|
+
const c = phoneCountries.find((x) => x.code === code)
|
|
150
|
+
const cname = c ? (lang === "ar" ? c.ar : c.name) : ""
|
|
151
|
+
if (!c) return d.length < 7 || d.length > 15 || d.startsWith("0") ? L.invalid : null
|
|
152
|
+
if (d.length < Math.min(...c.len)) return L.short.replace("{country}", cname)
|
|
153
|
+
if (d.length > Math.max(...c.len)) return L.long.replace("{country}", cname)
|
|
154
|
+
if (mobileOnly && !c.mobile.test(d)) return L.mobile
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
const e164 = (code: string, d: string): string | null => {
|
|
158
|
+
if (d === "") return null
|
|
159
|
+
const c = phoneCountries.find((x) => x.code === code)
|
|
160
|
+
return "+" + (c ? c.dial : "") + d
|
|
161
|
+
}
|
|
162
|
+
const emit = (code: string, d: string) => onChange?.(e164(code, d), problem(code, d) === null)
|
|
163
|
+
|
|
164
|
+
const ownError = touched ? problem(country, digits) : null
|
|
165
|
+
const error = errorText ?? ownError
|
|
166
|
+
const describedBy = error ? `${baseId}-error` : helperText ? `${baseId}-help` : undefined
|
|
167
|
+
|
|
168
|
+
const read = (raw: string): string => {
|
|
169
|
+
let d = westernDigits(raw).replace(/\D/g, "")
|
|
170
|
+
if (listed && d.startsWith(listed.dial) && d.length > Math.max(...listed.len)) d = d.slice(listed.dial.length)
|
|
171
|
+
return listed ? d.replace(/^0+/, "") : d
|
|
172
|
+
}
|
|
173
|
+
const shown = listed ? groupDigits(digits, typeof listed.group === "function" ? listed.group(digits) : listed.group) : digits ? "+" + digits : ""
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div className={cn("space-y-1.5", className)}>
|
|
177
|
+
<label htmlFor={baseId} className="block text-sm font-medium text-foreground">
|
|
178
|
+
{label}
|
|
179
|
+
</label>
|
|
180
|
+
<div
|
|
181
|
+
dir="ltr"
|
|
182
|
+
data-slot="phone-input"
|
|
183
|
+
className={cn(
|
|
184
|
+
"flex h-10 overflow-hidden rounded-control border bg-card focus-within:ring-2 focus-within:ring-ring",
|
|
185
|
+
error ? "border-destructive" : "border-input",
|
|
186
|
+
disabled && "opacity-50"
|
|
187
|
+
)}
|
|
188
|
+
>
|
|
189
|
+
<label className="relative inline-flex shrink-0 items-center gap-1 border-e border-input bg-muted pe-2 ps-2.5 font-mono text-sm text-foreground">
|
|
190
|
+
<span className="sr-only">{L.country}</span>
|
|
191
|
+
<select
|
|
192
|
+
className="absolute inset-0 cursor-pointer opacity-0"
|
|
193
|
+
value={country}
|
|
194
|
+
disabled={disabled || readOnly}
|
|
195
|
+
data-testid={`${baseId}-country`}
|
|
196
|
+
onChange={(event) => {
|
|
197
|
+
const next = event.target.value
|
|
198
|
+
const from = listed
|
|
199
|
+
// Keep what was typed: moving to Other carries the code along, and back strips it.
|
|
200
|
+
let d = digits
|
|
201
|
+
if (next === OTHER && from && d !== "") d = from.dial + d
|
|
202
|
+
const to = phoneCountries.find((x) => x.code === next)
|
|
203
|
+
if (from === null && to && d.startsWith(to.dial)) d = d.slice(to.dial.length)
|
|
204
|
+
setCountry(next)
|
|
205
|
+
setDigits(d)
|
|
206
|
+
emit(next, d)
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
{phoneCountries.map((c) => (
|
|
210
|
+
<option key={c.code} value={c.code}>
|
|
211
|
+
{(lang === "ar" ? c.ar : c.name) + " +" + c.dial}
|
|
212
|
+
</option>
|
|
213
|
+
))}
|
|
214
|
+
<option value={OTHER}>{L.other}</option>
|
|
215
|
+
</select>
|
|
216
|
+
<span aria-hidden="true">{listed ? "+" + listed.dial : "+"}</span>
|
|
217
|
+
<Icon name="chevron-down" size={14} className="text-muted-foreground" />
|
|
218
|
+
</label>
|
|
219
|
+
<input
|
|
220
|
+
id={baseId}
|
|
221
|
+
type="tel"
|
|
222
|
+
inputMode="tel"
|
|
223
|
+
autoComplete={listed ? "tel-national" : "tel"}
|
|
224
|
+
placeholder={listed ? listed.sample : L.otherSample}
|
|
225
|
+
className="min-w-0 flex-1 bg-transparent px-2.5 text-sm tabular-nums text-foreground outline-none"
|
|
226
|
+
value={shown}
|
|
227
|
+
disabled={disabled}
|
|
228
|
+
readOnly={readOnly}
|
|
229
|
+
aria-invalid={error ? true : undefined}
|
|
230
|
+
aria-describedby={describedBy}
|
|
231
|
+
title={name}
|
|
232
|
+
onChange={(event) => setDigits(read(event.target.value))}
|
|
233
|
+
onBlur={() => {
|
|
234
|
+
setTouched(true)
|
|
235
|
+
emit(country, digits)
|
|
236
|
+
}}
|
|
237
|
+
/>
|
|
238
|
+
</div>
|
|
239
|
+
{error ? (
|
|
240
|
+
<p id={`${baseId}-error`} role="alert" className="text-sm text-destructive">
|
|
241
|
+
{error}
|
|
242
|
+
</p>
|
|
243
|
+
) : helperText ? (
|
|
244
|
+
<p id={`${baseId}-help`} className="text-sm text-muted-foreground">
|
|
245
|
+
{helperText}
|
|
246
|
+
</p>
|
|
247
|
+
) : null}
|
|
248
|
+
</div>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { PhoneInput }
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { fn } from "storybook/test"
|
|
3
|
+
|
|
4
|
+
import { Avatar } from "./avatar"
|
|
5
|
+
import { RoleSummary } from "./role-summary"
|
|
6
|
+
import { TenantSwitcher } from "./tenant-switcher"
|
|
7
|
+
|
|
8
|
+
// WHIT-1175: eight long role names, as in the owner's report.
|
|
9
|
+
const EN = [
|
|
10
|
+
"Head of finance and accounts",
|
|
11
|
+
"Branch manager for the north region",
|
|
12
|
+
"Document approver",
|
|
13
|
+
"Inventory controller",
|
|
14
|
+
"Customer service supervisor",
|
|
15
|
+
"Payroll officer",
|
|
16
|
+
"Marketing coordinator",
|
|
17
|
+
"Quality assurance reviewer",
|
|
18
|
+
]
|
|
19
|
+
const AR = [
|
|
20
|
+
"رئيس قسم المالية والحسابات",
|
|
21
|
+
"مدير فرع المنطقة الشمالية",
|
|
22
|
+
"معتمد المستندات",
|
|
23
|
+
"مراقب المخزون",
|
|
24
|
+
"مشرف خدمة العملاء",
|
|
25
|
+
"موظف الرواتب",
|
|
26
|
+
"منسق التسويق",
|
|
27
|
+
"مراجع ضمان الجودة",
|
|
28
|
+
]
|
|
29
|
+
const AR_LABELS = {
|
|
30
|
+
more: (count: number) => `+${count} أخرى`,
|
|
31
|
+
separator: "، ",
|
|
32
|
+
all: "كل الأدوار: {roles}",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const meta = {
|
|
36
|
+
title: "People/RoleSummary",
|
|
37
|
+
component: RoleSummary,
|
|
38
|
+
tags: ["autodocs"],
|
|
39
|
+
args: { roles: EN },
|
|
40
|
+
} satisfies Meta<typeof RoleSummary>
|
|
41
|
+
|
|
42
|
+
export default meta
|
|
43
|
+
type Story = StoryObj<typeof meta>
|
|
44
|
+
|
|
45
|
+
/** The first role and "+7 more" on one line. */
|
|
46
|
+
export const ManyRoles: Story = {
|
|
47
|
+
decorators: [
|
|
48
|
+
(Story) => (
|
|
49
|
+
<div style={{ width: 240 }} className="text-xs text-muted-foreground">
|
|
50
|
+
<Story />
|
|
51
|
+
</div>
|
|
52
|
+
),
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One role is just the role. */
|
|
57
|
+
export const OneRole: Story = { args: { roles: ["Branch manager"] } }
|
|
58
|
+
|
|
59
|
+
/** Outside another control: a focusable "+7 more" with the list in a tooltip. */
|
|
60
|
+
export const Interactive: Story = {
|
|
61
|
+
args: { interactive: true },
|
|
62
|
+
decorators: [
|
|
63
|
+
(Story) => (
|
|
64
|
+
<div style={{ width: 280 }} className="text-sm text-muted-foreground">
|
|
65
|
+
<Story />
|
|
66
|
+
</div>
|
|
67
|
+
),
|
|
68
|
+
],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function Surfaces({ roles, labels, name }: { roles: string[]; labels?: typeof AR_LABELS; name: string }) {
|
|
72
|
+
return (
|
|
73
|
+
<div className="grid gap-6 bg-background p-4 text-foreground">
|
|
74
|
+
{/* Sidebar foot (256px sidebar). */}
|
|
75
|
+
<div
|
|
76
|
+
style={{ width: 240 }}
|
|
77
|
+
className="flex min-h-12 items-center gap-3 rounded-lg border border-border px-2 py-2"
|
|
78
|
+
>
|
|
79
|
+
<Avatar name={name} size={32} />
|
|
80
|
+
<span className="min-w-0 flex-1">
|
|
81
|
+
<span className="block truncate text-sm font-medium">{name}</span>
|
|
82
|
+
<RoleSummary roles={roles} labels={labels} className="text-xs text-muted-foreground" />
|
|
83
|
+
</span>
|
|
84
|
+
</div>
|
|
85
|
+
{/* Workspace switcher row. */}
|
|
86
|
+
<div style={{ width: 216 }}>
|
|
87
|
+
<TenantSwitcher
|
|
88
|
+
workspaces={[
|
|
89
|
+
{
|
|
90
|
+
id: "1",
|
|
91
|
+
name: "Example Bakery",
|
|
92
|
+
roles,
|
|
93
|
+
roleBefore: labels ? "المالك" : "Owner",
|
|
94
|
+
},
|
|
95
|
+
{ id: "2", name: "Example Clinic", roles: roles.slice(0, 1) },
|
|
96
|
+
]}
|
|
97
|
+
currentId="1"
|
|
98
|
+
labels={{ roles: labels }}
|
|
99
|
+
onChange={fn()}
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
{/* Sign-in workspace picker button. */}
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
style={{ width: 340 }}
|
|
106
|
+
className="flex h-10 items-center justify-between gap-3 rounded-control border border-border px-4 text-sm"
|
|
107
|
+
>
|
|
108
|
+
<span className="min-w-0 truncate">Example Bakery</span>
|
|
109
|
+
<RoleSummary roles={roles} labels={labels} className="max-w-[50%] shrink text-xs text-muted-foreground" />
|
|
110
|
+
</button>
|
|
111
|
+
{/* More page profile row on a phone (375px). */}
|
|
112
|
+
<div style={{ width: 343 }} className="flex min-h-16 items-center gap-3 rounded-lg border border-border px-4">
|
|
113
|
+
<Avatar name={name} size={40} />
|
|
114
|
+
<span className="min-w-0 flex-1">
|
|
115
|
+
<span className="block truncate text-base font-medium">{name}</span>
|
|
116
|
+
<RoleSummary
|
|
117
|
+
roles={roles}
|
|
118
|
+
before={labels ? "الملف الشخصي" : "Profile"}
|
|
119
|
+
after="Example Bakery"
|
|
120
|
+
labels={labels}
|
|
121
|
+
className="text-sm text-muted-foreground"
|
|
122
|
+
/>
|
|
123
|
+
</span>
|
|
124
|
+
</div>
|
|
125
|
+
{/* Your role › other workspaces. */}
|
|
126
|
+
<div style={{ width: 343 }} className="flex items-center justify-between gap-3 py-2.5 text-sm">
|
|
127
|
+
<span className="shrink-0">Example Clinic</span>
|
|
128
|
+
<RoleSummary roles={roles} labels={labels} interactive className="justify-end text-muted-foreground" />
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Every place a person's roles sit under their name, in English. */
|
|
135
|
+
export const EverySurfaceEnglish: Story = {
|
|
136
|
+
render: () => <Surfaces roles={EN} name="Amro Saleh" />,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The same in Arabic; switch Direction to RTL. */
|
|
140
|
+
export const EverySurfaceArabic: Story = {
|
|
141
|
+
globals: { direction: "rtl" },
|
|
142
|
+
render: () => <Surfaces roles={AR} labels={AR_LABELS} name="عمرو صالح" />,
|
|
143
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip"
|
|
4
|
+
import { cn } from "./utils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A person's roles as a one-line subtitle under their name (WHIT-1175).
|
|
8
|
+
*
|
|
9
|
+
* Since a person can hold several roles in one workspace (WHIT-1079), joining
|
|
10
|
+
* them all made the line under a name as long as the list, and with many roles
|
|
11
|
+
* it pushed rows apart. This shows the first role and "+N more" on one line:
|
|
12
|
+
* the first role truncates with an ellipsis, the count never does, and nothing
|
|
13
|
+
* wraps. The whole list stays reachable:
|
|
14
|
+
*
|
|
15
|
+
* - on hover, through the `title`;
|
|
16
|
+
* - for screen readers, as hidden text read in place of the short form;
|
|
17
|
+
* - with `interactive`, through a focusable "+N more" with a tooltip, for a
|
|
18
|
+
* summary that is not already inside a button or link. Inside a control
|
|
19
|
+
* (a menu trigger, a picker row) a second focus stop is not allowed, so the
|
|
20
|
+
* control's own name carries the list and the screen it opens shows it.
|
|
21
|
+
*
|
|
22
|
+
* `before` and `after` are words that share the line, such as "Owner" or the
|
|
23
|
+
* workspace name; they stay readable but give way to the roles' count first.
|
|
24
|
+
* Every visible string is a label with an English default.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export interface RoleSummaryLabels {
|
|
28
|
+
/** "+{count} more" after the first role. */
|
|
29
|
+
more?: (count: number) => string
|
|
30
|
+
/** Between roles in the full list. */
|
|
31
|
+
separator?: string
|
|
32
|
+
/** Between `before`, the roles and `after`. */
|
|
33
|
+
joiner?: string
|
|
34
|
+
/** Accessible name of the interactive "+N more"; `{roles}` is the full list. */
|
|
35
|
+
all?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RoleSummaryProps {
|
|
39
|
+
/** Role names, already in words, the primary one first. */
|
|
40
|
+
roles: readonly string[]
|
|
41
|
+
before?: string
|
|
42
|
+
after?: string
|
|
43
|
+
/** A focusable "+N more" with a tooltip; only outside another control. */
|
|
44
|
+
interactive?: boolean
|
|
45
|
+
labels?: RoleSummaryLabels
|
|
46
|
+
className?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const defaultMore = (count: number) => `+${count} more`
|
|
50
|
+
|
|
51
|
+
/** The roles once each, in order, without empty names. */
|
|
52
|
+
export function uniqueRoles(roles: readonly string[]): string[] {
|
|
53
|
+
return roles.filter((role, index) => role.trim() !== "" && roles.indexOf(role) === index)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The full sentence: before, every role, after. */
|
|
57
|
+
export function roleSummaryText(
|
|
58
|
+
roles: readonly string[],
|
|
59
|
+
{ before, after, labels = {} }: Pick<RoleSummaryProps, "before" | "after" | "labels"> = {},
|
|
60
|
+
): string {
|
|
61
|
+
const list = uniqueRoles(roles).join(labels.separator ?? ", ")
|
|
62
|
+
return [before, list, after].filter((part) => part !== undefined && part !== "").join(labels.joiner ?? " · ")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function RoleSummary({ roles, before, after, interactive = false, labels = {}, className }: RoleSummaryProps) {
|
|
66
|
+
const names = uniqueRoles(roles)
|
|
67
|
+
const full = roleSummaryText(names, { before, after, labels })
|
|
68
|
+
if (full === "") return null
|
|
69
|
+
|
|
70
|
+
const joiner = labels.joiner ?? " · "
|
|
71
|
+
const hidden = names.length - 1
|
|
72
|
+
const more = hidden > 0 ? (labels.more ?? defaultMore)(hidden) : ""
|
|
73
|
+
const lead = [before, names[0]].filter((part) => part !== undefined && part !== "").join(joiner)
|
|
74
|
+
const visualOnly = interactive ? undefined : true
|
|
75
|
+
const allLabel = (labels.all ?? "All roles: {roles}").replace("{roles}", names.join(labels.separator ?? ", "))
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<span
|
|
79
|
+
data-slot="role-summary"
|
|
80
|
+
title={hidden > 0 ? full : undefined}
|
|
81
|
+
className={cn("flex min-w-0 max-w-full items-baseline gap-1 overflow-hidden whitespace-nowrap", className)}
|
|
82
|
+
>
|
|
83
|
+
{/* Without `interactive` the short form is for the eyes only and the full list for screen readers. */}
|
|
84
|
+
{!interactive && <span className="sr-only">{full}</span>}
|
|
85
|
+
{lead !== "" && (
|
|
86
|
+
<span aria-hidden={visualOnly} className="min-w-0 truncate">
|
|
87
|
+
{lead}
|
|
88
|
+
</span>
|
|
89
|
+
)}
|
|
90
|
+
{hidden > 0 &&
|
|
91
|
+
(interactive ? (
|
|
92
|
+
<Tooltip>
|
|
93
|
+
<TooltipTrigger asChild>
|
|
94
|
+
<button
|
|
95
|
+
type="button"
|
|
96
|
+
aria-label={allLabel}
|
|
97
|
+
data-slot="role-summary-more"
|
|
98
|
+
className="shrink-0 rounded-sm underline decoration-dotted underline-offset-2 outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
99
|
+
>
|
|
100
|
+
{more}
|
|
101
|
+
</button>
|
|
102
|
+
</TooltipTrigger>
|
|
103
|
+
<TooltipContent>{names.join(labels.separator ?? ", ")}</TooltipContent>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
) : (
|
|
106
|
+
<span aria-hidden={visualOnly} data-slot="role-summary-more" className="shrink-0">
|
|
107
|
+
{more}
|
|
108
|
+
</span>
|
|
109
|
+
))}
|
|
110
|
+
{after !== undefined && after !== "" && (
|
|
111
|
+
<span aria-hidden={visualOnly} className="min-w-0 truncate">
|
|
112
|
+
{joiner.trimStart()}
|
|
113
|
+
{after}
|
|
114
|
+
</span>
|
|
115
|
+
)}
|
|
116
|
+
</span>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { RoleSummary }
|
package/src/tenant-switcher.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import * as React from "react"
|
|
|
4
4
|
import { IconCheck, IconPlus, IconSearch, IconSelector } from "@tabler/icons-react"
|
|
5
5
|
|
|
6
6
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
7
|
+
import { RoleSummary, type RoleSummaryLabels } from "./role-summary"
|
|
7
8
|
import { TenantLogo } from "./tenant-logo"
|
|
8
9
|
import { cn } from "./utils"
|
|
9
10
|
|
|
@@ -23,6 +24,13 @@ export interface TenantSwitcherWorkspace {
|
|
|
23
24
|
name: string
|
|
24
25
|
/** The person's role in this workspace, shown under its name. */
|
|
25
26
|
role?: string
|
|
27
|
+
/**
|
|
28
|
+
* Every role held here, the primary first. Takes the place of `role` and
|
|
29
|
+
* shows as one line: the first role and "+N more" (WHIT-1175).
|
|
30
|
+
*/
|
|
31
|
+
roles?: string[]
|
|
32
|
+
/** Words before the roles on that line, such as "Owner". */
|
|
33
|
+
roleBefore?: string
|
|
26
34
|
logoUrl?: string | null
|
|
27
35
|
}
|
|
28
36
|
|
|
@@ -32,6 +40,8 @@ export interface TenantSwitcherLabels {
|
|
|
32
40
|
find?: string
|
|
33
41
|
noResults?: string
|
|
34
42
|
create?: string
|
|
43
|
+
/** The "+N more" and list labels of each row's roles. */
|
|
44
|
+
roles?: RoleSummaryLabels
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
export interface TenantSwitcherProps {
|
|
@@ -113,11 +123,11 @@ function TenantSwitcher({
|
|
|
113
123
|
/>
|
|
114
124
|
</div>
|
|
115
125
|
)}
|
|
116
|
-
<ul role="listbox" aria-label={labels.find ?? "Find a workspace"} className="grid gap-px">
|
|
126
|
+
<ul role="listbox" aria-label={labels.find ?? "Find a workspace"} className="grid grid-cols-1 gap-px">
|
|
117
127
|
{shown.map((workspace) => {
|
|
118
128
|
const selected = workspace.id === current?.id
|
|
119
129
|
return (
|
|
120
|
-
<li key={workspace.id} role="option" aria-selected={selected}>
|
|
130
|
+
<li key={workspace.id} role="option" aria-selected={selected} className="min-w-0">
|
|
121
131
|
<button
|
|
122
132
|
type="button"
|
|
123
133
|
onClick={() => choose(workspace.id)}
|
|
@@ -131,8 +141,19 @@ function TenantSwitcher({
|
|
|
131
141
|
<span className={cn("block truncate text-sm", selected ? "text-primary-tint-foreground" : "text-foreground")}>
|
|
132
142
|
{workspace.name}
|
|
133
143
|
</span>
|
|
134
|
-
{workspace.
|
|
135
|
-
<
|
|
144
|
+
{workspace.roles && workspace.roles.length > 0 ? (
|
|
145
|
+
<RoleSummary
|
|
146
|
+
roles={workspace.roles}
|
|
147
|
+
before={workspace.roleBefore}
|
|
148
|
+
labels={labels.roles}
|
|
149
|
+
className="text-xs text-muted-foreground"
|
|
150
|
+
/>
|
|
151
|
+
) : (
|
|
152
|
+
(workspace.roleBefore || workspace.role) && (
|
|
153
|
+
<span className="block truncate text-xs text-muted-foreground">
|
|
154
|
+
{[workspace.roleBefore, workspace.role].filter(Boolean).join(" · ")}
|
|
155
|
+
</span>
|
|
156
|
+
)
|
|
136
157
|
)}
|
|
137
158
|
</span>
|
|
138
159
|
{selected && <IconCheck aria-hidden="true" className="size-4 shrink-0" />}
|
package/src/theme-mode.ts
CHANGED
|
@@ -38,6 +38,28 @@ export function resolveIsDark(preference: ThemeModePreference | null | undefined
|
|
|
38
38
|
return preference === 'dark' || (preference !== 'light' && systemPrefersDark);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// U+2028 and U+2029 (line and paragraph separator) are built from their code
|
|
42
|
+
// points rather than written as escapes: some transpilers emit an escape
|
|
43
|
+
// inside a regex literal as the raw character, which then ends the line.
|
|
44
|
+
const LINE_SEPARATOR = String.fromCharCode(0x2028);
|
|
45
|
+
const PARAGRAPH_SEPARATOR = String.fromCharCode(0x2029);
|
|
46
|
+
const SCRIPT_UNSAFE_PATTERN = new RegExp(`[<>/${LINE_SEPARATOR}${PARAGRAPH_SEPARATOR}]`, 'g');
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A JS string literal that is also safe inside an inline `<script>` element.
|
|
50
|
+
* JSON.stringify alone escapes quotes and backslashes but not `</script>` or
|
|
51
|
+
* the two line separators an older parser treats as newlines, so a value
|
|
52
|
+
* carrying either could close the element or break the statement. The key
|
|
53
|
+
* is a constant today; this keeps it safe if it ever is not (WHIT-1236,
|
|
54
|
+
* CodeQL js/bad-code-sanitization).
|
|
55
|
+
*/
|
|
56
|
+
export function scriptSafeStringLiteral(value: string): string {
|
|
57
|
+
return JSON.stringify(value).replace(
|
|
58
|
+
SCRIPT_UNSAFE_PATTERN,
|
|
59
|
+
(c) => `\\u${c.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
41
63
|
/**
|
|
42
64
|
* Source for a blocking `<script>` that must run as early as possible in
|
|
43
65
|
* `<head>` (before any stylesheet / styled content) so `.dark` lands on
|
|
@@ -47,6 +69,6 @@ export function resolveIsDark(preference: ThemeModePreference | null | undefined
|
|
|
47
69
|
* the actual `<script>` element.
|
|
48
70
|
*/
|
|
49
71
|
export function buildThemeInitScript(): string {
|
|
50
|
-
const key =
|
|
72
|
+
const key = scriptSafeStringLiteral(THEME_STORAGE_KEY);
|
|
51
73
|
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
74
|
}
|
package/src/time-picker.tsx
CHANGED
|
@@ -369,6 +369,7 @@ const TimePicker = React.forwardRef<HTMLDivElement, TimePickerProps>(
|
|
|
369
369
|
<button
|
|
370
370
|
type="button"
|
|
371
371
|
id={id}
|
|
372
|
+
data-slot="time-picker-trigger"
|
|
372
373
|
disabled={disabled}
|
|
373
374
|
className={cn(
|
|
374
375
|
"relative flex h-7 w-full items-center justify-start rounded-md border border-input bg-card ps-8 pe-8 py-0.5 text-xs font-medium text-foreground transition-colors outline-none 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",
|
package/src/toggle-group.tsx
CHANGED
|
@@ -113,7 +113,8 @@ function ToggleGroup({
|
|
|
113
113
|
"data-[state=on]:bg-primary-tint data-[state=on]:text-primary-tint-foreground",
|
|
114
114
|
size === "sm"
|
|
115
115
|
? cn("h-[22px] rounded-[5px] text-[0.8125rem]", iconOnly ? "w-[22px]" : "px-2")
|
|
116
|
-
:
|
|
116
|
+
: // TH.18: a selected chip goes from pill to rounded when the theme morphs.
|
|
117
|
+
cn("h-[30px] rounded-control-sm text-sm transition-[border-radius] duration-(--dur-morph) data-[state=on]:rounded-control-selected", iconOnly ? "w-[30px]" : "px-2.5")
|
|
117
118
|
)}
|
|
118
119
|
>
|
|
119
120
|
{option.icon && <Icon name={option.icon} />}
|
package/src/view-toggle.tsx
CHANGED
|
@@ -75,7 +75,8 @@ function ViewToggle<TValue extends string>({
|
|
|
75
75
|
<div
|
|
76
76
|
role="group"
|
|
77
77
|
aria-label={label}
|
|
78
|
-
|
|
78
|
+
data-slot="view-toggle"
|
|
79
|
+
className={cn("flex items-center overflow-hidden rounded-md border border-border", className)}
|
|
79
80
|
>
|
|
80
81
|
{options.map((option) => {
|
|
81
82
|
const active = option.value === value
|