shadcn base

This commit is contained in:
wip
2026-11-04 22:31:12 +01:00
commit d16a94324b
94 changed files with 15927 additions and 0 deletions
+254
View File
@@ -0,0 +1,254 @@
import { useId, type ReactNode } from 'react';
import { Check } from 'lucide-react';
import { cn } from '../../lib/cn';
import { Card } from '../Card/Card';
import { CardDescription, CardTitle } from '../ui/card';
import { Label } from '../ui/label';
import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
import { Spinner } from '../Spinner/Spinner';
import type { NavItemData } from '../Sidebar/Sidebar';
export interface SettingsNavGroup {
title: string;
items: NavItemData[];
}
export interface SettingsNavProps {
groups: SettingsNavGroup[];
activeId: string;
className?: string;
}
/** Left-hand navigation between settings pages (Konto, Allgemein, Info). */
export function SettingsNav({ groups, activeId, className }: SettingsNavProps) {
return (
<nav aria-label="Einstellungen" className={cn('flex max-w-[240px] flex-[1_1_200px] flex-col gap-0.5', className)}>
{groups.map((g, gi) => (
<div key={g.title} className="contents">
<div className={cn('px-3 pb-2 text-xs font-bold text-fg-subtle', gi > 0 && 'pt-[18px]')}>{g.title}</div>
{g.items.map((it) => {
const active = it.id === activeId;
return (
<a
key={it.id}
href={it.href}
aria-current={active ? 'page' : undefined}
className={cn(
'flex h-[38px] items-center gap-2.5 rounded-lg px-3 font-bold',
active
? 'bg-side-active text-fg shadow-[inset_0_0_0_1px_var(--cl-side-active-line)] hover:text-fg'
: 'text-fg-muted hover:text-fg',
)}
>
<span className={cn('flex', active ? 'text-accent-fg' : 'text-fg-subtle')}>{it.icon}</span>
{it.label}
</a>
);
})}
</div>
))}
</nav>
);
}
export interface SettingsSectionProps {
title: string;
description?: ReactNode;
children: ReactNode;
/** Footer row, right-aligned (e.g. Verwerfen / Speichern). */
footer?: ReactNode;
className?: string;
}
/** A settings card: heading block, then rows separated by hairlines. */
export function SettingsSection({ title, description, children, footer, className }: SettingsSectionProps) {
const id = useId();
return (
<Card aria-labelledby={id} padding="none" className={className}>
<div className="px-[22px] pt-[18px] pb-4">
<CardTitle asChild>
<h2 id={id}>{title}</h2>
</CardTitle>
{description && <CardDescription className="mt-1 leading-normal">{description}</CardDescription>}
</div>
{children}
{footer && (
<div className="flex flex-wrap items-center justify-end gap-2.5 border-t border-line-subtle px-[22px] py-3.5">
{footer}
</div>
)}
</Card>
);
}
export interface SettingsRowProps {
label: ReactNode;
description?: ReactNode;
/** id of the control, so the label is a real <label>. */
htmlFor?: string;
/** The control on the right. Put it on its own line by using `stacked`. */
children?: ReactNode;
stacked?: boolean;
className?: string;
}
/** Label + description on the left, control on the right; wraps on narrow screens. */
export function SettingsRow({ label, description, htmlFor, children, stacked, className }: SettingsRowProps) {
const L = htmlFor ? Label : 'div';
return (
<div
className={cn(
'border-t border-line-subtle px-[22px] py-4',
!stacked && 'flex flex-wrap items-center justify-between gap-x-6 gap-y-3',
className,
)}
>
<div className={cn('min-w-0', !stacked && 'flex-[1_1_260px]')}>
<L htmlFor={htmlFor} className="block leading-tight font-bold">
{label}
</L>
{description && <div className="mt-[3px] text-sm leading-normal text-fg-subtle">{description}</div>}
</div>
{children && <div className={cn(stacked ? 'mt-3.5' : 'max-w-full flex-none')}>{children}</div>}
</div>
);
}
export type ThemeChoice = 'light' | 'dark' | 'system';
function MiniWindow({ variant, className }: { variant: 'light' | 'dark'; className?: string }) {
const c =
variant === 'light'
? { bg: '#F4F4F5', side: '#FFFFFF', card: '#FFFFFF', line: '#DEDEE3', bar: '#E4E4E7' }
: { bg: '#050505', side: '#0E0E0E', card: '#141414', line: '#2E2E2E', bar: '#262626' };
return (
<span aria-hidden="true" className={cn('box-border flex h-[74px] w-full gap-1.5 p-2', className)} style={{ background: c.bg }}>
<span className="w-[26%] rounded-[5px]" style={{ background: c.side }} />
<span className="flex flex-auto flex-col gap-[5px]">
<span className="h-[26px] rounded-[5px]" style={{ background: c.card, boxShadow: `inset 0 0 0 1px ${c.line}` }} />
<span className="h-2 w-[70%] rounded" style={{ background: c.bar }} />
<span className="h-2 w-[45%] rounded" style={{ background: c.bar }} />
</span>
</span>
);
}
/** Selectable card; the checked one gets an accent ring. */
const radioCard =
'group flex flex-col rounded-xl border border-line bg-inset text-fg hover:bg-hover data-[state=checked]:shadow-[0_0_0_2px_var(--cl-accent)] data-[state=checked]:focus-visible:shadow-[0_0_0_2px_var(--cl-accent),0_0_0_5px_var(--cl-accent-ring)]';
const themeLabels: Record<ThemeChoice, string> = { light: 'Hell', dark: 'Dunkel', system: 'System' };
export interface ThemePickerProps {
value: ThemeChoice;
onChange?: (value: ThemeChoice) => void;
className?: string;
}
/** Radio cards with a miniature preview of each theme. */
export function ThemePicker({ value, onChange, className }: ThemePickerProps) {
return (
<RadioGroup
aria-label="Design"
value={value}
onValueChange={(v) => onChange?.(v as ThemeChoice)}
className={cn('grid-cols-[repeat(auto-fit,minmax(140px,1fr))]', className)}
>
{(['light', 'dark', 'system'] as const).map((t) => (
<RadioGroupItem
key={t}
value={t}
className={cn(radioCard, 'gap-2.5 px-2 pt-2 pb-2.5 text-left')}
>
{t === 'system' ? (
<span className="flex h-[74px] w-full overflow-hidden rounded-[9px]">
<span className="flex flex-1 basis-0 overflow-hidden">
<MiniWindow variant="light" className="w-[200%] flex-none" />
</span>
<span className="flex flex-1 basis-0 justify-end overflow-hidden">
<MiniWindow variant="dark" className="w-[200%] flex-none" />
</span>
</span>
) : (
<MiniWindow variant={t} className="rounded-[9px]" />
)}
<span className="flex items-center justify-between gap-2 px-1 text-sm font-bold">
{themeLabels[t]}
<span className="box-border h-4 w-4 flex-none rounded-full border-[1.5px] border-line-control group-data-[state=checked]:border-accent group-data-[state=checked]:bg-accent group-data-[state=checked]:shadow-[inset_0_0_0_3px_var(--cl-inset)]" />
</span>
</RadioGroupItem>
))}
</RadioGroup>
);
}
export interface ColorSchemeOption {
id: string;
name: string;
color: string;
}
export interface ColorSchemePickerProps {
options: readonly ColorSchemeOption[];
value: string;
onChange?: (id: string) => void;
/** id of the element that labels the group. */
labelledBy?: string;
className?: string;
}
/** Accent color swatches ("Farbschema"). */
export function ColorSchemePicker({ options, value, onChange, labelledBy, className }: ColorSchemePickerProps) {
return (
<RadioGroup
aria-labelledby={labelledBy}
aria-label={labelledBy ? undefined : 'Farbschema'}
value={value}
onValueChange={(v) => onChange?.(v)}
className={cn('grid-cols-[repeat(auto-fill,minmax(88px,1fr))] gap-2.5', className)}
>
{options.map((o) => (
<RadioGroupItem
key={o.id}
value={o.id}
className={cn(radioCard, 'items-center gap-2 px-1.5 pt-3 pb-2.5 text-xs font-bold')}
>
<span
aria-hidden="true"
className="flex h-8 w-8 items-center justify-center rounded-full text-on-accent"
style={{
background: `linear-gradient(180deg, color-mix(in srgb, ${o.color} 88%, #fff) 0%, color-mix(in srgb, ${o.color} 90%, #000) 100%)`,
boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.28), 0 1px 2px rgba(0,0,0,0.5)',
}}
>
<Check size={16} strokeWidth={3} className="hidden group-data-[state=checked]:block" />
</span>
{o.name}
</RadioGroupItem>
))}
</RadioGroup>
);
}
export interface SaveStatusProps {
state: 'idle' | 'saving' | 'saved';
className?: string;
}
/** Autosave indicator: "Wird gespeichert …" then "Gespeichert". */
export function SaveStatus({ state, className }: SaveStatusProps) {
if (state === 'idle') return null;
return (
<span
role="status"
className={cn(
'flex items-center gap-1.5 text-xs font-bold',
state === 'saving' ? 'text-fg-subtle' : 'text-success-fg',
className,
)}
>
{state === 'saving' ? <Spinner size={14} /> : <Check size={14} strokeWidth={2.5} aria-hidden="true" />}
{state === 'saving' ? 'Wird gespeichert …' : 'Gespeichert'}
</span>
);
}