feat(primitives): give PanelRow an optional detail line

A status row needs a second line under its title, such as what a failure
means or the command to run. The row grows to two lines with its icon level
with the first, and the trailing area and menu center on the row.
This commit is contained in:
LegGasai committed 2026-11-10 14:24:03 +08:00
1 parent 91e3d3a6c6
commit 85ebb18da5
7 files changed
+97 -7

No files matched your search

@@ -18,8 +18,8 @@
en: ead6be55c7c9d7cf
zh: 125ad36db7328551
/deepseek-ai-dsh-client-ui-primitives/use-this-package/component-catalog:
en: ee40f11e5ab81141
zh: 5e7dcb4bf30e25f1
en: b3fb6048736cb12f
zh: 712168ad890c4212
/deepseek-ai-dsh-client-ui-primitives/use-this-package/controls-and-icons:
en: 8265fa792c6fd9ec
zh: 600d2af4d5a3d183
+1 -1
View File
@@ -55,7 +55,7 @@ Check this table before writing a control in a feature package. A plugin cannot
| `SegmentedTabs` | Controlled equal-width tabs with a sliding indicator and Left/Right, Home, and End navigation. The caller supplies labels, tab/panel ids, and panel content. Default `size="md"` is 42px tall with a 4px inset; `size="sm"` is 34px tall with a 2px inset. |
| `Tag` | Read-only capsule badge; `tone` selects one of eight palettes. |
| `PathLabel` | Single-line file path with subdued directories, a primary filename, and the full path on hover. Fitting paths align left; clipped paths preserve their suffix with a left-edge fade that updates on path and size changes. |
| `PanelRow` | One fact row of a summary panel: a 16px decorative icon, single-line content that clips with an ellipsis, and an optional trailing value or control. The icon inherits the row ink. `menu` holds row actions, such as a More button, after the trailing area in a 16px column whose center sits 14px from the row's end; a plain `button` there gets a 24px target and a tertiary glyph that darkens on hover without a fill, so it needs no tooltip of its own. They show on row hover, on focus inside the row, and while one has its menu open, and always without hover. `onActivate` makes the whole row one button while the trailing area and the menu stay separate controls, and `actionLabel` names that button when its content does not describe the action; a row with an action or row actions fills as a whole on hover and while one of its menus is open. Other attributes, such as context-menu trigger props, reach the outer element. |
| `PanelRow` | One fact row of a summary panel: a 16px decorative icon, single-line content that clips with an ellipsis, and an optional trailing value or control. The icon inherits the row ink. `menu` holds row actions, such as a More button, after the trailing area in a 16px column whose center sits 14px from the row's end; a plain `button` there gets a 24px target and a tertiary glyph that darkens on hover without a fill, so it needs no tooltip of its own. They show on row hover, on focus inside the row, and while one has its menu open, and always without hover. `onActivate` makes the whole row one button while the trailing area and the menu stay separate controls, and `actionLabel` names that button when its content does not describe the action, starting with the visible text; a row with an action or row actions fills as a whole on hover and while one of its menus is open. `detail` adds a second line in smaller tertiary type that clips with an ellipsis, such as the consequence of a status or a command to run; the icon stays beside the first line and the trailing area and menu center on the row. Other attributes, such as context-menu trigger props, reach the outer element. |
| `MarqueeText`, `useHoverMarquee` | Single-line text that clips with an ellipsis at rest, and the row handlers that marquee it: entering the row crawls a clipped text at 30px/s to its far edge and holds it there, fading the edges that still hide text; leaving returns it to the start at once. Overflow of at most 8px, touch pointers, and text that fits stay put; reduced motion jumps to the far edge. |
| `StateDot` | Solid green `done`, amber `warning`, red `error`, and neutral-grey `idle` marks in a 10px slot, plus a tertiary-grey 14px rotating `ongoing` loader whose animations pin to document time zero on mount and on every animation restart, such as a list reorder, so every visible loader rotates in phase. `aria-hidden`, so the render site owns the name. `appearance="step"` shows a filled check for completion and a hollow pending circle. |
| `ConnectionIndicator` | Inline connection-recovery control across outage, retry, and recovered states. |
+1 -1
View File
@@ -55,7 +55,7 @@ kind: "package-library"
| `SegmentedTabs` | 受控的等宽分段标签,支持滑动指示条及左/右方向键、Home、End 导航。调用方提供文案、标签与面板 id,以及面板内容。默认 `size="md"` 总高 42px、内边距 4px;`size="sm"` 总高 34px、内边距 2px。 |
| `Tag` | 只读胶囊徽章;`tone` 选择八种配色之一。 |
| `PathLabel` | 单行文件路径:目录使用弱化颜色,文件名使用主色,悬停可查看完整路径。空间足够时靠左显示;溢出时保留尾部并在左侧渐隐,路径或尺寸变化时更新。 |
| `PanelRow` | 摘要面板中的一行事实:16px 装饰图标、单行内容(溢出时以省略号截断)以及可选的尾部数值或控件。图标沿用行文字颜色。`menu` 放在尾部区域之后的行操作(例如「更多」按钮),位于 16px 宽的一列,中心距行末端 14px;其中的普通 `button` 有 24px 点击区和三级文字色图标,悬停时图标变深、没有底色,因此不需要自己的 tooltip。鼠标悬停在行上、焦点在行内或其菜单打开时显示,没有悬停能力的设备上始终显示。传入 `onActivate` 时整行成为一个按钮,尾部区域与 `menu` 仍是各自独立的控件,内容不足以说明操作时用 `actionLabel` 为该按钮命名;带操作或行操作的行在悬停时以及菜单打开期间整行填充。其余属性(例如右键菜单触发属性)落在外层元素上。 |
| `PanelRow` | 摘要面板中的一行事实:16px 装饰图标、单行内容(溢出时以省略号截断)以及可选的尾部数值或控件。图标沿用行文字颜色。`menu` 放在尾部区域之后的行操作(例如「更多」按钮),位于 16px 宽的一列,中心距行末端 14px;其中的普通 `button` 有 24px 点击区和三级文字色图标,悬停时图标变深、没有底色,因此不需要自己的 tooltip。鼠标悬停在行上、焦点在行内或其菜单打开时显示,没有悬停能力的设备上始终显示。传入 `onActivate` 时整行成为一个按钮,尾部区域与 `menu` 仍是各自独立的控件,内容不足以说明操作时用 `actionLabel` 为该按钮命名,并以可见文字开头;带操作或行操作的行在悬停时以及菜单打开期间整行填充。`detail` 在内容下方加一行更小的浅灰文字,溢出时以省略号截断,例如某个状态的后果或要运行的命令;图标留在第一行旁边,尾部区域和菜单在整行中垂直居中。其余属性(例如右键菜单触发属性)落在外层元素上。 |
| `MarqueeText`、`useHoverMarquee` | 静止时以省略号截断的单行文字,以及让它滚动显示的行处理函数:指针进入行时,被截断的文字以 30px/s 匀速滚到末尾并停在那里,仍有文字被遮住的边缘渐隐;离开时立即回到开头。溢出不超过 8px、触摸指针以及放得下的文字都不滚动;减少动态效果时直接跳到末尾。 |
| `StateDot` | 10px 槽内的绿色 `done`、琥珀色 `warning`、红色 `error`、中性灰色 `idle` 圆点,以及 tertiary 灰色 14px 旋转 `ongoing` loading,其动画在挂载时以及每次动画重启(如列表重排)时固定到文档时间零点,所以所有可见 loading 同相旋转。它是 `aria-hidden` 的,名称由渲染点提供。 `appearance="step"` 以实心勾表示完成、空心圆表示等待。 |
| `ConnectionIndicator` | 行内连接恢复控件,覆盖断线、重试与已恢复三种状态。 |
@@ -91,6 +91,35 @@
color: var(--dsw-alias-label-tertiary);
}
/* A detail line under the content: the row grows by its 17px line and 4px insets, and the icon keeps the first
line's 20px box, so its center stays level with that line. */
.tall .body {
align-items: flex-start;
height: auto;
padding: 4px 0;
}
.tall .icon {
height: 20px;
}
.lines {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-width: 0;
}
.detail {
min-width: 0;
overflow: hidden;
color: var(--dsw-alias-label-tertiary);
font-size: 12px;
line-height: 17px;
text-overflow: ellipsis;
white-space: nowrap;
}
/* A 16px column, so the action's 24px target reaches past it without moving the glyph. */
.menu {
justify-content: center;
+16 -3
View File
@@ -26,6 +26,12 @@ export interface PanelRowProps extends Omit<HTMLAttributes<HTMLElement>, 'childr
* the visible text, so speech input that names what the row shows reaches the button.
*/
readonly actionLabel?: string | undefined
/**
* Second line under the content, in smaller tertiary type that clips with an ellipsis, such as the consequence of a
* status or a command to run; the row grows to two lines with the icon beside the first, and the trailing area and
* the menu centered on the row.
*/
readonly detail?: ReactNode
}
/**
@@ -35,16 +41,23 @@ export interface PanelRowProps extends Omit<HTMLAttributes<HTMLElement>, 'childr
* @param props - row content, the optional action and row actions, and attributes for the outer element.
* @returns the row element.
*/
export function PanelRow({ icon, children, trailing, menu, onActivate, actionLabel, className, ...attributes }: PanelRowProps) {
export function PanelRow({ icon, children, trailing, menu, onActivate, actionLabel, detail, className, ...attributes }: PanelRowProps) {
const body = (
<>
<span className={css.icon} aria-hidden="true">{icon}</span>
<span className={css.content}>{children}</span>
{detail === undefined
? <span className={css.content}>{children}</span>
: (
<span className={css.lines}>
<span className={css.content}>{children}</span>
<span className={css.detail}>{detail}</span>
</span>
)}
</>
)
const interactive = onActivate !== undefined || menu !== undefined
return (
<div {...attributes} className={clsx(css.row, interactive && css.interactive, className)} data-panel-row="">
<div {...attributes} className={clsx(css.row, interactive && css.interactive, detail !== undefined && css.tall, className)} data-panel-row="">
{onActivate === undefined
? <span className={css.body}>{body}</span>
: <button type="button" className={clsx(css.body, css.action)} aria-label={actionLabel} onClick={onActivate}>{body}</button>}
@@ -0,0 +1,36 @@
/**
* PanelRow's two-line geometry as CSS text: the component suite sees CSS
* Modules as class-name maps, so only the stylesheet proves that a detail line
* grows the row while the icon stays level with the first line.
*/
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
const css = readFileSync(fileURLToPath(new URL('../src/PanelRow.module.css', import.meta.url)), 'utf8')
function declarations(selector: string): Map<string, string> {
const found = new Map<string, string>()
for (const [, selectorList = '', body = ''] of css.replace(/\/\*[\s\S]*?\*\//g, ' ').matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
if (!selectorList.split(',').map(value => value.trim()).includes(selector)) continue
for (const part of body.split(';')) {
const colon = part.indexOf(':')
if (colon !== -1) found.set(part.slice(0, colon).trim(), part.slice(colon + 1).trim().replace(/\s+/g, ' '))
}
}
return found
}
describe('PanelRow.module.css', () => {
it('grows a row with a detail line and keeps the icon in the first line', () => {
const body = declarations('.tall .body')
expect([body.get('height'), body.get('align-items'), body.get('padding')]).toEqual(['auto', 'flex-start', '4px 0'])
expect(declarations('.tall .icon').get('height')).toBe('20px')
})
it('sets the detail line in clipped tertiary 12px type', () => {
const detail = declarations('.detail')
expect([detail.get('color'), detail.get('font-size'), detail.get('line-height'), detail.get('text-overflow'), detail.get('white-space')])
.toEqual(['var(--dsw-alias-label-tertiary)', '12px', '17px', 'ellipsis', 'nowrap'])
})
})
@@ -50,6 +50,18 @@ describe('PanelRow', () => {
expect(staticRow.className).not.toBe(interactive)
})
it('puts a detail line under the content and keeps the trailing area beside both lines', () => {
const view = render(
<PanelRow icon={<svg />} detail={<span>gh auth login</span>} trailing={<button type="button">Copy</button>}>Sign in</PanelRow>,
)
const row = view.container.querySelector('[data-panel-row]') as HTMLElement
const lines = screen.getByText('Sign in').parentElement as HTMLElement
expect([...lines.children].map(line => line.textContent)).toEqual(['Sign in', 'gh auth login'])
expect([...row.children].map(child => child.textContent)).toEqual(['Sign ingh auth login', 'Copy'])
const plain = render(<PanelRow icon={<svg />}>Sign in</PanelRow>).container.querySelector('[data-panel-row]') as HTMLElement
expect(row.className).not.toBe(plain.className)
})
it('forwards attributes such as context-menu handlers to the outer element', () => {
const onContextMenu = vi.fn()
const view = render(<PanelRow icon={<svg />} className="placed" onContextMenu={onContextMenu} tabIndex={0}>Row</PanelRow>)