Panel.tsx
1.87 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
import type { CSSProperties, ReactNode } from 'react';
export interface PanelProps {
/** 面板标题。省略则不渲染标题行(用于纯容器场景) */
title?: ReactNode;
/** 标题右侧的附加内容(操作按钮、开关等) */
extra?: ReactNode;
/** 标题左侧的竖向品牌色标记条。默认开启,用于统一样式语言 */
accent?: boolean;
/** 内容区内边距。'none' 时内容自己贴边(表格、地图类) */
bodyPadding?: 'default' | 'none';
/** 内容区最大高度,超出滚动。用于左侧筛选面板堆叠 */
maxHeight?: number | string;
className?: string;
style?: CSSProperties;
/** 挂在面板根节点上的 DOM id,供等高对齐 / 锚点跳转使用 */
id?: string;
children: ReactNode;
}
/**
* 面板:页面上所有信息块的统一容器。
*
* 存在的理由不是"省几行 div",而是把卡片式布局的圆角 / 阴影 / 标题排版
* 收敛到一处——否则每个分析面板各写一套,视觉上一定会漂移。
*/
export function Panel({
title,
extra,
accent = true,
bodyPadding = 'default',
maxHeight,
className,
style,
id,
children,
}: PanelProps) {
return (
<section className={['hm-panel', className].filter(Boolean).join(' ')} style={style} id={id}>
{(title || extra) && (
<header className="hm-panel__head">
<div className="hm-panel__title">
{accent && <i className="hm-panel__accent" aria-hidden />}
{title}
</div>
{extra && <div className="hm-panel__extra">{extra}</div>}
</header>
)}
<div
className={
bodyPadding === 'none' ? 'hm-panel__body hm-panel__body--flush' : 'hm-panel__body'
}
style={maxHeight === undefined ? undefined : { maxHeight, overflowY: 'auto' }}
>
{children}
</div>
</section>
);
}