@tbox.cn/app-agent-ui-kit 1.0.0-alpha.1 → 1.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/package.json +9 -6
  3. package/src/ChatPage.tsx +34 -7
  4. package/src/card/define-card.ts +34 -0
  5. package/src/card/primitives.test.tsx +147 -0
  6. package/src/card/primitives.tsx +627 -0
  7. package/src/card/use-card-actions.ts +86 -0
  8. package/src/chat-config.test.ts +35 -71
  9. package/src/chat-config.ts +18 -0
  10. package/src/components/ActionBar/DebugButton.tsx +3 -3
  11. package/src/components/ActionBar/index.tsx +13 -14
  12. package/src/components/ChatHeader/index.tsx +19 -17
  13. package/src/components/ChatInput/index.tsx +32 -26
  14. package/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
  15. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
  16. package/src/components/HistoryEntry/index.tsx +3 -4
  17. package/src/components/MediaList/index.tsx +42 -28
  18. package/src/components/MessageBubble/index.tsx +52 -27
  19. package/src/components/PullDownIndicator/index.tsx +3 -4
  20. package/src/components/QuickCommands/index.tsx +6 -6
  21. package/src/components/ReasoningBlock/index.tsx +14 -9
  22. package/src/components/ScrollToBottomButton/index.tsx +2 -4
  23. package/src/components/ToolCallBlock/index.tsx +54 -36
  24. package/src/icons.ts +39 -0
  25. package/src/index.ts +54 -1
  26. package/src/shell.contract.json +59 -0
  27. package/src/shell.test.ts +61 -0
  28. package/src/shell.ts +45 -0
  29. package/src/theme/base.css +132 -0
  30. package/src/theme/contract.json +1 -1
  31. package/src/theme/theme-contract.test.ts +3 -3
  32. package/src/theme/{tokens.less → tokens.css} +14 -12
  33. package/src/ChatPage.less +0 -62
  34. package/src/components/ActionBar/index.less +0 -123
  35. package/src/components/ChatHeader/index.less +0 -148
  36. package/src/components/ChatInput/index.less +0 -394
  37. package/src/components/HistoryEntry/index.less +0 -49
  38. package/src/components/MediaList/index.less +0 -241
  39. package/src/components/MessageBubble/index.less +0 -325
  40. package/src/components/PullDownIndicator/index.less +0 -32
  41. package/src/components/QuickCommands/index.less +0 -63
  42. package/src/components/ReasoningBlock/index.less +0 -90
  43. package/src/components/ScrollToBottomButton/index.less +0 -32
  44. package/src/components/ToolCallBlock/index.less +0 -312
  45. package/src/theme/global.less +0 -99
  46. /package/src/theme/{motion.less → motion.css} +0 -0
