Navigation.tsx
4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type { ReactNode } from 'react';
import styles from './Shared.module.css';
import { Icon } from './Icon';
import { cx } from './utils';
export interface TabsItem {
key: string;
label: ReactNode;
disabled?: boolean;
children?: ReactNode;
}
export interface TabsProps {
/** Tabs 采用受控 activeKey,切换只通过 onChange 通知业务侧。 */
activeKey: string;
items: TabsItem[];
onChange?: (key: string) => void;
}
export function Tabs({ activeKey, items, onChange }: TabsProps) {
const active = items.find((item) => item.key === activeKey);
return (
<div className={styles.tabs}>
<div className={styles.tabList} role="tablist">
{items.map((item) => (
<button
key={item.key}
className={styles.tab}
disabled={item.disabled}
role="tab"
type="button"
aria-selected={item.key === activeKey}
onClick={() => {
if (!item.disabled) onChange?.(item.key);
}}
>
{item.label}
</button>
))}
</div>
<div role="tabpanel">{active?.children}</div>
</div>
);
}
export interface StepsProps {
current: number;
status?: 'process' | 'finish' | 'error';
items: Array<{ title: ReactNode }>;
}
export function Steps({ current, items, status = 'process' }: StepsProps) {
return (
<ol className={styles.row}>
{items.map((item, index) => {
const state = index < current ? '完成' : index === current && status === 'error' ? '错误' : index === current ? '进行中' : '等待';
return <li key={index} className={styles.stack}><strong>{item.title}</strong><span>{state}</span></li>;
})}
</ol>
);
}
export interface CollapseItem {
key: string;
title: ReactNode;
children?: ReactNode;
disabled?: boolean;
}
export interface CollapseProps {
/** Collapse 支持多面板展开,activeKeys 由外部控制。 */
activeKeys: string[];
items: CollapseItem[];
onChange?: (keys: string[]) => void;
}
export function Collapse({ activeKeys, items, onChange }: CollapseProps) {
return (
<div className={styles.stack}>
{items.map((item) => {
const open = activeKeys.includes(item.key);
return (
<section key={item.key} className={styles.panel}>
<button
className={cx(styles.fieldButton, styles.control)}
disabled={item.disabled}
type="button"
aria-expanded={open}
onClick={() => onChange?.(open ? activeKeys.filter((key) => key !== item.key) : [...activeKeys, item.key])}
>
<span>{item.title}</span>
<Icon name={open ? 'chevron-down' : 'chevron-right'} />
</button>
{open ? <div className={styles.section}>{item.children}</div> : null}
</section>
);
})}
</div>
);
}
export interface EmptyProps {
description?: ReactNode;
action?: ReactNode;
}
export function Empty({ action, description = '暂无数据' }: EmptyProps) {
return <div className={styles.stack}><div className={styles.muted}>{description}</div>{action}</div>;
}
export function Skeleton({ active = false }: { active?: boolean }) {
return <div aria-label="加载占位" className={cx(styles.skeleton, active && styles.stack)} style={{ width: '100%', height: 16 }} />;
}
export function SkeletonAvatar() {
return <div aria-label="头像加载占位" className={styles.skeleton} style={{ width: 32, height: 32, borderRadius: 999 }} />;
}
export function SkeletonParagraph({ rows = 3 }: { rows?: number }) {
return <div aria-label="段落加载占位" className={styles.stack}>{Array.from({ length: rows }, (_, index) => <div key={index} className={styles.skeleton} style={{ width: `${100 - index * 12}%`, height: 14 }} />)}</div>;
}
export function SkeletonButton() {
return <div aria-label="按钮加载占位" className={styles.skeleton} style={{ width: 72, height: 32 }} />;
}
export function SkeletonInput() {
return <div aria-label="输入框加载占位" className={styles.skeleton} style={{ width: 180, height: 32 }} />;
}