Files
alpenwerk-hr/components/ui/Button.tsx
muena 3ea1765850 Übergabestand 2026-10-14
Anmeldung ausschliesslich ueber Microsoft Entra ID; HR-Zugang wird mit
freischalten.ps1 vergeben und entzogen (mit Eintrag im Audit-Log).

Startpasswort des LOLYO-Exports kommt aus LOLYO_STARTPASSWORT.
Content-Security-Policy wird durchgesetzt.
Sicherheitskonzept in docs/sicherheitskonzept.md; Lesezugriff fuer die IT
und Abnahme-Checkliste in deploy/windows/README.md.

Stand: d136da0
2026-10-14 09:46:52 +02:00

77 lines
2.5 KiB
TypeScript

"use client";
import type { ButtonHTMLAttributes, ReactNode } from "react";
// One definition of every button variant instead of a class chain per call
// site: hand-written copies drift in padding and hover colour. It also gives
// every button a visible keyboard focus ring.
const BASE =
"inline-flex items-center justify-center gap-1.5 rounded font-semibold transition-colors " +
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500 " +
"disabled:cursor-not-allowed disabled:opacity-50";
const VARIANTS = {
primary: "bg-brand-500 text-white hover:bg-brand-600",
// border-strong wie bei den Eingabefeldern: die Umrandung ist hier das
// Einzige, was den Knopf vom Hintergrund trennt, und muss deshalb die
// 3:1 aus WCAG 1.4.11 erreichen.
secondary: "border border-border-strong bg-white text-ink-body hover:bg-surface",
ghost: "text-ink-body hover:bg-surface",
danger: "bg-danger-solid text-white hover:brightness-110",
// Square icon-only button; pair with an aria-label.
icon: "text-ink-muted hover:bg-surface hover:text-ink",
} as const;
const SIZES = {
sm: "px-3 py-1.5 text-xs",
md: "px-4 py-2 text-sm",
// Meets the 44px touch target without looking oversized on desktop.
icon: "p-2",
} as const;
/**
* For anchors that read as buttons (download links, cross-page actions). A
* real <a> keeps middle-click and "open in new tab" working, which a button
* with an onClick would throw away — so those stay anchors and borrow the
* styling instead.
*/
export const LINK_BUTTON_CLASS = `${BASE} ${VARIANTS.secondary} ${SIZES.sm}`;
type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "className"> & {
variant?: keyof typeof VARIANTS;
size?: keyof typeof SIZES;
/** Disables and shows the busy label; use for in-flight server actions. */
pending?: boolean;
pendingLabel?: string;
fullWidth?: boolean;
className?: string;
children?: ReactNode;
};
export function Button({
variant = "primary",
size,
pending = false,
pendingLabel,
fullWidth,
disabled,
className = "",
children,
type = "button",
...rest
}: ButtonProps) {
const resolvedSize = size ?? (variant === "icon" ? "icon" : "md");
return (
<button
{...rest}
type={type}
disabled={disabled || pending}
aria-busy={pending || undefined}
className={`${BASE} ${VARIANTS[variant]} ${SIZES[resolvedSize]} ${fullWidth ? "w-full" : ""} ${className}`}
>
{pending && pendingLabel ? pendingLabel : children}
</button>
);
}