polish(admin): 抽出后台控件包并统一各页布局与交互
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
58
frontend/components/admin/AdminIconButton.tsx
Normal file
58
frontend/components/admin/AdminIconButton.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
type Tone = "default" | "accent" | "danger";
|
||||
|
||||
const toneClass: Record<Tone, string> = {
|
||||
default: "",
|
||||
accent: "is-accent",
|
||||
danger: "is-danger",
|
||||
};
|
||||
|
||||
/** 32px 圆形行内操作;hover/focus 走 CSS,禁止 JS 改 style */
|
||||
export default function AdminIconButton({
|
||||
children,
|
||||
tip,
|
||||
ariaLabel,
|
||||
tone = "default",
|
||||
className = "",
|
||||
href,
|
||||
disabled,
|
||||
onClick,
|
||||
type = "button",
|
||||
}: {
|
||||
children: ReactNode;
|
||||
tip?: string;
|
||||
ariaLabel: string;
|
||||
tone?: Tone;
|
||||
className?: string;
|
||||
href?: string;
|
||||
disabled?: boolean;
|
||||
onClick?: () => void;
|
||||
type?: "button" | "submit";
|
||||
}) {
|
||||
const cls = `admin-icon-btn ${toneClass[tone]} ${className}`.trim();
|
||||
|
||||
if (href && !disabled) {
|
||||
return (
|
||||
<Link href={href} className={cls} aria-label={ariaLabel} data-tip={tip}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type={type}
|
||||
className={cls}
|
||||
aria-label={ariaLabel}
|
||||
data-tip={tip}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user