Files
collabry-components/src/components/Dialog/Dialog.stories.tsx
T
2026-11-14 08:49:19 +01:00

327 lines
11 KiB
TypeScript

import type { Meta, StoryObj } from '@storybook/react';
import { SendHorizontal, Trash2 } from 'lucide-react';
import { useState } from 'react';
import { Stage, me, people, tasks } from '../../stories/fixtures';
import { priorityLabel, type Priority } from '../../lib/tokens';
import { PersonAvatar } from '../Avatar/Avatar';
import { StatusBadge, Swatch } from '../Badge/Badge';
import { Button, type ButtonState } from '../Button/Button';
import {
Comment,
CommentAuthor,
CommentBody,
CommentBubble,
CommentComposer,
CommentComposerHint,
CommentComposerRow,
CommentHeader,
CommentInput,
CommentList,
CommentTime,
} from '../Comment/Comment';
import { Field, FieldError, FieldLabel, FieldNote, Input, Select, SelectOption, Textarea } from '../Field/Field';
import { SegmentedControl, SegmentedControlItem } from '../SegmentedControl/SegmentedControl';
import {
AlertDialog,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
Dialog,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
Drawer,
DrawerActions,
DrawerBody,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from './Dialog';
const meta: Meta<typeof Dialog> = {
title: 'Overlays/Dialog',
component: Dialog,
};
export default meta;
type Story = StoryObj<typeof Dialog>;
const priorities: Priority[] = ['high', 'medium', 'low'];
function PrioritySelect({ value, onValueChange }: { value: string; onValueChange: (v: string) => void }) {
return (
<SegmentedControl aria-label="Priorität" size="md" value={value} onValueChange={onValueChange}>
{priorities.map((p) => (
<SegmentedControlItem key={p} value={p}>
{priorityLabel[p]}
</SegmentedControlItem>
))}
</SegmentedControl>
);
}
function GroupOptions() {
return (
<>
<SelectOption value="swe">SWE · Collabry</SelectOption>
<SelectOption value="db">Datenbanken Übung</SelectOption>
<SelectOption value="mk">Marketing Seminar</SelectOption>
</>
);
}
function PeopleOptions() {
return (
<>
{Object.entries(people).map(([k, p]) => (
<SelectOption key={k} value={k}>
{p.name}
</SelectOption>
))}
</>
);
}
export const NewTask: Story = {
render: function Render() {
const [open, setOpen] = useState(true);
const [prio, setPrio] = useState('medium');
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}>
<Dialog open={open} onOpenChange={setOpen}>
<div className="p-6">
<DialogTrigger asChild>
<Button variant="primary">Neue Aufgabe</Button>
</DialogTrigger>
</div>
<DialogContent>
<DialogHeader>
<DialogTitle>Neue Aufgabe</DialogTitle>
<DialogDescription>Die zuständige Person wird benachrichtigt.</DialogDescription>
</DialogHeader>
<DialogBody>
<Field>
<FieldLabel>Titel</FieldLabel>
<Input placeholder="Was ist zu tun?" value={title} onChange={(e) => setTitle(e.target.value)} />
{tried && !title.trim() && <FieldError>Bitte gib einen Titel ein.</FieldError>}
</Field>
<div className="grid grid-cols-[repeat(auto-fit,minmax(200px,1fr))] gap-4">
<Field>
<FieldLabel>Gruppe</FieldLabel>
<Select>
<GroupOptions />
</Select>
</Field>
<Field>
<FieldLabel>Zuständig</FieldLabel>
<Select>
<PeopleOptions />
</Select>
</Field>
<Field>
<FieldLabel>Fällig am</FieldLabel>
<Input 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>
<PrioritySelect value={prio} onValueChange={setPrio} />
</div>
</div>
<Field>
<FieldLabel>
Beschreibung <FieldNote>(optional)</FieldNote>
</FieldLabel>
<Textarea rows={3} />
</Field>
</DialogBody>
<DialogFooter>
<DialogClose asChild>
<Button>Abbrechen</Button>
</DialogClose>
<Button variant="primary" state={state} onClick={submit}>
Aufgabe erstellen
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</Stage>
);
},
};
export const Confirmation: Story = {
render: () => (
<Stage height={360}>
<AlertDialog defaultOpen>
<div className="p-6">
<AlertDialogTrigger asChild>
<Button variant="danger-outline">Aufgabe löschen</Button>
</AlertDialogTrigger>
</div>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Aufgabe löschen?</AlertDialogTitle>
<AlertDialogDescription>
„ER-Diagramm finalisieren“ wird für alle Gruppenmitglieder entfernt.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Abbrechen</AlertDialogCancel>
<Button variant="danger">Löschen</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Stage>
),
};
export const TaskDetails: Story = {
render: function Render() {
const [draft, setDraft] = useState('');
const [prio, setPrio] = useState('high');
const t = tasks[1];
return (
<Stage height={760}>
<Drawer defaultOpen>
<div className="p-6">
<DrawerTrigger asChild>
<Button>Details öffnen</Button>
</DrawerTrigger>
</div>
<DrawerContent aria-describedby={undefined}>
<DrawerTitle className="sr-only">{t.title}</DrawerTitle>
<DrawerHeader>
<span className="flex min-w-0 items-center gap-[7px] text-sm text-fg-muted">
<Swatch color={t.group.color} />
{t.group.name}
</span>
<DrawerActions>
<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>
</DrawerActions>
</DrawerHeader>
<DrawerBody>
<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">
<SelectOption value="open">Offen</SelectOption>
<SelectOption value="doing">In Arbeit</SelectOption>
<SelectOption value="review">Review</SelectOption>
<SelectOption value="done">Erledigt</SelectOption>
</Select>
<label htmlFor="td-who" className="text-sm text-fg-subtle">
Zuständig
</label>
<Select id="td-who">
<PeopleOptions />
</Select>
<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>
<PrioritySelect value={prio} onValueChange={setPrio} />
</div>
<Field>
<FieldLabel>Beschreibung</FieldLabel>
<Textarea 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>
<CommentList>
<Comment>
<PersonAvatar person={people.LB} size={30} aria-hidden="true" />
<CommentBody>
<CommentHeader>
<CommentAuthor>{people.LB.name}</CommentAuthor>
<CommentTime>vor 2 Std.</CommentTime>
</CommentHeader>
<CommentBubble>Bitte auch die Validierung der E-Mail-Adresse einbauen.</CommentBubble>
</CommentBody>
</Comment>
<Comment>
<PersonAvatar person={me} size={30} aria-hidden="true" />
<CommentBody>
<CommentHeader>
<CommentAuthor>{me.name}</CommentAuthor>
<CommentTime>vor 1 Std.</CommentTime>
</CommentHeader>
<CommentBubble>Mache ich, kommt heute noch.</CommentBubble>
</CommentBody>
</Comment>
</CommentList>
</section>
</DrawerBody>
<DrawerFooter>
<CommentComposer>
<CommentComposerRow>
<PersonAvatar person={me} size={30} aria-hidden="true" />
<CommentInput
value={draft}
onChange={(e) => setDraft(e.target.value)}
onSubmit={() => setDraft('')}
/>
<Button
variant="primary"
iconOnly
aria-label="Kommentar senden"
className="h-[38px] w-[38px]"
disabled={!draft.trim()}
>
<SendHorizontal size={16} strokeWidth={2} />
</Button>
</CommentComposerRow>
<CommentComposerHint />
</CommentComposer>
</DrawerFooter>
</DrawerContent>
</Drawer>
</Stage>
);
},
};