@podoba/react 0.0.52 → 0.0.53
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 +4 -4
- package/src/components/asset-selection-surface.tsx +264 -67
- package/src/components/citation.examples.tsx +14 -0
- package/src/components/citation.tsx +27 -0
- package/src/components/column-layout.examples.tsx +34 -0
- package/src/components/column-layout.tsx +36 -0
- package/src/components/combobox.tsx +9 -4
- package/src/components/compact-settings-dialog.tsx +80 -21
- package/src/components/date-picker.tsx +49 -8
- package/src/components/delivery/send-to-print-modal.tsx +191 -225
- package/src/components/field-appearance.ts +11 -1
- package/src/components/icon-button.examples.tsx +16 -0
- package/src/components/icon-button.tsx +20 -0
- package/src/components/input.tsx +25 -12
- package/src/components/island-toolbar.examples.tsx +27 -0
- package/src/components/island-toolbar.tsx +39 -0
- package/src/components/media-asset-panel.examples.tsx +44 -5
- package/src/components/media-asset-panel.tsx +339 -28
- package/src/components/media-collection.examples.tsx +18 -0
- package/src/components/media-collection.tsx +206 -0
- package/src/components/number-field.tsx +18 -9
- package/src/components/preview-error.examples.tsx +20 -0
- package/src/components/preview-error.tsx +29 -0
- package/src/components/preview-metadata-card.examples.tsx +32 -0
- package/src/components/preview-metadata-card.tsx +112 -0
- package/src/components/search-field.tsx +27 -7
- package/src/components/select.tsx +81 -50
- package/src/components/settings-dialog-surface.tsx +553 -114
- package/src/components/template-catalog-card.tsx +309 -78
- package/src/components/textarea.tsx +160 -12
- package/src/components/tile.tsx +30 -16
- package/src/components/zoomable-image.examples.tsx +33 -0
- package/src/components/zoomable-image.tsx +185 -0
- package/src/index.ts +96 -78
|
@@ -9,7 +9,8 @@ export type TemplateCatalogSelection = (typeof TEMPLATE_CATALOG_SELECTIONS)[numb
|
|
|
9
9
|
/** Legacy StatsCard label-1 value, distinct from the Tile heading ramp. */
|
|
10
10
|
export const CatalogMetricValue = uic('span', {
|
|
11
11
|
displayName: 'CatalogMetricValue',
|
|
12
|
-
baseClass:
|
|
12
|
+
baseClass:
|
|
13
|
+
'block w-full text-center text-display-large font-medium leading-(--line-height-display-large) tracking-wider',
|
|
13
14
|
})
|
|
14
15
|
|
|
15
16
|
export const CATALOG_METRIC_FOOTERS = ['present', 'missing'] as const
|
|
@@ -21,42 +22,111 @@ const MetricContent = uic('div', {
|
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
/** Compact source statistics: preserve the centered content band without a tail. */
|
|
24
|
-
export function CatalogMetricCard({
|
|
25
|
-
title
|
|
25
|
+
export function CatalogMetricCard({
|
|
26
|
+
title,
|
|
27
|
+
value,
|
|
28
|
+
footer,
|
|
29
|
+
onPress,
|
|
30
|
+
'aria-label': ariaLabel,
|
|
31
|
+
}: {
|
|
32
|
+
title: string
|
|
33
|
+
value: ReactNode
|
|
34
|
+
footer?: string
|
|
35
|
+
onPress?: () => void
|
|
36
|
+
'aria-label'?: string
|
|
26
37
|
}) {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
return (
|
|
39
|
+
<Tile
|
|
40
|
+
theme="light"
|
|
41
|
+
eyebrow={title}
|
|
42
|
+
footer={footer || undefined}
|
|
43
|
+
onPress={onPress}
|
|
44
|
+
aria-label={ariaLabel}
|
|
45
|
+
className="h-52 min-h-52 max-h-52"
|
|
46
|
+
>
|
|
47
|
+
<MetricContent data-slot="catalog-metric-content" footer={footer ? 'present' : 'missing'}>
|
|
48
|
+
<CatalogMetricValue>{value}</CatalogMetricValue>
|
|
49
|
+
</MetricContent>
|
|
50
|
+
</Tile>
|
|
51
|
+
)
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
const SummaryCard = uic('article', {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
54
|
+
const SummaryCard = uic('article', {
|
|
55
|
+
displayName: 'CatalogSummaryCard',
|
|
56
|
+
baseClass: 'flex h-95 w-full min-w-0 flex-col gap-6 overflow-hidden rounded-lg bg-surface-card p-4 text-fg',
|
|
57
|
+
})
|
|
58
|
+
export const CatalogSummaryGrid = uic('div', {
|
|
59
|
+
displayName: 'CatalogSummaryGrid',
|
|
60
|
+
baseClass:
|
|
61
|
+
'grid w-full min-w-0 grid-cols-1 gap-x-2 gap-y-4 overflow-x-hidden min-[768px]:grid-cols-3 min-[768px]:gap-x-3',
|
|
62
|
+
})
|
|
63
|
+
const SummaryHead = uic('div', {
|
|
64
|
+
displayName: 'CatalogSummaryHead',
|
|
65
|
+
baseClass: 'flex w-full min-w-0 items-center justify-between gap-3',
|
|
66
|
+
})
|
|
67
|
+
export const CatalogSummaryBadge = uic('span', {
|
|
68
|
+
displayName: 'CatalogSummaryBadge',
|
|
69
|
+
baseClass: 'ml-3 flex h-6 shrink-0 items-center rounded-2xl px-2.5 text-micro font-medium leading-5',
|
|
70
|
+
style: { fontFeatureSettings: '"liga" off, "clig" off' },
|
|
71
|
+
variants: {
|
|
72
|
+
color: { green: 'bg-brand-green text-fg-on-brand', grey: 'bg-surface-muted text-(--color-neutral-600)' },
|
|
73
|
+
},
|
|
74
|
+
defaultVariants: { color: 'grey' },
|
|
75
|
+
})
|
|
76
|
+
const SummaryTitle = uic('h2', {
|
|
77
|
+
displayName: 'CatalogSummaryTitle',
|
|
78
|
+
baseClass: 'm-0 min-w-0 truncate text-heading5 font-medium',
|
|
79
|
+
})
|
|
80
|
+
const SummaryTail = uic('div', {
|
|
81
|
+
displayName: 'CatalogSummaryTail',
|
|
82
|
+
baseClass: 'mt-auto flex flex-col gap-1 text-small font-normal text-fg-muted',
|
|
83
|
+
})
|
|
41
84
|
/** Source gs Tile image cover: caller artwork under a transparent → 30% → 50% black gradient. */
|
|
42
85
|
function CatalogCover({ preview }: { preview: ReactNode }) {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<div
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
className="absolute inset-0 -z-10 overflow-hidden [&_canvas]:size-full [&_canvas]:object-cover [&_img]:size-full [&_img]:object-cover"
|
|
91
|
+
>
|
|
92
|
+
{preview}
|
|
93
|
+
</div>
|
|
94
|
+
<div aria-hidden="true" className="absolute inset-0 -z-10 bg-linear-to-b from-black/0 via-black/30 to-black/50" />
|
|
95
|
+
</>
|
|
96
|
+
)
|
|
47
97
|
}
|
|
48
98
|
|
|
49
99
|
/**
|
|
50
100
|
* Display-only catalog tile. No synthetic imagery when a preview is absent. An optional
|
|
51
101
|
* real `preview` covers the card with the source gradient and switches the ink to white.
|
|
52
102
|
*/
|
|
53
|
-
export function CatalogSummaryCard({
|
|
103
|
+
export function CatalogSummaryCard({
|
|
104
|
+
title,
|
|
105
|
+
badge,
|
|
106
|
+
description,
|
|
107
|
+
details,
|
|
108
|
+
preview,
|
|
109
|
+
}: {
|
|
110
|
+
title: string
|
|
111
|
+
badge: ReactNode
|
|
112
|
+
description?: string
|
|
113
|
+
details: ReactNode
|
|
114
|
+
preview?: ReactNode
|
|
115
|
+
}) {
|
|
54
116
|
const covered = preview != null
|
|
55
|
-
return
|
|
56
|
-
{covered
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
117
|
+
return (
|
|
118
|
+
<SummaryCard data-preview={covered || undefined} className={covered ? 'relative isolate' : undefined}>
|
|
119
|
+
{covered ? <CatalogCover preview={preview} /> : null}
|
|
120
|
+
<SummaryHead>
|
|
121
|
+
<SummaryTitle className={covered ? 'text-white' : undefined}>{title}</SummaryTitle>
|
|
122
|
+
<span className="shrink-0">{badge}</span>
|
|
123
|
+
</SummaryHead>
|
|
124
|
+
<SummaryTail className={covered ? 'text-white/88' : undefined}>
|
|
125
|
+
{description ? <p className="m-0">{description}</p> : null}
|
|
126
|
+
<span>{details}</span>
|
|
127
|
+
</SummaryTail>
|
|
128
|
+
</SummaryCard>
|
|
129
|
+
)
|
|
60
130
|
}
|
|
61
131
|
|
|
62
132
|
/**
|
|
@@ -65,36 +135,100 @@ export function CatalogSummaryCard({ title, badge, description, details, preview
|
|
|
65
135
|
* under the source gs Tile image gradient (transparent → 30% → 50% black), and the
|
|
66
136
|
* title and tail switch to the source white / white 88% ink.
|
|
67
137
|
*/
|
|
68
|
-
export function CatalogLaunchCard({
|
|
138
|
+
export function CatalogLaunchCard({
|
|
139
|
+
title,
|
|
140
|
+
description,
|
|
141
|
+
details,
|
|
142
|
+
action,
|
|
143
|
+
preview,
|
|
144
|
+
}: {
|
|
145
|
+
title: string
|
|
146
|
+
description?: string
|
|
147
|
+
details: ReactNode
|
|
148
|
+
action: ReactNode
|
|
149
|
+
preview?: ReactNode
|
|
150
|
+
}) {
|
|
69
151
|
const covered = preview != null
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
152
|
+
return (
|
|
153
|
+
<SummaryCard
|
|
154
|
+
data-testid="scenario-launch-card"
|
|
155
|
+
data-preview={covered || undefined}
|
|
156
|
+
className="relative isolate h-70 min-h-70 max-h-70 transition-colors duration-200 focus-within:ring-2 focus-within:ring-ring"
|
|
157
|
+
>
|
|
158
|
+
{covered ? <CatalogCover preview={preview} /> : null}
|
|
159
|
+
<SummaryHead>
|
|
160
|
+
<SummaryTitle asChild className={covered ? 'text-white' : undefined}>
|
|
161
|
+
<h3>{title}</h3>
|
|
162
|
+
</SummaryTitle>
|
|
163
|
+
</SummaryHead>
|
|
164
|
+
<SummaryTail className={covered ? 'text-white/88' : undefined}>
|
|
165
|
+
{description ? <p className="m-0">{description}</p> : null}
|
|
166
|
+
<span>{details}</span>
|
|
167
|
+
</SummaryTail>
|
|
168
|
+
{action}
|
|
169
|
+
</SummaryCard>
|
|
170
|
+
)
|
|
76
171
|
}
|
|
77
172
|
|
|
78
173
|
const MetadataSection = uic('section', { displayName: 'CatalogMetadataSection', baseClass: 'm-0 w-full' })
|
|
79
174
|
/** Source metadata layout: full-width identity, paired attributes, wrapping IDs. */
|
|
80
|
-
export function CatalogMetadataSummary({
|
|
81
|
-
title
|
|
175
|
+
export function CatalogMetadataSummary({
|
|
176
|
+
title,
|
|
177
|
+
ariaLabel,
|
|
178
|
+
items,
|
|
179
|
+
density = 'default',
|
|
180
|
+
}: {
|
|
181
|
+
title: string
|
|
182
|
+
ariaLabel: string
|
|
183
|
+
density?: 'default' | 'compact'
|
|
184
|
+
items: { label: string; value: ReactNode; fullWidth?: boolean }[]
|
|
82
185
|
}) {
|
|
83
186
|
let column = 0
|
|
84
|
-
return
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
187
|
+
return (
|
|
188
|
+
<MetadataSection aria-label={ariaLabel}>
|
|
189
|
+
<h2
|
|
190
|
+
className={
|
|
191
|
+
density === 'compact'
|
|
192
|
+
? 'mb-3 mt-0 text-small font-medium text-fg'
|
|
193
|
+
: 'mb-3 mt-0 text-heading3 font-medium text-fg'
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
{title}
|
|
197
|
+
</h2>
|
|
198
|
+
<dl className="m-0 grid w-full grid-cols-1 border-t border-border min-[641px]:grid-cols-2">
|
|
199
|
+
{items.map((item) => {
|
|
200
|
+
const second = !item.fullWidth && column % 2 === 1
|
|
201
|
+
column = item.fullWidth ? 0 : column + 1
|
|
202
|
+
return (
|
|
203
|
+
<div
|
|
204
|
+
key={item.label}
|
|
205
|
+
className={`flex min-w-0 flex-col gap-1 border-b border-border py-3 ${item.fullWidth ? 'col-span-full' : ''} ${second ? 'min-[641px]:border-l min-[641px]:pl-3' : ''}`}
|
|
206
|
+
>
|
|
207
|
+
{/* #25: the term of a definition list is meaningful copy — AA `fg-muted`. */}
|
|
208
|
+
<dt
|
|
209
|
+
className={
|
|
210
|
+
density === 'compact'
|
|
211
|
+
? 'm-0 text-label font-normal text-fg-muted'
|
|
212
|
+
: 'm-0 text-body font-normal text-fg-muted'
|
|
213
|
+
}
|
|
214
|
+
>
|
|
215
|
+
{item.label}
|
|
216
|
+
</dt>
|
|
217
|
+
<dd
|
|
218
|
+
className={
|
|
219
|
+
density === 'compact'
|
|
220
|
+
? 'm-0 text-label font-normal text-fg [overflow-wrap:anywhere]'
|
|
221
|
+
: 'm-0 text-body font-normal text-fg [overflow-wrap:anywhere]'
|
|
222
|
+
}
|
|
223
|
+
>
|
|
224
|
+
{item.value}
|
|
225
|
+
</dd>
|
|
226
|
+
</div>
|
|
227
|
+
)
|
|
228
|
+
})}
|
|
229
|
+
</dl>
|
|
230
|
+
</MetadataSection>
|
|
231
|
+
)
|
|
98
232
|
}
|
|
99
233
|
|
|
100
234
|
export const TEMPLATE_REFERENCE_VIEWS = ['preview_grid', 'compact_list'] as const
|
|
@@ -106,25 +240,69 @@ export const TemplateReferenceGrid = uic('div', {
|
|
|
106
240
|
defaultVariants: { columns: 1 },
|
|
107
241
|
})
|
|
108
242
|
export const TemplateReferenceList = uic('div', {
|
|
109
|
-
displayName: 'TemplateReferenceList',
|
|
243
|
+
displayName: 'TemplateReferenceList',
|
|
244
|
+
baseClass: 'flex w-full flex-col gap-2',
|
|
110
245
|
})
|
|
111
246
|
const ReferenceButton = uic(AriaButton, {
|
|
112
247
|
displayName: 'TemplateReferenceButton',
|
|
113
|
-
baseClass:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
248
|
+
baseClass:
|
|
249
|
+
'w-full cursor-pointer border-0 p-0 text-start outline-none disabled:cursor-default data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring data-[focus-visible]:ring-offset-2',
|
|
250
|
+
variants: {
|
|
251
|
+
view: {
|
|
252
|
+
preview_grid: 'flex aspect-square items-center justify-center overflow-hidden rounded-lg bg-surface-card',
|
|
253
|
+
compact_list:
|
|
254
|
+
'grid min-h-16 grid-cols-[3rem_minmax(0,1fr)] items-center gap-3 border-b border-border bg-transparent py-2 last:border-b-0',
|
|
255
|
+
},
|
|
256
|
+
},
|
|
118
257
|
})
|
|
119
258
|
/** Read-only browsing surfaces: activation opens a preview, never selects it. */
|
|
120
|
-
export function TemplateReferenceItem({
|
|
121
|
-
title
|
|
122
|
-
|
|
259
|
+
export function TemplateReferenceItem({
|
|
260
|
+
title,
|
|
261
|
+
meta,
|
|
262
|
+
preview,
|
|
263
|
+
view,
|
|
264
|
+
isDisabled,
|
|
265
|
+
onOpen,
|
|
266
|
+
templateId,
|
|
267
|
+
referenceId,
|
|
268
|
+
}: {
|
|
269
|
+
title: string
|
|
270
|
+
meta: string
|
|
271
|
+
preview: ReactNode
|
|
272
|
+
view: TemplateReferenceView
|
|
273
|
+
isDisabled?: boolean
|
|
274
|
+
onOpen: () => void
|
|
275
|
+
templateId?: string
|
|
276
|
+
referenceId?: string
|
|
123
277
|
}) {
|
|
124
|
-
return
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
278
|
+
return (
|
|
279
|
+
<ReferenceButton
|
|
280
|
+
type="button"
|
|
281
|
+
view={view}
|
|
282
|
+
isDisabled={isDisabled}
|
|
283
|
+
onPress={onOpen}
|
|
284
|
+
aria-label={title}
|
|
285
|
+
data-template-id={templateId}
|
|
286
|
+
data-reference-id={referenceId}
|
|
287
|
+
>
|
|
288
|
+
<span
|
|
289
|
+
aria-hidden="true"
|
|
290
|
+
className={
|
|
291
|
+
view === 'compact_list'
|
|
292
|
+
? 'flex size-12 items-center justify-center overflow-hidden rounded-sm bg-surface-card [&>div]:w-full'
|
|
293
|
+
: 'flex h-full w-full items-center justify-center [&>div]:w-full'
|
|
294
|
+
}
|
|
295
|
+
>
|
|
296
|
+
{preview}
|
|
297
|
+
</span>
|
|
298
|
+
{view === 'compact_list' ? (
|
|
299
|
+
<span className="flex min-w-0 flex-col gap-1">
|
|
300
|
+
<span className="truncate text-label font-normal text-fg">{title}</span>
|
|
301
|
+
<span className="truncate text-label font-normal text-fg-muted">{meta}</span>
|
|
302
|
+
</span>
|
|
303
|
+
) : null}
|
|
304
|
+
</ReferenceButton>
|
|
305
|
+
)
|
|
128
306
|
}
|
|
129
307
|
|
|
130
308
|
export const TemplateCatalogGrid = uic('div', {
|
|
@@ -134,7 +312,8 @@ export const TemplateCatalogGrid = uic('div', {
|
|
|
134
312
|
|
|
135
313
|
const Card = uic(AriaButton, {
|
|
136
314
|
displayName: 'TemplateCatalogCardSurface',
|
|
137
|
-
baseClass:
|
|
315
|
+
baseClass:
|
|
316
|
+
'group box-border flex h-(--template-catalog-height) min-w-0 w-full cursor-pointer flex-col gap-6 overflow-hidden rounded-lg border-0 p-4 text-start outline-none transition-colors duration-200 motion-reduce:transition-none hover:bg-brand-green hover:text-fg-on-brand data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring data-[focus-visible]:ring-offset-2',
|
|
138
317
|
variants: {
|
|
139
318
|
selection: {
|
|
140
319
|
available: 'bg-surface-card text-fg',
|
|
@@ -149,7 +328,8 @@ const Title = uic('span', {
|
|
|
149
328
|
})
|
|
150
329
|
const Preview = uic('span', {
|
|
151
330
|
displayName: 'TemplateCatalogCardPreview',
|
|
152
|
-
baseClass:
|
|
331
|
+
baseClass:
|
|
332
|
+
'box-border flex min-h-0 w-full flex-1 items-center justify-center overflow-hidden rounded-md bg-transparent p-3 [&>div]:w-full',
|
|
153
333
|
})
|
|
154
334
|
|
|
155
335
|
const geometry: CSSProperties & { '--template-catalog-height': string } = {
|
|
@@ -163,15 +343,39 @@ export const TemplateCatalogBrowseGrid = uic('div', {
|
|
|
163
343
|
})
|
|
164
344
|
const BrowseCard = uic('div', {
|
|
165
345
|
displayName: 'TemplateCatalogBrowseSurface',
|
|
166
|
-
baseClass:
|
|
346
|
+
baseClass:
|
|
347
|
+
'box-border flex h-(--template-catalog-height) min-w-0 w-full cursor-default flex-col gap-6 overflow-hidden rounded-lg border-0 bg-surface-card p-4 text-start text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
|
167
348
|
})
|
|
168
349
|
/** Legacy readOnly catalog: no activation, hover shadow or extra card CTA. */
|
|
169
|
-
export function TemplateCatalogBrowseCard({
|
|
170
|
-
title
|
|
350
|
+
export function TemplateCatalogBrowseCard({
|
|
351
|
+
title,
|
|
352
|
+
preview,
|
|
353
|
+
templateId,
|
|
354
|
+
id,
|
|
355
|
+
testId,
|
|
356
|
+
}: {
|
|
357
|
+
title: string
|
|
358
|
+
preview: ReactNode
|
|
359
|
+
templateId: string
|
|
360
|
+
id?: string
|
|
361
|
+
testId?: string
|
|
171
362
|
}) {
|
|
172
|
-
return
|
|
173
|
-
<
|
|
174
|
-
|
|
363
|
+
return (
|
|
364
|
+
<BrowseCard
|
|
365
|
+
role="group"
|
|
366
|
+
tabIndex={0}
|
|
367
|
+
aria-label={title}
|
|
368
|
+
id={id}
|
|
369
|
+
data-catalog-template-id={templateId}
|
|
370
|
+
data-testid={testId}
|
|
371
|
+
style={geometry}
|
|
372
|
+
>
|
|
373
|
+
<Title>{title}</Title>
|
|
374
|
+
<Preview aria-hidden="true" className="pointer-events-none">
|
|
375
|
+
{preview}
|
|
376
|
+
</Preview>
|
|
377
|
+
</BrowseCard>
|
|
378
|
+
)
|
|
175
379
|
}
|
|
176
380
|
|
|
177
381
|
/** Selection-only catalog tile. No badge, selected ring, nested action, or artwork
|
|
@@ -179,10 +383,21 @@ export function TemplateCatalogBrowseCard({ title, preview, templateId, id, test
|
|
|
179
383
|
* the original catalog; aria-disabled and the press guard prevent its removal.
|
|
180
384
|
* The caller owns selection and supplies a non-interactive, contain-fit preview.
|
|
181
385
|
*/
|
|
182
|
-
export function TemplateCatalogCard({
|
|
183
|
-
|
|
386
|
+
export function TemplateCatalogCard({
|
|
387
|
+
title,
|
|
388
|
+
preview,
|
|
389
|
+
isSelected = false,
|
|
390
|
+
isSelectionLocked = false,
|
|
391
|
+
onToggle,
|
|
392
|
+
onOpen,
|
|
393
|
+
templateId,
|
|
394
|
+
testId,
|
|
395
|
+
classification,
|
|
396
|
+
description,
|
|
184
397
|
}: {
|
|
185
398
|
title: string
|
|
399
|
+
classification?: ReactNode
|
|
400
|
+
description?: ReactNode
|
|
186
401
|
preview: ReactNode
|
|
187
402
|
isSelected?: boolean
|
|
188
403
|
isSelectionLocked?: boolean
|
|
@@ -192,11 +407,27 @@ export function TemplateCatalogCard({ title, preview, isSelected = false, isSele
|
|
|
192
407
|
templateId?: string
|
|
193
408
|
testId?: string
|
|
194
409
|
}) {
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
410
|
+
return (
|
|
411
|
+
<Card
|
|
412
|
+
type="button"
|
|
413
|
+
selection={isSelected ? 'selected' : 'available'}
|
|
414
|
+
aria-label={title}
|
|
415
|
+
aria-pressed={onOpen ? undefined : isSelected}
|
|
416
|
+
aria-disabled={isSelectionLocked}
|
|
417
|
+
data-template-id={templateId}
|
|
418
|
+
data-testid={testId}
|
|
419
|
+
style={geometry}
|
|
420
|
+
onPress={() => {
|
|
421
|
+
if (!isSelectionLocked) {
|
|
422
|
+
if (onOpen) onOpen()
|
|
423
|
+
else onToggle?.()
|
|
424
|
+
}
|
|
425
|
+
}}
|
|
426
|
+
>
|
|
427
|
+
<Title>{title}</Title>
|
|
428
|
+
{classification ? <span className="text-label text-fg-muted">{classification}</span> : null}
|
|
429
|
+
{description ? <p className="m-0 text-label font-normal text-fg-muted">{description}</p> : null}
|
|
430
|
+
<Preview aria-hidden="true">{preview}</Preview>
|
|
431
|
+
</Card>
|
|
432
|
+
)
|
|
202
433
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type { ReactNode } from 'react'
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
2
|
+
useId,
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
type KeyboardEventHandler,
|
|
6
|
+
type FormEventHandler,
|
|
7
|
+
type Ref,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from 'react'
|
|
10
|
+
import { FieldError, Label, Text, TextArea as RACTextArea, TextField, type TextFieldProps } from 'react-aria-components'
|
|
10
11
|
import { uic } from '../utils/uic'
|
|
11
12
|
import {
|
|
12
13
|
fieldDescriptionClass,
|
|
13
14
|
fieldErrorClass,
|
|
14
|
-
|
|
15
|
+
fieldLabelClasses,
|
|
16
|
+
type FieldLabelSize,
|
|
15
17
|
fieldStackClass,
|
|
16
18
|
filledFieldClasses,
|
|
17
19
|
outlinedFieldClasses,
|
|
@@ -48,6 +50,7 @@ const StyledTextArea = uic(RACTextArea, {
|
|
|
48
50
|
export type TextareaProps = TextFieldProps & {
|
|
49
51
|
appearance?: FieldAppearance
|
|
50
52
|
/** Visible field label (required for accessibility). */
|
|
53
|
+
labelSize?: FieldLabelSize
|
|
51
54
|
label: ReactNode
|
|
52
55
|
/** Helper text rendered under the field. */
|
|
53
56
|
description?: ReactNode
|
|
@@ -58,14 +61,40 @@ export type TextareaProps = TextFieldProps & {
|
|
|
58
61
|
rows?: number
|
|
59
62
|
/** Optional class for the inner native textarea, used by source-specific modal layouts. */
|
|
60
63
|
textAreaClassName?: string
|
|
64
|
+
textAreaRef?: Ref<HTMLTextAreaElement>
|
|
65
|
+
onTextAreaKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>
|
|
66
|
+
onTextAreaInput?: FormEventHandler<HTMLTextAreaElement>
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
export const Textarea = ({
|
|
69
|
+
export const Textarea = ({
|
|
70
|
+
label,
|
|
71
|
+
labelSize = 'default',
|
|
72
|
+
description,
|
|
73
|
+
errorMessage,
|
|
74
|
+
placeholder,
|
|
75
|
+
rows,
|
|
76
|
+
textAreaClassName,
|
|
77
|
+
textAreaRef,
|
|
78
|
+
onTextAreaKeyDown,
|
|
79
|
+
onTextAreaInput,
|
|
80
|
+
appearance = 'outlined',
|
|
81
|
+
autoFocus,
|
|
82
|
+
...props
|
|
83
|
+
}: TextareaProps) => (
|
|
64
84
|
// Label and gap match `Input` in both appearances (gs 17px/20px field label,
|
|
65
85
|
// 12px to the control), so a Title + Description pair reads as one form.
|
|
66
86
|
<TextField {...props} className={`${fieldStackClass} w-full`}>
|
|
67
|
-
<Label className={
|
|
68
|
-
<StyledTextArea
|
|
87
|
+
<Label className={fieldLabelClasses[labelSize]}>{label}</Label>
|
|
88
|
+
<StyledTextArea
|
|
89
|
+
ref={textAreaRef}
|
|
90
|
+
onKeyDown={onTextAreaKeyDown}
|
|
91
|
+
onInput={onTextAreaInput}
|
|
92
|
+
autoFocus={autoFocus}
|
|
93
|
+
className={textAreaClassName}
|
|
94
|
+
placeholder={placeholder}
|
|
95
|
+
rows={rows}
|
|
96
|
+
appearance={appearance}
|
|
97
|
+
/>
|
|
69
98
|
{description ? (
|
|
70
99
|
<Text slot="description" className={fieldDescriptionClass}>
|
|
71
100
|
{description}
|
|
@@ -74,3 +103,122 @@ export const Textarea = ({ label, description, errorMessage, placeholder, rows,
|
|
|
74
103
|
<FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
|
|
75
104
|
</TextField>
|
|
76
105
|
)
|
|
106
|
+
|
|
107
|
+
export interface MentionTextareaProps {
|
|
108
|
+
id?: string
|
|
109
|
+
label: string
|
|
110
|
+
value: string
|
|
111
|
+
onChange: (value: string) => void
|
|
112
|
+
options: ReadonlyArray<{ id: string; name: string }>
|
|
113
|
+
placeholder?: string
|
|
114
|
+
readOnly?: boolean
|
|
115
|
+
autoFocus?: boolean
|
|
116
|
+
rows?: number
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Multiline comment field with keyboard-accessible @ people suggestions. */
|
|
120
|
+
export function MentionTextarea({
|
|
121
|
+
id,
|
|
122
|
+
label,
|
|
123
|
+
value,
|
|
124
|
+
onChange,
|
|
125
|
+
options,
|
|
126
|
+
placeholder,
|
|
127
|
+
readOnly,
|
|
128
|
+
autoFocus,
|
|
129
|
+
rows = 3,
|
|
130
|
+
}: MentionTextareaProps): ReactNode {
|
|
131
|
+
const listId = useId()
|
|
132
|
+
const fieldId = id ?? `${listId}-field`
|
|
133
|
+
const field = useRef<HTMLTextAreaElement>(null)
|
|
134
|
+
const [mention, setMention] = useState<{ start: number; end: number; query: string } | null>(null)
|
|
135
|
+
const [active, setActive] = useState(0)
|
|
136
|
+
const matches = mention
|
|
137
|
+
? options.filter((option) => option.name.toLocaleLowerCase().includes(mention.query.toLocaleLowerCase()))
|
|
138
|
+
: []
|
|
139
|
+
const open = !readOnly && matches.length > 0
|
|
140
|
+
const activeIndex = Math.min(active, Math.max(0, matches.length - 1))
|
|
141
|
+
const updateMention = (text: string, caret: number) => {
|
|
142
|
+
const prefix = text.slice(0, caret)
|
|
143
|
+
const match = /\s$/.test(prefix) ? null : /(?:^|\s)@([^@\n]*)$/.exec(prefix)
|
|
144
|
+
setMention(match ? { start: caret - (match[1]?.length ?? 0) - 1, end: caret, query: match[1] ?? '' } : null)
|
|
145
|
+
setActive(0)
|
|
146
|
+
}
|
|
147
|
+
const select = (person: { id: string; name: string }) => {
|
|
148
|
+
if (!mention || readOnly) return
|
|
149
|
+
const inserted = `@${person.name} `
|
|
150
|
+
onChange(value.slice(0, mention.start) + inserted + value.slice(mention.end))
|
|
151
|
+
const caret = mention.start + inserted.length
|
|
152
|
+
setMention(null)
|
|
153
|
+
requestAnimationFrame(() => {
|
|
154
|
+
field.current?.focus()
|
|
155
|
+
field.current?.setSelectionRange(caret, caret)
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
return (
|
|
159
|
+
<div className="relative flex flex-col gap-2">
|
|
160
|
+
<label htmlFor={fieldId} className="sr-only">
|
|
161
|
+
{label}
|
|
162
|
+
</label>
|
|
163
|
+
<textarea
|
|
164
|
+
ref={field}
|
|
165
|
+
id={fieldId}
|
|
166
|
+
value={value}
|
|
167
|
+
placeholder={placeholder}
|
|
168
|
+
readOnly={readOnly}
|
|
169
|
+
autoFocus={autoFocus}
|
|
170
|
+
rows={rows}
|
|
171
|
+
onInput={(event) => {
|
|
172
|
+
onChange(event.currentTarget.value)
|
|
173
|
+
updateMention(event.currentTarget.value, event.currentTarget.selectionStart)
|
|
174
|
+
}}
|
|
175
|
+
onSelect={(event) => {
|
|
176
|
+
if (!readOnly) updateMention(event.currentTarget.value, event.currentTarget.selectionStart)
|
|
177
|
+
}}
|
|
178
|
+
onBlur={() => setMention(null)}
|
|
179
|
+
onKeyDown={(event) => {
|
|
180
|
+
if (!open) return
|
|
181
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
182
|
+
event.preventDefault()
|
|
183
|
+
setActive((index) => (index + (event.key === 'ArrowDown' ? 1 : -1) + matches.length) % matches.length)
|
|
184
|
+
} else if (event.key === 'Enter' && !event.shiftKey) {
|
|
185
|
+
event.preventDefault()
|
|
186
|
+
const person = matches[activeIndex]
|
|
187
|
+
if (person) select(person)
|
|
188
|
+
} else if (event.key === 'Escape') {
|
|
189
|
+
event.preventDefault()
|
|
190
|
+
event.stopPropagation()
|
|
191
|
+
setMention(null)
|
|
192
|
+
}
|
|
193
|
+
}}
|
|
194
|
+
aria-autocomplete="list"
|
|
195
|
+
aria-controls={open ? listId : undefined}
|
|
196
|
+
aria-activedescendant={open ? `${listId}-${activeIndex}` : undefined}
|
|
197
|
+
className="min-h-[5.5rem] resize-y rounded-sm border border-border bg-surface p-3 text-small text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring read-only:text-fg-muted"
|
|
198
|
+
/>
|
|
199
|
+
{open ? (
|
|
200
|
+
<ul
|
|
201
|
+
id={listId}
|
|
202
|
+
role="listbox"
|
|
203
|
+
aria-label={label}
|
|
204
|
+
className="m-0 flex max-h-40 list-none flex-col overflow-y-auto rounded-md border border-border bg-surface-card p-1 shadow-lg"
|
|
205
|
+
>
|
|
206
|
+
{matches.map((person, index) => (
|
|
207
|
+
<li
|
|
208
|
+
key={person.id}
|
|
209
|
+
id={`${listId}-${index}`}
|
|
210
|
+
role="option"
|
|
211
|
+
aria-selected={index === activeIndex}
|
|
212
|
+
onPointerDown={(event) => event.preventDefault()}
|
|
213
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
214
|
+
onClick={() => select(person)}
|
|
215
|
+
className={`cursor-pointer rounded-md px-3 py-2 text-small text-fg hover:bg-surface-muted ${index === activeIndex ? 'bg-surface-muted' : ''}`}
|
|
216
|
+
>
|
|
217
|
+
@{person.name}
|
|
218
|
+
</li>
|
|
219
|
+
))}
|
|
220
|
+
</ul>
|
|
221
|
+
) : null}
|
|
222
|
+
</div>
|
|
223
|
+
)
|
|
224
|
+
}
|