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
+216
View File
@@ -0,0 +1,216 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Trash2 } from 'lucide-react';
import { useState } from 'react';
import { Stage, me, people, tasks } from '../../stories/fixtures';
import { StatusBadge, Swatch } from '../Badge/Badge';
import { Button, type ButtonState } from '../Button/Button';
import { CommentComposer, CommentItem } from '../Comment/Comment';
import { Field, Input, Select, Textarea } from '../Field/Field';
import { SegmentedControl } from '../SegmentedControl/SegmentedControl';
import { Dialog, Drawer } from './Dialog';
const meta: Meta<typeof Dialog> = {
title: 'Overlays/Dialog',
component: Dialog,
parameters: { layout: 'padded' },
};
export default meta;
type Story = StoryObj<typeof Dialog>;
const groupOptions = [
{ value: 'swe', label: 'SWE · Collabry' },
{ value: 'db', label: 'Datenbanken Übung' },
{ value: 'mk', label: 'Marketing Seminar' },
];
const peopleOptions = Object.entries(people).map(([k, p]) => ({ value: k, label: p.name }));
const prioOptions = [
{ value: 'Hoch', label: 'Hoch' },
{ value: 'Mittel', label: 'Mittel' },
{ value: 'Niedrig', label: 'Niedrig' },
];
export const NeueAufgabe: Story = {
name: 'Neue Aufgabe',
render: function Render() {
const [open, setOpen] = useState(true);
const [prio, setPrio] = useState('Mittel');
const [title, setTitle] = useState('');
const [tried, setTried] = useState(false);
const [state, setState] = useState<ButtonState>('idle');
const submit = () => {
setTried(true);
if (!title.trim()) return;
setState('loading');
setTimeout(() => setState('success'), 900);
setTimeout(() => {
setState('idle');
setOpen(false);
}, 1600);
};
return (
<Stage height={640}>
<div className="p-6">
<Button variant="primary" onClick={() => setOpen(true)}>
Neue Aufgabe
</Button>
</div>
<Dialog
open={open}
onClose={() => setOpen(false)}
title="Neue Aufgabe"
description="Die zuständige Person wird benachrichtigt."
footer={
<>
<Button onClick={() => setOpen(false)}>Abbrechen</Button>
<Button variant="primary" state={state} onClick={submit}>
Aufgabe erstellen
</Button>
</>
}
>
<Field label="Titel" error={tried && !title.trim() ? 'Bitte gib einen Titel ein.' : undefined}>
{({ id, invalid, describedBy }) => (
<Input
id={id}
placeholder="Was ist zu tun?"
value={title}
onChange={(e) => setTitle(e.target.value)}
invalid={invalid}
aria-describedby={describedBy}
/>
)}
</Field>
<div className="grid grid-cols-[repeat(auto-fit,minmax(200px,1fr))] gap-4">
<Field label="Gruppe">{({ id }) => <Select id={id} options={groupOptions} />}</Field>
<Field label="Zuständig">{({ id }) => <Select id={id} options={peopleOptions} />}</Field>
<Field label="Fällig am">{({ id }) => <Input id={id} type="date" defaultValue="2026-11-09" />}</Field>
<div className="flex min-w-0 flex-col gap-1.5">
<span className="text-sm font-bold">Priorität</span>
<SegmentedControl label="Priorität" size="md" value={prio} onChange={setPrio} options={prioOptions} />
</div>
</div>
<Field label="Beschreibung" labelNote="(optional)">
{({ id }) => <Textarea id={id} rows={3} />}
</Field>
</Dialog>
</Stage>
);
},
};
export const Bestaetigung: Story = {
name: 'Bestätigung',
render: function Render() {
const [open, setOpen] = useState(true);
return (
<Stage height={360}>
<div className="p-6">
<Button variant="danger-outline" onClick={() => setOpen(true)}>
Aufgabe löschen
</Button>
</div>
<Dialog
open={open}
onClose={() => setOpen(false)}
kind="alert"
width={420}
title="Aufgabe löschen?"
description="„ER-Diagramm finalisieren“ wird für alle Gruppenmitglieder entfernt."
footer={
<>
<Button onClick={() => setOpen(false)}>Abbrechen</Button>
<Button variant="danger" onClick={() => setOpen(false)}>
Löschen
</Button>
</>
}
/>
</Stage>
);
},
};
export const Aufgabendetails: Story = {
render: function Render() {
const [open, setOpen] = useState(true);
const [draft, setDraft] = useState('');
const [prio, setPrio] = useState('Hoch');
const t = tasks[1];
return (
<Stage height={760}>
<div className="p-6">
<Button onClick={() => setOpen(true)}>Details öffnen</Button>
</div>
<Drawer
open={open}
onClose={() => setOpen(false)}
label={t.title}
header={
<span className="flex items-center gap-[7px] text-sm text-fg-muted">
<Swatch color={t.group.color} />
{t.group.name}
</span>
}
actions={
<Button variant="ghost" size="sm" iconOnly aria-label="Aufgabe löschen" title="Löschen" className="text-fg-subtle">
<Trash2 size={16} strokeWidth={1.75} />
</Button>
}
footer={<CommentComposer me={me} value={draft} onChange={setDraft} onSend={() => setDraft('')} />}
>
<div>
<input
aria-label="Titel"
defaultValue={t.title}
className="-mx-2 box-border w-[calc(100%+16px)] rounded-lg border border-transparent bg-transparent px-2 py-1.5 text-xl leading-tight font-black text-fg hover:border-line focus:border-accent-focus focus:shadow-focus focus:outline-none"
/>
<div className="mt-1.5 flex gap-2">
<StatusBadge status={t.status} />
</div>
</div>
<div className="grid grid-cols-[110px_minmax(0,1fr)] items-center gap-x-3.5 gap-y-3">
<label htmlFor="td-status" className="text-sm text-fg-subtle">
Status
</label>
<Select
id="td-status"
defaultValue="doing"
options={[
{ value: 'open', label: 'Offen' },
{ value: 'doing', label: 'In Arbeit' },
{ value: 'review', label: 'Review' },
{ value: 'done', label: 'Erledigt' },
]}
/>
<label htmlFor="td-who" className="text-sm text-fg-subtle">
Zuständig
</label>
<Select id="td-who" options={peopleOptions} />
<label htmlFor="td-due" className="text-sm text-fg-subtle">
Fällig am
</label>
<Input id="td-due" type="date" defaultValue="2026-11-04" />
<span className="text-sm text-fg-subtle">Priorität</span>
<SegmentedControl label="Priorität" size="md" value={prio} onChange={setPrio} options={prioOptions} />
</div>
<Field label="Beschreibung">
{({ id }) => <Textarea id={id} rows={4} placeholder="Details, Links oder Akzeptanzkriterien …" />}
</Field>
<section className="flex flex-col gap-1 border-t border-line-divider pt-4">
<h3 className="m-0 mb-2 text-base font-bold">Kommentare</h3>
<ol className="m-0 flex flex-col gap-3.5 p-0">
<CommentItem
comment={{ id: 'c1', author: people.LB, when: 'vor 2 Std.', text: 'Bitte auch die Validierung der E-Mail-Adresse einbauen.' }}
/>
<CommentItem
comment={{ id: 'c2', author: me, when: 'vor 1 Std.', text: 'Mache ich, kommt heute noch.', mine: true }}
onDelete={() => undefined}
/>
</ol>
</section>
</Drawer>
</Stage>
);
},
};