init commit

This commit is contained in:
2026-11-14 08:49:19 +01:00
parent d16a94324b
commit f94d10e8e9
75 changed files with 5662 additions and 3731 deletions
+252 -187
View File
@@ -1,131 +1,223 @@
import { useId, type ReactNode } from 'react';
import { createContext, useContext, useId, type ComponentProps } from 'react';
import { Check } from 'lucide-react';
import { Slot } from 'radix-ui';
import { cn } from '../../lib/cn';
import { Card } from '../Card/Card';
import { CardDescription, CardTitle } from '../ui/card';
import { Card, CardFrame } from '../Card/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[];
}
/* ---------------------------------------------------------------- Nav */
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) {
/** Left-hand navigation between settings pages: `SettingsNavLabel`s and `SettingsNavItem`s. */
export function SettingsNav({ className, ...props }: ComponentProps<'nav'>) {
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>
<nav
aria-label="Einstellungen"
data-slot="settings-nav"
className={cn('flex max-w-[240px] flex-[1_1_200px] flex-col gap-0.5', className)}
{...props}
/>
);
}
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';
/** Group title, e.g. "Persönlich". */
export function SettingsNavLabel({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="settings-nav-label"
className={cn('px-3 pb-2 text-xs font-bold text-fg-subtle not-first:pt-[18px]', className)}
{...props}
/>
);
}
export interface SettingsNavItemProps extends ComponentProps<'a'> {
active?: boolean;
asChild?: boolean;
}
/** Icon and label; the active one is framed with an accent icon. */
export function SettingsNavItem({ active, asChild, className, ...props }: SettingsNavItemProps) {
const Comp = asChild ? Slot.Root : 'a';
return (
<Comp
aria-current={active ? 'page' : undefined}
data-slot="settings-nav-item"
className={cn(
'border-t border-line-subtle px-[22px] py-4',
'flex h-[38px] items-center gap-2.5 rounded-lg px-3 font-bold text-fg-muted hover:text-fg [&>svg]:text-fg-subtle',
'aria-[current=page]:bg-side-active aria-[current=page]:text-fg aria-[current=page]:shadow-[inset_0_0_0_1px_var(--cl-side-active-line)] aria-[current=page]:[&>svg]:text-accent-fg',
className,
)}
{...props}
/>
);
}
/* ---------------------------------------------------------------- Section */
const SectionContext = createContext<string | undefined>(undefined);
/**
* A settings card: header, then `SettingsRow`s separated by hairlines, then an optional footer.
* Labelled by its `SettingsSectionTitle`. `className` goes to the frame.
*/
export function SettingsSection({ className, ...props }: ComponentProps<'section'>) {
const titleId = useId();
return (
<SectionContext value={titleId}>
<CardFrame className={className}>
<Card asChild padding="none">
<section aria-labelledby={titleId} data-slot="settings-section" {...props} />
</Card>
</CardFrame>
</SectionContext>
);
}
export function SettingsSectionHeader({ className, ...props }: ComponentProps<'div'>) {
return <div data-slot="settings-section-header" className={cn('px-[22px] pt-[18px] pb-4', className)} {...props} />;
}
export function SettingsSectionTitle({ className, ...props }: ComponentProps<'h2'>) {
return (
<h2
id={useContext(SectionContext)}
data-slot="settings-section-title"
className={cn('m-0 text-md font-bold', className)}
{...props}
/>
);
}
export function SettingsSectionDescription({ className, ...props }: ComponentProps<'p'>) {
return (
<p
data-slot="settings-section-description"
className={cn('mt-1 mb-0 text-sm leading-normal text-fg-subtle', className)}
{...props}
/>
);
}
/** Right-aligned actions, e.g. Verwerfen / Speichern. */
export function SettingsSectionFooter({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="settings-section-footer"
className={cn(
'flex flex-wrap items-center justify-end gap-2.5 border-t border-line-subtle px-[22px] py-3.5',
className,
)}
{...props}
/>
);
}
export interface SettingsRowProps extends ComponentProps<'div'> {
/** Put the control on its own line under the text. */
stacked?: boolean;
}
/** `SettingsRowText` on the left, `SettingsRowControl` on the right; wraps on narrow screens. Also fits free content. */
export function SettingsRow({ stacked, className, ...props }: SettingsRowProps) {
return (
<div
data-slot="settings-row"
data-stacked={stacked || undefined}
className={cn(
'group/row 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>
{...props}
/>
);
}
export function SettingsRowText({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="settings-row-text"
className={cn('min-w-0 flex-[1_1_260px] group-data-stacked/row:flex-none', className)}
{...props}
/>
);
}
/** A `<label>`; set `htmlFor` to the control's id. */
export function SettingsRowLabel({ className, ...props }: ComponentProps<typeof Label>) {
return <Label data-slot="settings-row-label" className={cn('block leading-tight font-bold', className)} {...props} />;
}
export function SettingsRowDescription({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="settings-row-description"
className={cn('mt-[3px] text-sm leading-normal text-fg-subtle', className)}
{...props}
/>
);
}
export function SettingsRowControl({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="settings-row-control"
className={cn('max-w-full flex-none group-data-stacked/row:mt-3.5', className)}
{...props}
/>
);
}
/* ---------------------------------------------------------------- Pickers */
/** 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)]';
export type ThemeChoice = 'light' | 'dark' | 'system';
/** Radio cards for the theme: `ThemeOption`s. Arrow keys move the choice. */
export function ThemePicker({ className, ...props }: ComponentProps<typeof RadioGroup>) {
return (
<RadioGroup
aria-label="Design"
data-slot="theme-picker"
className={cn('grid-cols-[repeat(auto-fit,minmax(140px,1fr))]', className)}
{...props}
/>
);
}
/** One card: a `ThemePreview` and a `ThemeOptionLabel`. */
export function ThemeOption({ className, ...props }: ComponentProps<typeof RadioGroupItem>) {
return (
<RadioGroupItem
data-slot="theme-option"
className={cn(radioCard, 'gap-2.5 px-2 pt-2 pb-2.5 text-left', className)}
{...props}
/>
);
}
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
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-[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>
@@ -133,119 +225,92 @@ function MiniWindow({ variant, className }: { variant: 'light' | 'dark'; classNa
);
}
/** 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) {
/** Miniature app window in the given theme; `system` shows half light, half dark. */
export function ThemePreview({ theme, className }: { theme: ThemeChoice; className?: string }) {
if (theme !== 'system') return <MiniWindow variant={theme} className={cn('rounded-[9px]', className)} />;
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>
<span className={cn('flex h-[74px] w-full overflow-hidden rounded-[9px]', className)}>
<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>
);
}
export interface ColorSchemeOption {
id: string;
name: string;
/** Name of the option, with a radio dot on the right. */
export function ThemeOptionLabel({ className, children, ...props }: ComponentProps<'span'>) {
return (
<span
data-slot="theme-option-label"
className={cn('flex items-center justify-between gap-2 px-1 text-sm font-bold', className)}
{...props}
>
{children}
<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>
);
}
/** Accent color swatches ("Farbschema"): `ColorSchemeOption`s. */
export function ColorSchemePicker({ className, ...props }: ComponentProps<typeof RadioGroup>) {
return (
<RadioGroup
data-slot="color-scheme-picker"
className={cn('grid-cols-[repeat(auto-fill,minmax(88px,1fr))] gap-2.5', className)}
{...props}
/>
);
}
export interface ColorSchemeOptionProps extends ComponentProps<typeof RadioGroupItem> {
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) {
/** Round swatch in the color (checked: with a check mark), then `children` as the name. */
export function ColorSchemeOption({ color, className, children, ...props }: ColorSchemeOptionProps) {
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)}
<RadioGroupItem
data-slot="color-scheme-option"
className={cn(radioCard, 'items-center gap-2 px-1.5 pt-3 pb-2.5 text-xs font-bold', className)}
{...props}
>
{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>
<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, ${color} 88%, #fff) 0%, color-mix(in srgb, ${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>
{children}
</RadioGroupItem>
);
}
export interface SaveStatusProps {
/* ---------------------------------------------------------------- Status */
export interface SaveStatusProps extends ComponentProps<'span'> {
state: 'idle' | 'saving' | 'saved';
className?: string;
}
/** Autosave indicator: "Wird gespeichert …" then "Gespeichert". */
export function SaveStatus({ state, className }: SaveStatusProps) {
/** Autosave indicator: "Wird gespeichert …" then "Gespeichert". Renders nothing while idle. */
export function SaveStatus({ state, className, ...props }: SaveStatusProps) {
if (state === 'idle') return null;
return (
<span
role="status"
data-slot="save-status"
className={cn(
'flex items-center gap-1.5 text-xs font-bold',
state === 'saving' ? 'text-fg-subtle' : 'text-success-fg',
className,
)}
{...props}
>
{state === 'saving' ? <Spinner size={14} /> : <Check size={14} strokeWidth={2.5} aria-hidden="true" />}
{state === 'saving' ? 'Wird gespeichert …' : 'Gespeichert'}