refactor(ui): 补三处组件层缺件并记入收敛文档

- 新增 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。
This commit is contained in:
Menghuan1918 committed 2026-11-25 01:01:36 +08:00
1 parent fd13838b09
commit 6f9dbdf403
8 files changed
+194 -8

No files matched your search

@@ -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(错误行只能退回手写 `<div role="alert">`) | `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 例)。
仍然缺口但本轮没做(单点使用,按「只被一个页面用到的不要抽象」留下):
- 图片缩略图的外链壳(`<a target="_blank"><img>`)只有侧边对话一处。
- 终端输出区、diff 行内部结构属于各自的渲染模型,不是页面 pattern,等 B3 报告是否需要形状级共享。
+2 -2
View File
@@ -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'
+38
View File
@@ -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;
}
+39 -1
View File
@@ -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 (
<span
className={clsx(css.fileChip, className)}
title={title}
{...(unavailable === true ? { 'data-unavailable': 'true' } : {})}
>
<span className={css.fileChipIcon} aria-hidden="true"><FileTypeIcon path={path ?? name} size={16} /></span>
<span className={css.fileChipName}>{name}</span>
{size !== undefined && <span className={css.fileChipSize}>{size}</span>}
</span>
)
}
/**
* 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
+5
View File
@@ -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;
+34 -4
View File
@@ -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<HTMLElement>) => 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 (
<div
{...dataProps}
{...controlAria}
className={clsx(css.listRow, className)}
{...(selected === true ? { 'data-selected': 'true' } : {})}
{...(dimmed === true ? { 'data-dimmed': 'true' } : {})}
{...(disabled === true ? { 'data-disabled': 'true' } : {})}
onContextMenu={onContextMenu}
>
{leading !== undefined && <span className={css.listRowLeading}>{leading}</span>}
@@ -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
+28 -1
View File
@@ -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<HTMLElement>('[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<HTMLElement>('[class*="fileChip"]')!
expect(chip.dataset.unavailable).toBe('true')
expect(chip.textContent).toContain('gone.png')
expect(container.querySelector('[class*="fileChipSize"]')).toBeNull()
await unmount()
})
})
+31
View File
@@ -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',