Alune 组件
DialogField
标签、控件与提示按统一节奏排列;错误与成功提示自动带图标并播报。
使用方式
弹窗字段由宿主传入状态和回调,适合在不同应用和文档中复用。先完成快速开始中的 Provider 与样式配置。
import { DialogField, DialogFieldRow } from '@alune/ui'; 运行示例
运行与复制源码来自同一 TSX 文件。浮层、状态和主题独立于文档;所有回调只更新本地模拟数据。
正在加载示例…
查看运行源码
import { useState } from 'react';
import {
Button,
DialogBadge,
DialogBadges,
DialogCard,
DialogField,
DialogFieldRow,
DialogIcon,
DialogList,
DialogListItem,
DialogPath,
Input,
OrbButton,
Select,
} from '@alune/ui';
export default function Example() {
const [name, setName] = useState('feature/example');
const [opened, setOpened] = useState(false);
const [busy, setBusy] = useState(false);
const taken = name.trim() === 'main';
return (
<div className="example">
<section className="example-group">
<h2 className="example-title">字段</h2>
<div className="example-stack">
<DialogField
label="分支名称"
mono
status={!name.trim() || taken ? 'error' : 'ok'}
hint={!name.trim() ? '请输入分支名称' : taken ? '已存在同名分支' : '名称可用'}
>
<Input
prefix={<DialogIcon name="branch" />}
value={name}
status={!name.trim() || taken ? 'error' : undefined}
onChange={(event) => setName(event.target.value)}
/>
</DialogField>
<DialogFieldRow end>
<DialogField label="主机" extra="必填" mono>
<Input defaultValue="example.local" />
</DialogField>
<DialogField label="端口" mono>
<Input defaultValue="22" />
</DialogField>
</DialogFieldRow>
<DialogField label="标签类型" labelId="example-tag-type">
<Select
aria-labelledby="example-tag-type"
defaultValue="annotated"
options={[
{ value: 'lightweight', label: '轻量标签' },
{ value: 'annotated', label: '附注标签' },
]}
/>
</DialogField>
</div>
</section>
<section className="example-group">
<h2 className="example-title">标签与列表</h2>
<div className="example-stack">
<DialogBadges>
<DialogBadge>新建</DialogBadge>
<DialogBadge tone="success" icon="check">
可合并
</DialogBadge>
<DialogBadge tone="warning" icon="clock">
暂不可合并
</DialogBadge>
<DialogBadge mono tone="success">
+12
</DialogBadge>
<DialogBadge mono tone="danger">
−3
</DialogBadge>
</DialogBadges>
<DialogCard>
<DialogList>
<DialogListItem
icon="folder"
title="example-app"
detail={<DialogPath path="/work/example-app" />}
>
<DialogBadge tone="success" icon="check">
已添加
</DialogBadge>
</DialogListItem>
<DialogListItem
icon="folder"
title="example-docs"
detail="子模块 · 有独立的 Git 状态"
>
<Button size="small">打开仓库</Button>
</DialogListItem>
</DialogList>
</DialogCard>
</div>
</section>
<section className="example-group">
<h2 className="example-title">带图标圆点的主操作</h2>
<div className="example-row">
<OrbButton
icon="arrow-up-right"
loading={busy}
onClick={() => {
setBusy(true);
window.setTimeout(() => {
setBusy(false);
setOpened(true);
}, 1200);
}}
>
打开仓库
</OrbButton>
<span className="example-status" role="status">
{busy ? '正在打开…' : opened ? '已打开示例仓库' : ''}
</span>
</div>
</section>
</div>
);
}
API
DialogField
DialogField 是通用组合成员,具体属性见关联 Props 表,运行效果见上方示例。
DialogFieldProps
| 属性 / 方法 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
label | ReactNode | — | 否 | 可访问名称或展示文案。 |
extra | ReactNode | — | 否 | 额外内容或操作。 |
hint | ReactNode | — | 否 | 确认提示。 |
status | "error" | "ok" | — | 否 | 状态关键字,同时保留文字表达。 |
hintId | string | — | 否 | Id for the hint so the control can reference it with aria-describedby. |
labelId | string | — | 否 | Id of the label text, for controls labelled with aria-labelledby. |
htmlFor | string | — | 否 | Id of the control the label points at. |
mono | boolean | — | 否 | Monospace input text for paths, refs and keys. |
className | string | — | 否 | 附加 CSS 类名。 |
children | ReactNode | — | 否 | 渲染的子内容。 |
DialogFieldRow
DialogFieldRow 是通用组合成员,具体属性见关联 Props 表,运行效果见上方示例。
DialogFieldRowProps
| 属性 / 方法 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
end | boolean | — | 否 | 参见类型定义及对应实现。 |
children | ReactNode | — | 是 | 渲染的子内容。 |
交互与使用限制
为每个操作提供可访问名称,为输入关联 label;使用语义化组件和清晰焦点。不要只靠颜色传达状态,禁用与等待时避免重复执行。
宿主负责状态、业务操作、错误处理与真实内容。组件不读取业务 store、路由或 Electron。示例中的反馈和等待均为本地模拟。
键盘、焦点、风险确认与通知策略的完整约定见交互规范。