import type { CSSProperties, ReactNode } from 'react' import { cn } from '../../lib/cn' /** 面板:站内唯一的「有边框的内容块」。窄屏自动收窄内边距(旧站每个页面自己写一遍)。 */ export function Panel({ children, className, style, pad = true }: { children?: ReactNode; className?: string; style?: CSSProperties; pad?: boolean }) { return (
{children}
) } /** * 面板头:眉标 + 标题 + 右侧动作。 * * 旧站 25 处面板头全都是 +

,标题走的是全局 h2(17px); * 第一版迁移手写成 14px 的 h3,整站面板标题比正文重不了多少,扫视时找不到锚点。 * 窄列必须允许换行(旧站第二十章补的 .panel-head{flex-wrap:wrap}):两列栅格下 * 每列只有 ~400px,筛选控件的最小宽度就超过整列,不换行会把内容压到相邻面板上。 */ export function PanelHead({ title, eyebrow, sub, right, className }: { title?: ReactNode; eyebrow?: ReactNode; sub?: ReactNode; right?: ReactNode; className?: string }) { return (
*]:min-w-0', className)}>
{eyebrow && {eyebrow}} {title &&

{title}

} {sub &&

{sub}

}
{right &&
{right}
}
) } /** 眉标(面板上方那行全大写小字) */ export function Eyebrow({ children, className }: { children: ReactNode; className?: string }) { return
{children}
} /** 小标题 + 右侧动作(.small-label / .sect-act:增删按钮一律贴在标题行右端) */ export function SectionTitle({ children, action, className }: { children: ReactNode; action?: ReactNode; className?: string }) { return (
{children} {action && {action}}
) } /** 指标卡 */ export function Stat({ label, value, hint, className }: { label: ReactNode; value: ReactNode; hint?: ReactNode; className?: string }) { return (
{label} {value} {hint && {hint}}
) } /* 降列档位写成字面量:Tailwind 按源码里的字符串生成工具类, 运行时拼出来的 `max-[${w}px]:grid-cols-${c}` 根本不会被扫描到。 */ const STEP_CLS: Record = { 'huge:3': 'max-huge:grid-cols-3', 'mid:3': 'max-mid:grid-cols-3', 'mid2:3': 'max-mid2:grid-cols-3', 'nav:2': 'max-nav:grid-cols-2', 'short:2': 'max-short:grid-cols-2', 'mid2:2': 'max-mid2:grid-cols-2', 'tiny:1': 'max-tiny:grid-cols-1', 'narrow:1': 'max-narrow:grid-cols-1', 'short:1': 'max-short:grid-cols-1' } export type StatStep = { at: 'huge' | 'mid' | 'mid2' | 'nav' | 'short' | 'tiny' | 'narrow'; cols: 1 | 2 | 3 } /** * 指标卡栅格:列数与降列节奏都由容器声明,页面不写 @media。 * 默认沿用旧站 .stats:4 列 → ≤900 两列 → ≤560 收紧间距(卡片本身跟着换小字号内边距)。 * 卡片数不是 4 的页面把节奏写进 steps(用户管理 5 张卡:≤1280 三列、≤820 两列), * 这样例外是可见的参数,而不是又一段散回样式表、没人敢删的 @media。 */ export function StatGrid({ children, cols = 4, steps, className }: { children: ReactNode; cols?: number; steps?: StatStep[]; className?: string }) { return (
STEP_CLS[`${st.at}:${st.cols}`]), 'max-narrow:gap-2', className)} style={{ ['--cols' as string]: cols }}> {children}
) } /** 进度条(.bar / .bar i) */ export function ProgressBar({ value, bad, className }: { value: number; bad?: boolean; className?: string }) { const pct = Math.max(0, Math.min(100, Number(value) || 0)) return ( ) } export function Divider({ className }: { className?: string }) { return
} export function Empty({ children = '暂无数据', className }: { children?: ReactNode; className?: string }) { return
{children}
} export function Loading({ children = '读取中…', className }: { children?: ReactNode; className?: string }) { return
{children}
} export function Spinner({ className }: { className?: string }) { return } /** 提示条:成功用默认(青柠底),错误用 danger;只放一句人话,长说明收进抽屉 */ export function Notice({ children, danger, className, onClose }: { children: ReactNode; danger?: boolean; className?: string; onClose?: () => void }) { if (!children) return null return (
{children}
{onClose && ( )}
) } /** 数据回显(.val)与条件告警(.linehint):规范 §7 G2 —— 版面不放成段解释文字 */ export function Value({ children, muted, className }: { children: ReactNode; muted?: boolean; className?: string }) { return
{children}
} export function LineHint({ children, className }: { children: ReactNode; className?: string }) { return
{children}
} /** 等宽小字(路径 / id / 枚举码) */ export function Mono({ children, className, title }: { children: ReactNode; className?: string; title?: string }) { return {children} } /** 文字链(.link):导航用 ,这里只给「打开外部资源 / 下载」 */ export function ExtLink({ href, children, className, download }: { href: string; children: ReactNode; className?: string; download?: boolean | string }) { return {children} } /** 卡片行(.cardrow):标题 + 说明 + 右侧动作,列表里重复项的统一骨架 */ export function CardRow({ title, children, right, className, tone = 'border' }: { title?: ReactNode; children?: ReactNode; right?: ReactNode; className?: string; tone?: 'border' | 'plain' }) { return (
{title &&

{title}

} {children &&
{children}
}
{right &&
{right}
}
) } /** 元信息一行(.meta) */ export function Meta({ children, className }: { children: ReactNode; className?: string }) { return
{children}
} /** 行内动作组(.actions) */ export function Actions({ children, className }: { children: ReactNode; className?: string }) { return
{children}
} /** 通用栅格:.grid(4) .grid2 .grid3 .grid4 —— 1fr 轨道配 min-w-0,防止内容把列顶宽 */ export function Grid({ children, cols = 4, gap = 12, className, min = 0 }: { children: ReactNode; cols?: number | string; gap?: number; className?: string; min?: number }) { return (
*]:min-w-0', className)} style={{ gridTemplateColumns: `repeat(${cols},minmax(${min}px,1fr))`, gap }}> {children}
) }