diff --git a/frontend/src/components/ui/Button.tsx b/frontend/src/components/ui/Button.tsx index e38c485..50bd1d9 100644 --- a/frontend/src/components/ui/Button.tsx +++ b/frontend/src/components/ui/Button.tsx @@ -62,19 +62,29 @@ type CommonProps = { type ButtonProps = CommonProps & ButtonHTMLAttributes & { href?: undefined } type AnchorProps = CommonProps & AnchorHTMLAttributes & { href: string } +/** + * 按钮的样式计算单独拿出来: / 这类「看起来是按钮的站内链接」 + * (模型迁移入口、空状态里的「去创建」)复用同一份配方, + * 而不是再抄一遍类名 —— 抄的那份永远不会跟着变体调整。 + */ +export function buttonCls(opt: CommonProps & { variant?: ButtonVariant } = {}) { + const { variant = 'secondary', size = 'md', square, danger, on, className } = opt + return cn( + BASE, + VARIANTS[variant as ButtonVariant], + size !== 'md' && SIZES[size as ButtonSize], + square && 'w-(--ctl-h) px-0 text-ui', + danger && variant === 'outline' && 'text-danger-bright border-danger-line hover:not-disabled:bg-danger-tint-2', + danger && variant === 'ghost' && 'text-danger-bright border-danger-line', + danger && variant === 'del' && 'bg-danger border-danger text-danger-ink shadow-raise', + on && 'border-accent-line bg-accent-tint text-accent-bright', + className + ) +} + export const Button = forwardRef( function Button({ variant = 'secondary', size = 'md', square, danger, on, className, children, ...rest }: any, ref) { - const classes = cn( - BASE, - VARIANTS[variant as ButtonVariant], - size !== 'md' && SIZES[size as ButtonSize], - square && 'w-(--ctl-h) px-0 text-ui', - danger && variant === 'outline' && 'text-danger-bright border-danger-line hover:not-disabled:bg-danger-tint-2', - danger && variant === 'ghost' && 'text-danger-bright border-danger-line', - danger && variant === 'del' && 'bg-danger border-danger text-danger-ink shadow-raise', - on && 'border-accent-line bg-accent-tint text-accent-bright', - className - ) + const classes = buttonCls({ variant, size, square, danger, on, className }) /* ref 是「按钮或链接」的联合类型,到这里没法收窄,交给 DOM 元素自己判断 */ const nodeRef = ref as Ref | undefined if (rest.href !== undefined) { diff --git a/frontend/src/components/ui/Controls.tsx b/frontend/src/components/ui/Controls.tsx index 7266aad..e2e1c48 100644 --- a/frontend/src/components/ui/Controls.tsx +++ b/frontend/src/components/ui/Controls.tsx @@ -121,16 +121,21 @@ export function ChipBar({ children, label, className, top }: { children: ReactNo ) } -/** 筛选/开关胶囊(.chip) */ +/** + * 筛选/开关胶囊(.chip)。 + * 默认是可点的 button;只读计数(调度中心队列旁的「queued 12」那种)传 as="span", + * 否则一行里会冒出七八个按了没反应的 Tab 停靠点。 + */ export function Chip({ active, children, onClick, className, title, disabled, as = 'button', href }: { active?: boolean; children: ReactNode; onClick?: () => void; className?: string; title?: string - disabled?: boolean; as?: 'button' | 'a'; href?: string + disabled?: boolean; as?: 'button' | 'a' | 'span'; href?: string }) { const classes = cn('inline-flex items-center justify-center gap-[5px] h-(--ctl-h-md) px-2 text-tiny rounded-pill ' + 'border whitespace-nowrap shrink-0 no-underline transition-colors duration-150', active ? 'bg-accent-fill border-accent-fill text-on-accent font-bold' : 'bg-raise border-line-strong text-ink-3 hover:bg-active hover:text-ink', disabled && 'opacity-40 cursor-not-allowed', className) + if (as === 'span') return {children} if (as === 'a') return {children} return } @@ -176,11 +181,11 @@ export function Pager({ page, pages, total, pageSize, onPageSize, onPage, extra } /** 复选(.check):勾选框 + 文案,整块可点 */ -export function Check({ checked, onChange, children, disabled, className }: { - checked: boolean; onChange: (next: boolean) => void; children: ReactNode; disabled?: boolean; className?: string +export function Check({ checked, onChange, children, disabled, className, title }: { + checked: boolean; onChange: (next: boolean) => void; children: ReactNode; disabled?: boolean; className?: string; title?: string }) { return ( -