From 6f9dbdf4032a98d0c1b0bc0d68d9ea252c029cdf Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Wed, 25 Nov 2026 01:01:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20=E8=A1=A5=E4=B8=89=E5=A4=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=B1=82=E7=BC=BA=E4=BB=B6=E5=B9=B6=E8=AE=B0?= =?UTF-8?q?=E5=85=A5=E6=94=B6=E6=95=9B=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 FileAttachmentChip:非交互的静态文件附件卡(宿主 FileTypeIcon + 名称 + 大小 + 可选 title),补上 B2 报告的「附件卡在 SidechatAttachments 与 SideChatView 各手写一份」。 - StatusLine 的 role 扩到 'status' | 'alert',让失败行可以中断式播报,默认行为不变。 - ListRow 增加 disabled 与 aria-expanded / aria-controls / aria-label 直通:disabled 落 disabled + data-disabled,aria 落标题按钮(plain 行落外壳),供可折叠分组头使用。 - 契约测试:FileAttachmentChip 2 例、ListRow 2 例、StatusLine 1 例。 - docs/plans/2026-11-25-ui-kit-convergence.md 追加「组件层补件记录」,写明缺口来源、 补了什么、以及合并后需要切换的消费点。 门禁:typecheck / lint 无错;test 366 文件、4630 通过、18 skipped。 --- docs/plans/2026-11-25-ui-kit-convergence.md | 17 +++++++++ src/client/ui/index.ts | 4 +-- src/client/ui/kit.module.css | 38 ++++++++++++++++++++ src/client/ui/kit.tsx | 40 ++++++++++++++++++++- src/client/ui/patterns.module.css | 5 +++ src/client/ui/patterns.tsx | 38 +++++++++++++++++--- tests/ui-kit.spec.tsx | 29 ++++++++++++++- tests/ui-patterns.spec.tsx | 31 ++++++++++++++++ 8 files changed, 194 insertions(+), 8 deletions(-) diff --git a/docs/plans/2026-11-25-ui-kit-convergence.md b/docs/plans/2026-11-25-ui-kit-convergence.md index 46dcce3a..781cd001 100644 --- a/docs/plans/2026-11-25-ui-kit-convergence.md +++ b/docs/plans/2026-11-25-ui-kit-convergence.md @@ -110,3 +110,20 @@ comm -23 \ 2. **B2 侧边对话**(`SidechatImages` → `SidechatAttachments`)。 3. **B3 标签页与预览宿主**(`diff/*` → `TerminalView` → `media-preview` → `PdfView`/`LargeFileView` → `OrphanedTab` 收尾)。 4. **B4 文件树与侧栏外壳**(`Switch` → `dock-fallback` → `split-pane`):直接动交互与布局,放最后。 + +## 组件层补件记录(U2) + +收敛过程中,接页面的批次报告了三处「两个以上页面需要、组件层却没有」的缺口。本轮只补组件层与契约测试,消费页面仍在各自批次分支上,切换留到合并后统一做。 + +| 缺口 | 来源 | 补的件 | 需要切换的消费点 | +| --- | --- | --- | --- | +| 非交互的静态文件附件卡(`FileTypeIcon` + 名称 + 大小 + 可选 title,不是按钮) | B2(`SidechatAttachments.FileChip` 与 `SideChatView` 各手写一份) | `FileAttachmentChip`(`ui/kit.tsx`,导出 + `FileAttachmentChipProps`) | `src/client/SidechatAttachments.tsx`、`src/client/SideChatView.tsx` | +| `StatusLine` 只能 `role="status"`,失败需要中断式播报 | B2/B3(错误行只能退回手写 `
`) | `StatusLine.role?: 'status' \| 'alert'`(默认行为不变) | 各批次的错误行 | +| `ListRow` 没有 `disabled`,也没法把 `aria-expanded` / `aria-controls` / `aria-label` 交给标题按钮 | B1(可折叠分组的表头) | `ListRow` 增加 `disabled` 与三个 aria 直通;`disabled` 落 `disabled` + `data-disabled`,aria 落按钮(plain 行落外壳) | B1 的 `tasks-shared` 分组头 | + +补件后的约束没变:样式仍只走 `--dsw-*` / `--ds-*` 令牌,`tests/theme.spec.ts` 照旧扫描;三项契约测试分别在 `tests/ui-kit.spec.tsx`(`FileAttachmentChip` 2 例)与 `tests/ui-patterns.spec.tsx`(`ListRow` 2 例、`StatusLine` 1 例)。 + +仍然缺口但本轮没做(单点使用,按「只被一个页面用到的不要抽象」留下): + +- 图片缩略图的外链壳(``)只有侧边对话一处。 +- 终端输出区、diff 行内部结构属于各自的渲染模型,不是页面 pattern,等 B3 报告是否需要形状级共享。 diff --git a/src/client/ui/index.ts b/src/client/ui/index.ts index c7f8b7b3..f36861df 100644 --- a/src/client/ui/index.ts +++ b/src/client/ui/index.ts @@ -4,8 +4,8 @@ * free to split further without touching call sites. */ export { - ActionButton, Chip, ConfirmDialog, DownloadLink, IconButton, Notice, SectionHeader, StatusBadge, - type StatusTone, + ActionButton, Chip, ConfirmDialog, DownloadLink, FileAttachmentChip, IconButton, Notice, SectionHeader, StatusBadge, + type FileAttachmentChipProps, type StatusTone, } from './kit.tsx' export { LoadingIndicator, type LoadingIndicatorProps } from './LoadingIndicator.tsx' export { WorkbenchSection, type WorkbenchSectionProps } from './WorkbenchSection.tsx' diff --git a/src/client/ui/kit.module.css b/src/client/ui/kit.module.css index 2de5059e..e756c486 100644 --- a/src/client/ui/kit.module.css +++ b/src/client/ui/kit.module.css @@ -363,3 +363,41 @@ .downloadLinkInline:hover { background: none; } + +/* A static file attachment: the chip's band without the chip's control. The + glyph is the host's own artwork, so no color is decided here beyond the + label tokens. */ +.fileChip { + box-sizing: border-box; + display: inline-flex; + align-items: center; + gap: 6px; + min-width: 0; + max-width: 100%; + height: 22px; + padding: 0 8px; + border: 1px solid var(--dsw-alias-border-l2); + border-radius: var(--ds-sidebar-radius); + color: var(--dsw-alias-label-secondary); + font: var(--dsw-font-xxxs-11); +} + +.fileChipIcon { + display: inline-flex; + flex: none; +} + +.fileChipName { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.fileChipSize { + flex: none; + color: var(--dsw-alias-label-tertiary); +} + +.fileChip[data-unavailable='true'] { + opacity: 0.4; +} diff --git a/src/client/ui/kit.tsx b/src/client/ui/kit.tsx index d68b3759..f765b951 100644 --- a/src/client/ui/kit.tsx +++ b/src/client/ui/kit.tsx @@ -17,7 +17,7 @@ */ import { forwardRef, type ButtonHTMLAttributes, type MouseEvent, type ReactNode } from 'react' import clsx from 'clsx' -import { Modal } from '@deepseek-ai/dsh-client-ui-primitives' +import { FileTypeIcon, Modal } from '@deepseek-ai/dsh-client-ui-primitives' import { LoadingIndicator } from './LoadingIndicator.tsx' import design from './design.module.css' import css from './kit.module.css' @@ -105,6 +105,44 @@ export function Chip(props: { ) } +/** + * Props of {@link FileAttachmentChip}. + */ +export interface FileAttachmentChipProps { + /** File name shown as the chip's title. */ + readonly name: string + /** Human-readable size ("312 KB"); omitted when the host cannot know it. */ + readonly size?: string + /** Path that picks the host's file-type glyph; defaults to `name`. */ + readonly path?: string + /** Native tooltip, typically the attachment's full path. */ + readonly title?: string + /** The message still names the attachment but it can no longer be resolved. */ + readonly unavailable?: boolean + readonly className?: string | undefined +} + +/** + * The ONE static file attachment: the host's file-type glyph, the name and the + * size on the same 22px band as {@link Chip}. It is a picture, not a control — + * there is no button, no hover, no focus — because an attachment inside a + * message is data the reader reads, unlike the filter chips that act. + */ +export function FileAttachmentChip(props: FileAttachmentChipProps): ReactNode { + const { name, size, path, title, unavailable, className } = props + return ( + + + {name} + {size !== undefined && {size}} + + ) +} + /** * The ONE download affix: a real anchor carrying `download`, so the file goes * to disk instead of opening a tab. `button` is the bordered pill a fallback diff --git a/src/client/ui/patterns.module.css b/src/client/ui/patterns.module.css index 7163f986..4ee5f23e 100644 --- a/src/client/ui/patterns.module.css +++ b/src/client/ui/patterns.module.css @@ -88,6 +88,11 @@ .listRow[data-dimmed='true'] { color: var(--dsw-alias-label-tertiary); } +/* An inert row keeps its place and its name: the opacity, never a removal, is + what says "not actionable". */ +.listRow[data-disabled='true'] { opacity: 0.4; } +.listRow[data-disabled='true']:hover { background: none; } + .listRowLeading { display: inline-flex; align-items: center; diff --git a/src/client/ui/patterns.tsx b/src/client/ui/patterns.tsx index a4f58aca..d8954751 100644 --- a/src/client/ui/patterns.tsx +++ b/src/client/ui/patterns.tsx @@ -138,6 +138,18 @@ export interface ListRowProps extends DataAttributes { readonly selected?: boolean /** A row that exists but is not actionable yet (unresolved reference). */ readonly dimmed?: boolean + /** The row's own control is inert: the title button gets `disabled` and the shell `data-disabled`. */ + readonly disabled?: boolean + /** + * ARIA state of the row's control, for a collapsible section header that is + * one real button. `aria-expanded` / `aria-controls` / `aria-label` land on + * the title button; a plain-title row has no control of its own, so they land + * on the shell for the caller's own control to reference. + */ + readonly 'aria-expanded'?: boolean + readonly 'aria-controls'?: string + /** Accessible name, overriding the derived {@link ListRowProps.titleLabel}. */ + readonly 'aria-label'?: string readonly onContextMenu?: (event: MouseEvent) => void /** * Roving-focus membership for {@link useListNavigation}: the title button @@ -160,14 +172,28 @@ export interface ListRowProps extends DataAttributes { export function ListRow(props: ListRowProps): ReactNode { const { leading, title, titleData, titleLabel, subtitle, meta, actions, titleAs = 'plain', onTitleClick, - selected, dimmed, onContextMenu, primary, className, ...dataProps + selected, dimmed, disabled, onContextMenu, primary, className, + 'aria-expanded': expanded, 'aria-controls': controls, 'aria-label': ariaLabel, + ...dataProps } = props + const label = ariaLabel ?? titleLabel + // The control semantics belong to whichever element is the control: the + // title button when the row navigates, the shell otherwise. + const controlAria = titleAs === 'button' + ? {} + : { + ...(expanded === undefined ? {} : { 'aria-expanded': expanded }), + ...(controls === undefined ? {} : { 'aria-controls': controls }), + ...(label === undefined ? {} : { 'aria-label': label }), + } return (
{leading !== undefined && {leading}} @@ -180,7 +206,11 @@ export function ListRow(props: ListRowProps): ReactNode { type="button" {...titleData} className={clsx(css.listRowMain, css.listRowTitle)} - {...(titleLabel === undefined ? {} : { 'aria-label': titleLabel, title: titleLabel })} + {...(label === undefined ? {} : { 'aria-label': label })} + {...(titleLabel === undefined ? {} : { title: titleLabel })} + {...(expanded === undefined ? {} : { 'aria-expanded': expanded })} + {...(controls === undefined ? {} : { 'aria-controls': controls })} + disabled={disabled} {...(primary === undefined ? {} : { 'data-list-primary': true, tabIndex: primary ? 0 : -1 })} onClick={onTitleClick} > @@ -410,8 +440,8 @@ export interface StatusLineProps { readonly icon?: ReactNode readonly meta?: ReactNode readonly action?: ReactNode - /** `status` announces changes politely; omit for a purely static footnote. */ - readonly role?: 'status' + /** `status` announces changes politely, `alert` interrupts for a failure; omit for a purely static footnote. */ + readonly role?: 'status' | 'alert' /** Drop the horizontal padding when the caller's container already has it. */ readonly plain?: boolean readonly className?: string diff --git a/tests/ui-kit.spec.tsx b/tests/ui-kit.spec.tsx index 36980095..a6887ece 100644 --- a/tests/ui-kit.spec.tsx +++ b/tests/ui-kit.spec.tsx @@ -12,7 +12,7 @@ import { createElement, type ReactNode } from 'react' import { createRoot, type Root } from 'react-dom/client' import { act } from 'react-dom/test-utils' import { setupReactAct } from './test-utils.ts' -import { Chip, ConfirmDialog, DownloadLink, IconButton, Notice, SectionHeader, StatusBadge } from '../src/client/ui/kit.tsx' +import { Chip, ConfirmDialog, DownloadLink, FileAttachmentChip, IconButton, Notice, SectionHeader, StatusBadge } from '../src/client/ui/kit.tsx' import { invalidateGitStatus, statusOfXY, useGitStatus, type GitStatusView } from '../src/client/ui/git-status.ts' import type { GitStatusResult } from '../src/client/api.ts' @@ -357,3 +357,30 @@ describe('DownloadLink', () => { await unmount() }) }) + +describe('FileAttachmentChip', () => { + it('renders a static file card with the host glyph, name and size — never a control', async () => { + const { container, unmount } = await mount(createElement(FileAttachmentChip, { + name: 'report.pdf', size: '1.2 MB', title: '/tmp/report.pdf', + })) + const chip = container.querySelector('[class*="fileChip"]')! + expect(chip.tagName).toBe('SPAN') + expect(chip.getAttribute('title')).toBe('/tmp/report.pdf') + expect(container.querySelector('[class*="fileChipName"]')!.textContent).toBe('report.pdf') + expect(container.querySelector('[class*="fileChipSize"]')!.textContent).toBe('1.2 MB') + expect(chip.querySelector('svg')).not.toBeNull() + expect(container.querySelector('button, a')).toBeNull() + await unmount() + }) + + it('marks an unavailable attachment without dropping its identity', async () => { + const { container, unmount } = await mount(createElement(FileAttachmentChip, { + name: 'gone.png', unavailable: true, + })) + const chip = container.querySelector('[class*="fileChip"]')! + expect(chip.dataset.unavailable).toBe('true') + expect(chip.textContent).toContain('gone.png') + expect(container.querySelector('[class*="fileChipSize"]')).toBeNull() + await unmount() + }) +}) diff --git a/tests/ui-patterns.spec.tsx b/tests/ui-patterns.spec.tsx index 7a51ba6b..0576ec10 100644 --- a/tests/ui-patterns.spec.tsx +++ b/tests/ui-patterns.spec.tsx @@ -138,6 +138,29 @@ describe('ListRow', () => { view = renderRoot(createElement(ListRow, { title: 'Row', 'data-clue-result-row': 'clue-1' })) expect(view.container.querySelector('[data-clue-result-row]')).not.toBeNull() }) + + it('carries a collapsible header expanded state on its one button', () => { + view = renderRoot(createElement(ListRow, { + title: 'Environment', + titleAs: 'button', + 'aria-expanded': true, + 'aria-controls': 'panel-body', + 'aria-label': 'Environment section', + })) + const button = view.container.querySelector('button')! + expect(button.getAttribute('aria-expanded')).toBe('true') + expect(button.getAttribute('aria-controls')).toBe('panel-body') + expect(button.getAttribute('aria-label')).toBe('Environment section') + // The row shell itself is not the control, so it must not claim the state. + expect(byClass(view.container, 'listRow')!.hasAttribute('aria-expanded')).toBe(false) + }) + + it('renders a disabled row as inert while keeping its title readable', () => { + view = renderRoot(createElement(ListRow, { title: 'Locked', titleAs: 'button', disabled: true })) + expect((view.container.querySelector('button') as HTMLButtonElement).disabled).toBe(true) + expect(byClass(view.container, 'listRow')!.dataset.disabled).toBe('true') + expect(byClass(view.container, 'listRow')!.textContent).toContain('Locked') + }) }) describe('EmptyState', () => { @@ -300,6 +323,14 @@ describe('StatusLine', () => { expect(view.container.querySelector('[role="status"]')).not.toBeNull() }) + it('can interrupt with an alert when the line reports a failure', () => { + view = renderRoot(createElement(StatusLine, { text: 'Upload failed', tone: 'error', role: 'alert' })) + const line = view.container.querySelector('[role="alert"]') + expect(line).not.toBeNull() + expect(line!.getAttribute('role')).toBe('alert') + expect(view.container.querySelector('[role="status"]')).toBeNull() + }) + it('separates the trailing action from the text', () => { view = renderRoot(createElement(StatusLine, { text: 'Failed', tone: 'error',