Alpenwerk HR — HR-Stammdatenverwaltung Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte, Massenimport und ein lückenloser Nachweis jeder Änderung. Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der Datenbank, die Zugriffsschranke ist Row Level Security. Betrieb auf Windows Server: siehe deploy/windows/README.md. Sicherheitskonzept: docs/sicherheitskonzept.md.
77 lines
2.5 KiB
TypeScript
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>
|
|
);
|
|
}
|