refactor(ui): 统一组件层地基与批次规划
- 新增 DownloadLink(kit.tsx)与 FallbackPane(patterns.tsx),从 ui/index.ts 导出; 样式只用 --dsw-* / --ds-* 令牌,覆盖下载出口与 pane 级兜底消息两个跨页面模式 - 示范替换孤儿标签页占位组件(改用 FallbackPane role="status",文案与类型 chip 不变) 与 binary-download(整页 FallbackPane + DownloadLink),删除 binary 独占的 .editorBinary / .editorBinaryNotice 规则 - tests/ui-kit.spec.tsx、tests/ui-patterns.spec.tsx 补两个新组件的契约: download 属性、inline 变体、role 只在调用方要求时透传 - docs/plans/2026-11-25-ui-kit-convergence.md:36 个未接入 tsx 的 A/B/C 分类与 B1–B4 批次(任务/作业 → 侧边对话 → 标签页与预览宿主 → 文件树与侧栏外壳)
This commit is contained in:
1 parent
d7e525471e
commit
fd13838b09
11 files changed
+283
-32
No files matched your search
@@ -5,11 +5,16 @@
|
||||
* it through the tab bar's X button as usual. This is the graceful-
|
||||
* degradation path for the open tab-type set: {@link Sidebar} renders this
|
||||
* instead of crashing on an unknown type.
|
||||
*
|
||||
* The body is the shared {@link FallbackPane} (a pane-filling centred message
|
||||
* with `role="status"`), so the sentence and the type chip are the only parts
|
||||
* this file owns.
|
||||
*/
|
||||
import type { ReactNode } from 'react'
|
||||
import { t } from './locales.ts'
|
||||
import css from './sidebar.module.css'
|
||||
import type { TabComponentProps } from './service.ts'
|
||||
import { FallbackPane } from './ui/index.ts'
|
||||
|
||||
export function OrphanedTab(props: TabComponentProps): ReactNode {
|
||||
const { tab } = props
|
||||
@@ -18,10 +23,11 @@ export function OrphanedTab(props: TabComponentProps): ReactNode {
|
||||
<div className={css.editorHeader}>
|
||||
<span className={css.editorTitle} title={tab.type}>{tab.title}</span>
|
||||
</div>
|
||||
<div className={css.editorPlaceholder} role="status">
|
||||
<span>{t('pluginNotLoaded')}</span>
|
||||
<code className={css.orphanedType}>{tab.type}</code>
|
||||
</div>
|
||||
<FallbackPane
|
||||
role="status"
|
||||
title={t('pluginNotLoaded')}
|
||||
description={<code className={css.orphanedType}>{tab.type}</code>}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,21 +3,22 @@
|
||||
* viewer can render a file (binary without a registered renderer, or the
|
||||
* `binary-download` strategy) and registered as the `binary-download` viewer
|
||||
* component so the declarative route and the host fallback share one UI.
|
||||
*
|
||||
* The pane is the shared {@link FallbackPane}; only its sentence and its way
|
||||
* out belong to this file.
|
||||
*/
|
||||
import type { ReactNode } from 'react'
|
||||
import type { SessionScope } from './api.ts'
|
||||
import { downloadUrl } from './api.ts'
|
||||
import { t } from './locales.ts'
|
||||
import css from './sidebar.module.css'
|
||||
import { DownloadLink, FallbackPane } from './ui/index.ts'
|
||||
|
||||
export function BinaryDownload(props: { scope: SessionScope; path: string }): ReactNode {
|
||||
const { scope, path } = props
|
||||
return (
|
||||
<div className={css.editorBinary}>
|
||||
<span className={css.editorBinaryNotice}>{t('binaryNoPreview')}</span>
|
||||
<a className={css.editorDownloadLink} href={downloadUrl(scope, path)} download>
|
||||
{t('downloadToView')}
|
||||
</a>
|
||||
</div>
|
||||
<FallbackPane
|
||||
title={t('binaryNoPreview')}
|
||||
actions={<DownloadLink href={downloadUrl(scope, path)}>{t('downloadToView')}</DownloadLink>}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1604,22 +1604,6 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
|
||||
|
||||
/* Binary / download-only files (legacy OLE .doc/.xls/.ppt, unknown binaries):
|
||||
a centered notice plus a download link — the user always gets the file. */
|
||||
.editorBinary {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 24px 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.editorBinaryNotice {
|
||||
font: var(--dsw-font-xxs-12);
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
}
|
||||
|
||||
.editorDownloadLink {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* free to split further without touching call sites.
|
||||
*/
|
||||
export {
|
||||
ActionButton, Chip, ConfirmDialog, IconButton, Notice, SectionHeader, StatusBadge,
|
||||
ActionButton, Chip, ConfirmDialog, DownloadLink, IconButton, Notice, SectionHeader, StatusBadge,
|
||||
type StatusTone,
|
||||
} from './kit.tsx'
|
||||
export { LoadingIndicator, type LoadingIndicatorProps } from './LoadingIndicator.tsx'
|
||||
@@ -12,9 +12,9 @@ export { WorkbenchSection, type WorkbenchSectionProps } from './WorkbenchSection
|
||||
export { SelectMenu, type SelectMenuProps, type SelectOption } from './SelectMenu.tsx'
|
||||
export { TextInput, TextArea, NumberInput, Checkbox, ToggleSwitch, Tabs, SettingRow, type TabOption } from './controls.tsx'
|
||||
export {
|
||||
ActionFooter, ChoiceCard, Disclosure, EmptyState, ErrorBlock, FactList, FactRow, Field, ListRow, StatusLine,
|
||||
ActionFooter, ChoiceCard, Disclosure, EmptyState, ErrorBlock, FactList, FactRow, FallbackPane, Field, ListRow, StatusLine,
|
||||
type ActionFooterProps, type ChoiceCardProps, type ChoiceOption, type DisclosureProps, type EmptyStateProps,
|
||||
type ErrorBlockProps, type Fact, type FactListProps, type FactRowProps, type FieldProps,
|
||||
type ErrorBlockProps, type Fact, type FactListProps, type FactRowProps, type FallbackPaneProps, type FieldProps,
|
||||
type ListRowProps, type PatternTone, type StatusLineProps,
|
||||
} from './patterns.tsx'
|
||||
export { SourceSwitcher, type SourceSwitcherItem, type SourceSwitcherProps } from './SourceSwitcher.tsx'
|
||||
|
||||
@@ -321,3 +321,45 @@
|
||||
.statusBadge[data-tone='write'] { color: var(--dsw-alias-state-business-primary); }
|
||||
.statusBadge[data-tone='edit'] { color: var(--dsw-alias-state-warn-primary); }
|
||||
.statusBadge[data-tone='neutral'] { color: var(--dsw-alias-label-tertiary); }
|
||||
|
||||
/* The one download affordance (kit.tsx’s DownloadLink): a bordered pill in a
|
||||
fallback pane, or the underlined escape hatch inside a notice bar. */
|
||||
.downloadLink {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--ds-sidebar-space-2);
|
||||
padding: 6px 14px;
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 6px;
|
||||
background: var(--dsw-alias-bg-layer-2);
|
||||
color: var(--dsw-alias-label-primary);
|
||||
font: var(--dsw-font-xxs-strong-12);
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background var(--ds-transition-duration-slow) var(--ds-ease-in-out),
|
||||
border-color var(--ds-transition-duration-slow) var(--ds-ease-in-out);
|
||||
}
|
||||
|
||||
.downloadLink:hover {
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
}
|
||||
|
||||
.downloadLink:focus-visible {
|
||||
outline: 2px solid var(--dsw-alias-interactive-bg-hover-accent);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
.downloadLinkInline {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.downloadLinkInline:hover {
|
||||
background: none;
|
||||
}
|
||||
@@ -105,6 +105,31 @@ export function Chip(props: {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* pane offers as its way out; `inline` is the underlined escape hatch a notice
|
||||
* bar puts beside its sentence. Four surfaces cut this recipe by hand before
|
||||
* (binary download, media fallback, PDF toolbar, large-file notice).
|
||||
*/
|
||||
export function DownloadLink(props: {
|
||||
href: string
|
||||
children: ReactNode
|
||||
variant?: 'button' | 'inline'
|
||||
className?: string | undefined
|
||||
}): ReactNode {
|
||||
const { href, children, variant = 'button', className } = props
|
||||
return (
|
||||
<a
|
||||
className={clsx(css.downloadLink, variant === 'inline' && css.downloadLinkInline, className)}
|
||||
href={href}
|
||||
download
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A 28px section band: a label (with an optional count) that may carry ONE
|
||||
* trailing action. The hairline under it is the page's only section divider.
|
||||
|
||||
@@ -558,3 +558,16 @@
|
||||
@media (pointer: coarse) {
|
||||
.disclosureSummary { min-height: 44px; }
|
||||
}
|
||||
|
||||
/* A pane-filling centred message (patterns.tsx’s FallbackPane): the body a
|
||||
viewer or window shows when there is nothing to render, with its way out
|
||||
under the sentence. It owns the fill; the sentence belongs to the caller. */
|
||||
.fallbackPane {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: var(--ds-sidebar-space-4) var(--ds-sidebar-space-3);
|
||||
text-align: center;
|
||||
}
|
||||
@@ -228,6 +228,40 @@ export function EmptyState({ icon, title, description, actions, tone = 'well', c
|
||||
)
|
||||
}
|
||||
|
||||
/** Props of {@link FallbackPane}. */
|
||||
export interface FallbackPaneProps extends DataAttributes {
|
||||
readonly icon?: ReactNode
|
||||
readonly title: ReactNode
|
||||
readonly description?: ReactNode
|
||||
/** The way out of the pane: a download pill, a retry, a settings link. */
|
||||
readonly actions?: ReactNode
|
||||
/** The pane announces itself only when the caller asks (the orphaned tab asks). */
|
||||
readonly role?: string
|
||||
readonly className?: string | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* The pane-filling "nothing to render here, here is the way out" shape: a
|
||||
* centred {@link EmptyState} that fills the tab or window body.
|
||||
*
|
||||
* The binary and media fallbacks cut this same recipe by hand before (a flex
|
||||
* column filling the pane, centred tertiary text, a download pill under it,
|
||||
* 24/16 padding), so the layout lives here and the sentence stays the caller's.
|
||||
*/
|
||||
export function FallbackPane({ icon, title, description, actions, role, className, ...dataProps }: FallbackPaneProps): ReactNode {
|
||||
return (
|
||||
<div {...dataProps} {...(role === undefined ? {} : { role })} className={clsx(css.fallbackPane, className)}>
|
||||
<EmptyState
|
||||
tone="page"
|
||||
{...(icon === undefined ? {} : { icon })}
|
||||
title={title}
|
||||
{...(description === undefined ? {} : { description })}
|
||||
{...(actions === undefined ? {} : { actions })}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Props of {@link ErrorBlock}. */
|
||||
export interface ErrorBlockProps extends DataAttributes {
|
||||
readonly message: ReactNode
|
||||
|
||||
Reference in new issue
Block a user