nex_animation/frontend/src/components/ui/Page.tsx

102 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 页面级骨架(旧全局样式里的 header / .row / .between / .error / .sub)。
*
* 这些不是"组件"那么重,但 13 个页面每一页都要用;写成一处的意义和
* UI规范第二章一样:同一层级的东西在所有页面上量出来必须是同一个数。
* 页面里再出现 <header className="flex justify-between…"> 就算抄回去了一遍。
*/
import type { ReactNode } from 'react'
import { cn } from '../../lib/cn'
/** 次要说明文字(.muted):11px + 最淡的一级灰,表格单元格的第二行、附注都用它 */
export const MUTED = 'text-faint text-caption'
/** 等宽小字(.mono):路径 / id / 枚举码 / 数值列 */
export const MONO = 'font-mono text-[10.5px] tracking-[-.2px]'
/** 弱化 + 等宽(.muted.mono):id、路径、枚举码 */
export const MUTED_MONO = `${'text-faint'} ${MONO}`
/** 站内文字链配色(.link):<Link> 没有组件形态,用这个类名常量保持一致 */
export const LINK_CLS = 'text-success text-caption no-underline hover:underline'
/**
* 页头(旧 <header>):左边「状态行 + 大标题」,右边整组动作。
* 标题只有一层中文——旧站在标题上方另加一行全大写英文眉标,切不到英文,
* 只是装饰,现在整层删掉(见 UI规范 §1)。
* 窄屏按旧站规则改成纵向堆叠,动作按钮拉满一行——两三个小按钮排在
* 25px 标题右边,在 430px 屏上会挤成一团中文碎渣。
*/
export function PageHead({ title, meta, actions, className }: {
title?: ReactNode; meta?: ReactNode; actions?: ReactNode; className?: string
}) {
return (
<header className={cn('flex flex-wrap items-center justify-between gap-3 mb-[25px] min-w-0 max-nav:items-start', className)}>
<div className="min-w-0">
{meta && <Row className="max-nav:w-full max-nav:[&>button]:flex-1">{meta}</Row>}
{title && <h1>{title}</h1>}
</div>
{actions && <Row className="max-nav:w-full max-nav:[&>button]:flex-1 [--ctl-h:var(--ctl-h-md)]">{actions}</Row>}
</header>
)
}
/** 通用横排(.row):窄屏自动折行,同行控件等高由 --ctl-h 保证 */
export function Row({ children, className, tight }: { children?: ReactNode; className?: string; tight?: boolean }) {
return (
<div className={cn('flex flex-wrap items-center gap-[9px] min-w-0', tight && '[--ctl-h:var(--ctl-h-md)]', className)}>
{children}
</div>
)
}
/** 两端对齐(.between):左说明右动作,窄屏折行后仍然左对齐 */
export function Between({ children, className, tight }: { children?: ReactNode; className?: string; tight?: boolean }) {
return (
<div className={cn('flex flex-wrap items-center justify-between gap-3 min-w-0', tight && '[--ctl-h:var(--ctl-h-md)]', className)}>
{children}
</div>
)
}
/** 行内错误回显(.error):10px 红字,紧贴它说明的那个控件,不占提示条的位置 */
export function ErrorText({ children, className }: { children?: ReactNode; className?: string }) {
if (!children) return null
return <span className={cn('block text-danger text-tiny [overflow-wrap:anywhere] mt-1', className)}>{children}</span>
}
/** 分节线(.sub):同一面板里两个话题之间用它,不要再塞一个 h3 */
export function Sub({ children, className }: { children?: ReactNode; className?: string }) {
return <div className={cn('border-t border-line mt-[22px] pt-[18px] min-w-0', className)}>{children}</div>
}
/** 页签正文(.tabstack):面板之间固定 16px 呼吸,页面不要再自己写 mb-* */
export function TabStack({ children, className }: { children?: ReactNode; className?: string }) {
return <div className={cn('flex min-w-0 flex-col gap-4', className)}>{children}</div>
}
/**
* 两栏正文(.layout):主栏吃掉剩余宽度,侧栏最窄 300px。
* ≤1100 收成单列——断点写在组件里,页面不许再为自己写 @media。
*/
export function Layout({ children, className }: { children?: ReactNode; className?: string }) {
return (
<div className={cn('grid min-w-0 items-start gap-4 grid-cols-[minmax(0,1.5fr)_minmax(300px,0.8fr)] '
+ '[&>*]:min-w-0 max-mid2:grid-cols-1', className)}>
{children}
</div>
)
}
/**
* 一栏内的面板堆叠(.right)。
* ≤1100 时 <Layout> 已经折成单列,这一层临时并排两列把宽度用掉;
* ≤900 再叠回来(max-* 变体按断点从宽到窄排进样式表,后者自然覆盖前者)。
*/
export function Stack({ children, className }: { children?: ReactNode; className?: string }) {
return (
<div className={cn('flex min-w-0 flex-col gap-[15px] [&>*]:min-w-0 '
+ 'max-mid2:grid max-mid2:grid-cols-2 max-mid2:gap-4 max-nav:flex max-nav:gap-[15px]', className)}>
{children}
</div>
)
}