@@ -0,0 +1,627 @@
1
+ /**
2
+ * 卡片基元:一张卡需要的排版积木。
3
+ *
4
+ * 设计约束:
5
+ * - 全部走主题 token(`--tbox-*`),换主题自动跟随;不写死品牌色;
6
+ * - 尺寸用 750 设计稿 px(构建期转 rem),屏幕像素约为其一半;
7
+ * - 不引入新的交互语义:按钮一律由调用方决定 `onClick`,禁用由 `useCardActions().disabled` 统一控制。
8
+ *
9
+ * 信息类卡片(明细、票据、状态、路线)用这些积木拼即可,不必自写结构与样式;
10
+ * 需要完全自定义布局时再写组件,规则见 `docs/agent/style.md`。
11
+ */
12
+ import { useState } from 'react';
13
+ import type { ReactNode } from 'react';
14
+ import type { CardActions } from './use-card-actions';
15
+
16
+ export type Tone = 'neutral' | 'info' | 'success' | 'warning' | 'error';
17
+
18
+ /** 状态色:中性走契约语义色,其余是旧 less 里的固定色值(透明度底 + 深色字) */
19
+ const TAG_TONE: Record<Tone, string> = {
20
+ neutral: 'bg-muted text-secondary-foreground',
21
+ info: 'bg-[rgba(22,119,255,0.12)] text-[var(--tbox-primary,#1677ff)]',
22
+ success: 'bg-[rgba(34,160,90,0.12)] text-[#1a7f4b]',
23
+ warning: 'bg-[rgba(230,150,0,0.14)] text-[#9a6200]',
24
+ error: 'bg-[rgba(220,60,60,0.12)] text-[#b02a2a]',
25
+ };
26
+
27
+ const NOTICE_TONE: Record<Tone, string> = {
28
+ neutral: 'bg-muted',
29
+ info: 'bg-muted',
30
+ success: 'bg-[rgba(34,160,90,0.1)]',
31
+ warning: 'bg-[rgba(230,150,0,0.1)]',
32
+ error: 'bg-[rgba(220,60,60,0.1)]',
33
+ };
34
+
35
+ export interface CardProps {
36
+ children: ReactNode;
37
+ /** 卡片右下角的补充说明(可选) */
38
+ footer?: ReactNode;
39
+ className?: string;
40
+ }
41
+
42
+ /** 卡片容器:统一背景、圆角、内边距与阴影。 *
43
+ * @behavior 卡框统一圆角与内边距;footer 固定在内容之后,不随内容滚动。
44
+ */
45
+ export function Card({ children, footer, className }: CardProps) {
46
+ return (
47
+ <section
48
+ className={`tbox-card-primitive flex flex-col gap-2.5 rounded-lg bg-card p-3.5 text-sm leading-normal text-foreground shadow-sm ${className ? ` ${className}` : ''}`}
49
+ >
50
+ <div className="tbox-card-primitive__body flex flex-col gap-2.5">{children}</div>
51
+ {footer ? (
52
+ <footer className="tbox-card-primitive__footer border-t border-border pt-2 text-xs text-muted-foreground">{footer}</footer>
53
+ ) : null}
54
+ </section>
55
+ );
56
+ }
57
+
58
+ export interface CardHeaderProps {
59
+ title: ReactNode;
60
+ /** 标题上方的小字(如类别、时间) */
61
+ eyebrow?: ReactNode;
62
+ /** 右侧状态位 *
63
+ * @behavior 标题单行截断;eyebrow 在上、status 在右,窄屏不换行。
64
+ */
65
+ status?: ReactNode;
66
+ icon?: ReactNode;
67
+ }
68
+
69
+ export function CardHeader({ title, eyebrow, status, icon }: CardHeaderProps) {
70
+ return (
71
+ <header className="tbox-card-head flex items-start gap-2">
72
+ {icon ? <span className="tbox-card-head__icon inline-flex shrink-0">{icon}</span> : null}
73
+ <div className="tbox-card-head__text flex min-w-0 flex-1 flex-col gap-1">
74
+ {eyebrow ? <span className="tbox-card-head__eyebrow text-xs text-muted-foreground">{eyebrow}</span> : null}
75
+ <h4 className="tbox-card-head__title m-0 truncate text-base font-semibold">{title}</h4>
76
+ </div>
77
+ {status ? <span className="tbox-card-head__status shrink-0">{status}</span> : null}
78
+ </header>
79
+ );
80
+ }
81
+
82
+ export interface KeyValueItem {
83
+ label: ReactNode;
84
+ value: ReactNode;
85
+ }
86
+
87
+ /** 属性列表:左标签右值,逐行。 *
88
+ * @behavior 逐行两列;value 长文本自动换行,不截断。
89
+ */
90
+ export function KeyValueList({ items }: { items: KeyValueItem[] }) {
91
+ return (
92
+ <dl className="tbox-kv m-0 flex flex-col gap-1.5">
93
+ {items.map((item, index) => (
94
+ <div className="tbox-kv__row flex items-baseline justify-between gap-3" key={typeof item.label === 'string' ? item.label : index}>
95
+ <dt className="tbox-kv__label shrink-0 text-xs text-secondary-foreground">{item.label}</dt>
96
+ <dd className="tbox-kv__value m-0 break-words text-right text-sm">{item.value}</dd>
97
+ </div>
98
+ ))}
99
+ </dl>
100
+ );
101
+ }
102
+
103
+ export interface BillLine {
104
+ label: ReactNode;
105
+ value: ReactNode;
106
+ /** 弱化显示(折扣、说明) */
107
+ muted?: boolean;
108
+ }
109
+
110
+ /** 明细 + 合计:金额、积分、费用清单通用。 *
111
+ * @behavior 金额右对齐;muted 行弱化;total 在最后加一条分隔线。
112
+ */
113
+ export function Bill({ lines, total }: { lines: BillLine[]; total?: { label: ReactNode; value: ReactNode } }) {
114
+ return (
115
+ <div className="tbox-bill flex flex-col gap-1.5">
116
+ {lines.map((line, index) => (
117
+ <div
118
+ className={`tbox-bill__row flex justify-between gap-3 text-xs ${line.muted ? ' tbox-bill__row--muted text-muted-foreground' : ''}`}
119
+ key={index}
120
+ >
121
+ <span className="tbox-bill__label">{line.label}</span>
122
+ <span className="tbox-bill__value">{line.value}</span>
123
+ </div>
124
+ ))}
125
+ {total ? (
126
+ <div className="tbox-bill__total flex items-baseline justify-between border-t border-dashed border-border pt-1.5 text-xs">
127
+ <span>{total.label}</span>
128
+ <strong className="text-xl text-primary">{total.value}</strong>
129
+ </div>
130
+ ) : null}
131
+ </div>
132
+ );
133
+ }
134
+
135
+ /** 状态标签。 *
136
+ * @behavior 行内标签,不换行;一屏最多 3 个并排。
137
+ */
138
+ export function StatusTag({ children, tone = 'neutral' }: { children: ReactNode; tone?: Tone }) {
139
+ return (
140
+ <span
141
+ className={`tbox-tag tbox-tag--${tone} inline-flex max-w-44 items-center truncate rounded-full px-2 py-0.5 text-xs ${TAG_TONE[tone]}`}
142
+ >
143
+ {children}
144
+ </span>
145
+ );
146
+ }
147
+
148
+ export interface NoticeProps {
149
+ children: ReactNode;
150
+ tone?: Tone;
151
+ icon?: ReactNode;
152
+ }
153
+
154
+ /** 提示条:说明、限制、下一步指引。 *
155
+ * @behavior 图标在左、文本在右;长文本换行,不截断。
156
+ */
157
+ export function Notice({ children, tone = 'info', icon }: NoticeProps) {
158
+ return (
159
+ <div
160
+ className={`tbox-notice tbox-notice--${tone} flex items-start gap-1.25 rounded-md px-2.5 py-2 text-xs text-secondary-foreground ${NOTICE_TONE[tone]}`}
161
+ >
162
+ {icon ? <span className="tbox-notice__icon inline-flex shrink-0">{icon}</span> : null}
163
+ <span className="tbox-notice__text">{children}</span>
164
+ </div>
165
+ );
166
+ }
167
+
168
+ export interface ActionRowProps {
169
+ /** 主按钮(实心) */
170
+ primary?: ReactNode;
171
+ /** 次按钮(描边) */
172
+ secondary?: ReactNode;
173
+ /** 禁用整行(通常传 `useCardActions().disabled`) */
174
+ disabled?: boolean;
175
+ }
176
+
177
+ /** 按钮行:主次两级,禁用整行。 *
178
+ * @behavior 最多两个按钮并排;窄屏各占一半,不换行。
179
+ */
180
+ export function ActionRow({ primary, secondary, disabled }: ActionRowProps) {
181
+ if (!primary && !secondary) return null;
182
+ return (
183
+ <div className={`tbox-actions mt-2.5 flex items-center gap-1.5 ${disabled ? 'tbox-actions--disabled opacity-55' : ''}`}>
184
+ {secondary ? <div className="tbox-actions__secondary min-w-0 flex-1">{secondary}</div> : null}
185
+ {primary ? <div className="tbox-actions__primary min-w-0 flex-1">{primary}</div> : null}
186
+ </div>
187
+ );
188
+ }
189
+
190
+ /** 按钮:与基元同一套排版,禁用态统一。 *
191
+ * @behavior primary 撑满整行;secondary 与 link 宽度随内容;禁用态不触发点击。
192
+ */
193
+ const BUTTON_VARIANT = {
194
+ primary: 'w-full bg-primary px-3 py-2.5 text-sm text-white',
195
+ secondary: 'w-auto border border-border bg-transparent px-3 py-2.5 text-sm text-primary',
196
+ link: 'w-auto bg-transparent px-0 py-1 text-xs text-primary',
197
+ } as const;
198
+
199
+ export function CardButton({
200
+ children,
201
+ onClick,
202
+ variant = 'primary',
203
+ disabled,
204
+ }: {
205
+ children: ReactNode;
206
+ onClick?: () => void;
207
+ variant?: 'primary' | 'secondary' | 'link';
208
+ disabled?: boolean;
209
+ }) {
210
+ return (
211
+ <button
212
+ className={`tbox-btn tbox-btn--${variant} inline-flex cursor-pointer items-center justify-center rounded-full border-0 leading-tight disabled:cursor-not-allowed ${BUTTON_VARIANT[variant]}`}
213
+ type="button"
214
+ onClick={onClick}
215
+ disabled={disabled}
216
+ >
217
+ {children}
218
+ </button>
219
+ );
220
+ }
221
+
222
+ export interface ConfirmSheetProps {
223
+ open: boolean;
224
+ title: ReactNode;
225
+ description?: ReactNode;
226
+ confirmText?: string;
227
+ cancelText?: string;
228
+ onConfirm: () => void;
229
+ onCancel: () => void;
230
+ }
231
+
232
+ /** 确认弹层:写操作前的一次确认。 */
233
+ export function ConfirmSheet({
234
+ open,
235
+ title,
236
+ description,
237
+ confirmText = '确认',
238
+ cancelText = '取消',
239
+ onConfirm,
240
+ onCancel,
241
+ }: ConfirmSheetProps) {
242
+ if (!open) return null;
243
+ return (
244
+ <div className="tbox-sheet fixed inset-0 z-50" role="dialog" aria-modal="true">
245
+ <div className="tbox-sheet__mask absolute inset-0 bg-scrim" onClick={onCancel} />
246
+ <div className="tbox-sheet__panel absolute inset-x-0 bottom-0 flex flex-col gap-2.5 rounded-t-xl bg-card px-4 pb-5 pt-4">
247
+ <h5 className="tbox-sheet__title m-0 text-base">{title}</h5>
248
+ {description ? <p className="tbox-sheet__desc m-0 text-xs text-secondary-foreground">{description}</p> : null}
249
+ <div className="tbox-sheet__actions flex gap-2">
250
+ <CardButton variant="secondary" onClick={onCancel}>
251
+ {cancelText}
252
+ </CardButton>
253
+ <CardButton onClick={onConfirm}>{confirmText}</CardButton>
254
+ </div>
255
+ </div>
256
+ </div>
257
+ );
258
+ }
259
+
260
+ const TICKET_TONE = {
261
+ primary: 'border-primary-foreground bg-primary-soft',
262
+ muted: 'border-border bg-muted',
263
+ } as const;
264
+
265
+ const HERO_TONE = {
266
+ primary: 'bg-linear-to-br from-primary-foreground to-card',
267
+ warm: 'bg-linear-to-br from-warm to-card',
268
+ jade: 'bg-linear-to-br from-jade to-card',
269
+ neutral: 'bg-muted',
270
+ } as const;
271
+
272
+ export interface TicketProps {
273
+ /** 主金额或主标题 */
274
+ amount: ReactNode;
275
+ /** 面额后的说明(如「满 100 减 20」) */
276
+ condition?: ReactNode;
277
+ /** 有效期、码等补充 */
278
+ meta?: ReactNode;
279
+ status?: ReactNode;
280
+ tone?: 'primary' | 'muted';
281
+ }
282
+
283
+ /** 票券形:券、凭证、卡包条目。 */
284
+ export function Ticket({ amount, condition, meta, status, tone = 'primary' }: TicketProps) {
285
+ return (
286
+ <div className={`tbox-ticket tbox-ticket--${tone} flex items-center gap-2.5 rounded-lg border border-dashed p-3 ${TICKET_TONE[tone]}`}>
287
+ <div className="tbox-ticket__main flex shrink-0 flex-col gap-1">
288
+ <span className={`tbox-ticket__amount text-2xl font-bold ${tone === 'muted' ? 'text-muted-foreground' : 'text-primary'}`}>{amount}</span>
289
+ {condition ? <span className="tbox-ticket__condition text-xs text-secondary-foreground">{condition}</span> : null}
290
+ </div>
291
+ {meta ? <div className="tbox-ticket__meta min-w-0 flex-1 text-xs text-muted-foreground">{meta}</div> : null}
292
+ {status ? <div className="tbox-ticket__status shrink-0">{status}</div> : null}
293
+ </div>
294
+ );
295
+ }
296
+
297
+ export interface StepItem {
298
+ title: ReactNode;
299
+ detail?: ReactNode;
300
+ }
301
+
302
+ /** 步骤/路线:取车路线、办理进度。 */
303
+ export function Steps({ steps }: { steps: StepItem[] }) {
304
+ return (
305
+ <ol className="tbox-steps m-0 flex list-none flex-col gap-2.25 p-0">
306
+ {steps.map((step, index) => (
307
+ <li className="tbox-steps__item flex items-start gap-2" key={index}>
308
+ <span className="tbox-steps__index inline-flex size-5 shrink-0 items-center justify-center rounded-full bg-primary-foreground text-xs text-primary">
309
+ {index + 1}
310
+ </span>
311
+ <div className="tbox-steps__text flex flex-col gap-1">
312
+ <span className="tbox-steps__title text-sm">{step.title}</span>
313
+ {step.detail ? <span className="tbox-steps__detail text-xs text-muted-foreground">{step.detail}</span> : null}
314
+ </div>
315
+ </li>
316
+ ))}
317
+ </ol>
318
+ );
319
+ }
320
+
321
+ export interface MediaRowProps {
322
+ title: ReactNode;
323
+ meta?: ReactNode;
324
+ tags?: ReactNode;
325
+ /** 右侧操作(按钮或链接) */
326
+ action?: ReactNode;
327
+ /** 左侧缩略图 */
328
+ thumb?: ReactNode;
329
+ }
330
+
331
+ /** 图文条目:门店、商品、活动。 */
332
+ export function MediaRow({ title, meta, tags, action, thumb }: MediaRowProps) {
333
+ return (
334
+ <div className="tbox-media flex items-center gap-2.5">
335
+ {thumb ? (
336
+ <div className="tbox-media__thumb size-15 shrink-0 overflow-hidden rounded-media [&_img]:size-full [&_img]:object-cover">
337
+ {thumb}
338
+ </div>
339
+ ) : null}
340
+ <div className="tbox-media__text flex min-w-0 flex-1 flex-col gap-1.5">
341
+ <span className="tbox-media__title text-sm font-semibold">{title}</span>
342
+ {meta ? <span className="tbox-media__meta text-xs text-secondary-foreground">{meta}</span> : null}
343
+ {tags ? <span className="tbox-media__tags flex flex-wrap gap-1">{tags}</span> : null}
344
+ </div>
345
+ {action ? <div className="tbox-media__action shrink-0">{action}</div> : null}
346
+ </div>
347
+ );
348
+ }
349
+
350
+ // ── 第二版基元:按两次真实构建里出现最多的形态补齐(会员/积分/停车/商户/活动) ──
351
+
352
+ export interface HeroProps {
353
+ /** 标题上方小字(品牌名、卡类别) */
354
+ eyebrow?: ReactNode;
355
+ title: ReactNode;
356
+ /** 主数值(积分、余额、金额) */
357
+ value?: ReactNode;
358
+ /** 数值后的单位 */
359
+ unit?: ReactNode;
360
+ /** 数值下方一句说明 */
361
+ footnote?: ReactNode;
362
+ icon?: ReactNode;
363
+ tone?: 'primary' | 'warm' | 'jade' | 'neutral';
364
+ }
365
+
366
+ /** 品牌色块:主数值 + 说明,用于会员、积分、钱包类卡片的头部。 */
367
+ export function Hero({ eyebrow, title, value, unit, footnote, icon, tone = 'primary' }: HeroProps) {
368
+ return (
369
+ <div className={`tbox-hero tbox-hero--${tone} flex items-center gap-2 rounded-md p-3.5 pb-3.25 ${HERO_TONE[tone]}`}>
370
+ <div className="tbox-hero__text flex min-w-0 flex-1 flex-col gap-1.5">
371
+ {eyebrow ? <span className="tbox-hero__eyebrow text-xs tracking-wide text-muted-foreground">{eyebrow}</span> : null}
372
+ <span className="tbox-hero__title text-sm font-semibold">{title}</span>
373
+ {value !== undefined ? (
374
+ <span className="tbox-hero__value text-3xl font-bold leading-tight [&_small]:ml-1 [&_small]:text-xs [&_small]:font-medium [&_small]:text-secondary-foreground">
375
+ {value}
376
+ {unit ? <small>{unit}</small> : null}
377
+ </span>
378
+ ) : null}
379
+ {footnote ? <span className="tbox-hero__footnote text-xs text-secondary-foreground">{footnote}</span> : null}
380
+ </div>
381
+ {icon ? (
382
+ <span className="tbox-hero__icon flex size-12 shrink-0 items-center justify-center rounded-full bg-card text-primary" aria-hidden="true">
383
+ {icon}
384
+ </span>
385
+ ) : null}
386
+ </div>
387
+ );
388
+ }
389
+
390
+ export interface StatItem {
391
+ label: ReactNode;
392
+ value: ReactNode;
393
+ hint?: ReactNode;
394
+ }
395
+
396
+ /** 并列数值格(两到三格):积分/余额、车位/时长。 */
397
+ export function StatGrid({ items }: { items: StatItem[] }) {
398
+ return (
399
+ <div className="tbox-stats flex gap-1.5">
400
+ {items.map((item, index) => (
401
+ <div className="tbox-stats__item flex flex-1 flex-col gap-1 rounded-md bg-muted p-2.5 text-center" key={index}>
402
+ <span className="tbox-stats__value text-lg font-bold text-foreground">{item.value}</span>
403
+ <span className="tbox-stats__label text-xs text-muted-foreground">{item.label}</span>
404
+ {item.hint ? <span className="tbox-stats__hint text-xs text-secondary-foreground">{item.hint}</span> : null}
405
+ </div>
406
+ ))}
407
+ </div>
408
+ );
409
+ }
410
+
411
+ export interface EntityRowProps {
412
+ title: ReactNode;
413
+ /** 副标题:分类、距离、营业时间 */
414
+ meta?: ReactNode;
415
+ tags?: ReactNode;
416
+ /** 右侧价格或主数值 */
417
+ price?: ReactNode;
418
+ /** 右侧操作(按钮) */
419
+ action?: ReactNode;
420
+ /** 左侧缩略图或首字 */
421
+ thumb?: ReactNode;
422
+ /** 展开后的说明 */
423
+ description?: ReactNode;
424
+ }
425
+
426
+ /** 实体行(MediaRow 的超集):商户、活动、券包条目,支持价格与展开说明。 */
427
+ export function EntityRow({ title, meta, tags, price, action, thumb, description }: EntityRowProps) {
428
+ return (
429
+ <div className="tbox-entity flex items-center gap-2 border-b border-border py-2.5 last:border-b-0">
430
+ {thumb ? (
431
+ <div className="tbox-entity__thumb flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-media bg-muted [&_img]:size-full [&_img]:object-cover">
432
+ {thumb}
433
+ </div>
434
+ ) : null}
435
+ <div className="tbox-entity__text flex min-w-0 flex-1 flex-col gap-1.5">
436
+ <span className="tbox-entity__title text-sm font-semibold">{title}</span>
437
+ {meta ? <span className="tbox-entity__meta text-xs text-secondary-foreground">{meta}</span> : null}
438
+ {tags ? <span className="tbox-entity__tags flex flex-wrap gap-1">{tags}</span> : null}
439
+ {description ? <span className="tbox-entity__desc text-xs leading-normal text-muted-foreground">{description}</span> : null}
440
+ </div>
441
+ {price !== undefined || action ? (
442
+ <div className="tbox-entity__right flex shrink-0 flex-col items-end gap-1">
443
+ {price !== undefined ? <span className="tbox-entity__price text-base font-bold text-primary">{price}</span> : null}
444
+ {action}
445
+ </div>
446
+ ) : null}
447
+ </div>
448
+ );
449
+ }
450
+
451
+ export interface CheckRowProps {
452
+ label: ReactNode;
453
+ description?: ReactNode;
454
+ checked: boolean;
455
+ /** 只读时省略;给了就是可点行 */
456
+ onChange?: (checked: boolean) => void;
457
+ disabled?: boolean;
458
+ trailing?: ReactNode;
459
+ }
460
+
461
+ /** 勾选行:用券、同意条款、选择车位。 */
462
+ export function CheckRow({ label, description, checked, onChange, disabled, trailing }: CheckRowProps) {
463
+ const interactive = typeof onChange === 'function' && !disabled;
464
+ return (
465
+ <button
466
+ type="button"
467
+ className={`tbox-check flex w-full items-center gap-2 rounded-sm border border-border bg-card p-2.5 text-left ${checked ? ' tbox-check--on border-primary bg-primary-foreground' : ''}${interactive ? '' : ' tbox-check--static cursor-default'}`}
468
+ onClick={interactive ? () => onChange(!checked) : undefined}
469
+ disabled={disabled}
470
+ aria-pressed={checked}
471
+ >
472
+ <span
473
+ className={`tbox-check__box flex size-5 shrink-0 items-center justify-center rounded border-2 border-border-strong text-xs text-card ${checked ? ' border-primary bg-primary' : ''}`}
474
+ aria-hidden="true"
475
+ >
476
+ {checked ? '✓' : ''}
477
+ </span>
478
+ <span className="tbox-check__text flex min-w-0 flex-1 flex-col gap-1">
479
+ <span className="tbox-check__label text-sm text-foreground">{label}</span>
480
+ {description ? <span className="tbox-check__desc text-xs text-muted-foreground">{description}</span> : null}
481
+ </span>
482
+ {trailing ? <span className="tbox-check__trailing shrink-0 text-xs text-secondary-foreground">{trailing}</span> : null}
483
+ </button>
484
+ );
485
+ }
486
+
487
+ const TIMELINE_DOT = {
488
+ gain: 'bg-success',
489
+ spend: 'bg-warning',
490
+ neutral: 'bg-border-strong',
491
+ } as const;
492
+
493
+ const TIMELINE_AMOUNT = {
494
+ gain: 'text-success',
495
+ spend: 'text-warning',
496
+ neutral: '',
497
+ } as const;
498
+
499
+ export interface TimelineItem {
500
+ label: ReactNode;
501
+ time?: ReactNode;
502
+ /** 金额或积分变化(带符号) */
503
+ amount?: ReactNode;
504
+ tone?: 'gain' | 'spend' | 'neutral';
505
+ }
506
+
507
+ /** 明细时间线:积分收支、停车计费。 *
508
+ * @behavior 单列时间线;label 与 time 同行,amount 右对齐。
509
+ */
510
+ export function Timeline({ items }: { items: TimelineItem[] }) {
511
+ return (
512
+ <ul className="tbox-timeline m-0 list-none p-0">
513
+ {items.map((item, index) => {
514
+ const tone = item.tone ?? 'neutral';
515
+ return (
516
+ <li className={`tbox-timeline__item tbox-timeline__item--${tone} relative flex items-center gap-2 py-2`} key={index}>
517
+ <span className={`tbox-timeline__dot size-1.5 shrink-0 rounded-full ${TIMELINE_DOT[tone]}`} aria-hidden="true" />
518
+ <span className="tbox-timeline__text flex min-w-0 flex-1 flex-col gap-0.5">
519
+ <span className="tbox-timeline__label text-sm text-foreground">{item.label}</span>
520
+ {item.time ? <span className="tbox-timeline__time text-xs text-muted-foreground">{item.time}</span> : null}
521
+ </span>
522
+ {item.amount !== undefined ? (
523
+ <span className={`tbox-timeline__amount text-sm font-semibold ${TIMELINE_AMOUNT[tone]}`}>{item.amount}</span>
524
+ ) : null}
525
+ </li>
526
+ );
527
+ })}
528
+ </ul>
529
+ );
530
+ }
531
+
532
+ /** 空态:没券、没订单、没记录时给一句解释与一个下一步。 *
533
+ * @behavior 居中;action 最多一个按钮。
534
+ */
535
+ export function EmptyState({ title, description, action }: { title: ReactNode; description?: ReactNode; action?: ReactNode }) {
536
+ return (
537
+ <div className="tbox-empty flex flex-col items-center gap-1.25 px-3 py-6 text-center">
538
+ <span className="tbox-empty__title text-sm font-semibold text-foreground">{title}</span>
539
+ {description ? (
540
+ <span className="tbox-empty__desc text-xs leading-normal text-muted-foreground">{description}</span>
541
+ ) : null}
542
+ {action ? <span className="tbox-empty__action mt-1">{action}</span> : null}
543
+ </div>
544
+ );
545
+ }
546
+
547
+ /** 标签组:口味、距离、适用条件。 *
548
+ * @behavior 自动换行;单个 tag 不截断,超过两行折叠为一行滚动。
549
+ */
550
+ export function TagList({ tags, tone = 'neutral' }: { tags: ReactNode[]; tone?: Tone }) {
551
+ return (
552
+ <span className="tbox-tags flex flex-wrap gap-1">
553
+ {tags.map((tag, index) => (
554
+ <StatusTag key={index} tone={tone}>
555
+ {tag}
556
+ </StatusTag>
557
+ ))}
558
+ </span>
559
+ );
560
+ }
561
+
562
+ export interface CardActionSpec {
563
+ label: string;
564
+ /** 走模型:一句话(或气泡文案与透传文案分开) */
565
+ send?: string | { text: string; displayText?: string };
566
+ /** 走确定性动作:id + 入参 */
567
+ invoke?: { id: string; input?: Record<string, unknown> };
568
+ /** 点击前确认 */
569
+ confirm?: { title: string; description?: ReactNode; confirmText?: string; cancelText?: string };
570
+ style?: 'primary' | 'secondary';
571
+ }
572
+
573
+ /**
574
+ * 按钮组(描述对象版):把「发消息 / 确定性动作 / 确认弹层 / 禁用」收进一处。
575
+ *
576
+ * 用法:`const api = useCardActions({ cardId, isHistory, actionTokens }); <ActionList api={api} actions={[...]} />`
577
+ *
578
+ * @behavior 纵向排列,每个按钮独占一行;confirm 走 ConfirmSheet;disabled 自动接 api.disabled。
579
+ */
580
+ export function ActionList({ actions, api }: { actions: CardActionSpec[]; api: CardActions }) {
581
+ const [pending, setPending] = useState<number | null>(null);
582
+ const run = (spec: CardActionSpec) => {
583
+ if (spec.invoke) {
584
+ api.invoke(spec.invoke.id, spec.invoke.input);
585
+ return;
586
+ }
587
+ if (spec.send) {
588
+ if (typeof spec.send === 'string') api.send(spec.send);
589
+ else api.send(spec.send.text, { displayText: spec.send.displayText });
590
+ }
591
+ };
592
+ const trigger = (spec: CardActionSpec, index: number) => {
593
+ if (api.disabled) return;
594
+ if (spec.confirm) {
595
+ setPending(index);
596
+ return;
597
+ }
598
+ run(spec);
599
+ };
600
+ const pendingSpec = pending === null ? undefined : actions[pending];
601
+ return (
602
+ <>
603
+ <div className="tbox-action-list mt-2.5 flex flex-col gap-2">
604
+ {actions.map((spec, index) => (
605
+ <CardButton key={`${spec.label}-${index}`} variant={spec.style ?? (index === 0 ? 'primary' : 'secondary')} disabled={api.disabled} onClick={() => trigger(spec, index)}>
606
+ {spec.label}
607
+ </CardButton>
608
+ ))}
609
+ </div>
610
+ {pendingSpec?.confirm ? (
611
+ <ConfirmSheet
612
+ open
613
+ title={pendingSpec.confirm.title}
614
+ {...(pendingSpec.confirm.description ? { description: pendingSpec.confirm.description } : {})}
615
+ {...(pendingSpec.confirm.confirmText ? { confirmText: pendingSpec.confirm.confirmText } : {})}
616
+ {...(pendingSpec.confirm.cancelText ? { cancelText: pendingSpec.confirm.cancelText } : {})}
617
+ onConfirm={() => {
618
+ const spec = pendingSpec;
619
+ setPending(null);
620
+ run(spec);
621
+ }}
622
+ onCancel={() => setPending(null)}
623
+ />
624
+ ) : null}
625
+ </>
626
+ );
627
+ }