Files
jiang13-bbs/frontend/components/admin/AdminIconButton.tsx

59 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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>
);
}