init commit
This commit is contained in:
@@ -1,41 +1,112 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { SendHorizontal } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { me, people } from '../../stories/fixtures';
|
||||
import { CommentComposer, CommentItem, type CommentData } from './Comment';
|
||||
import { PersonAvatar, type Person } from '../Avatar/Avatar';
|
||||
import { Button } from '../Button/Button';
|
||||
import {
|
||||
Comment,
|
||||
CommentAuthor,
|
||||
CommentBody,
|
||||
CommentBubble,
|
||||
CommentComposer,
|
||||
CommentComposerHint,
|
||||
CommentComposerRow,
|
||||
CommentHeader,
|
||||
CommentInput,
|
||||
CommentList,
|
||||
CommentTime,
|
||||
} from './Comment';
|
||||
|
||||
const meta: Meta<typeof CommentItem> = {
|
||||
title: 'Aufgaben/Kommentare',
|
||||
component: CommentItem,
|
||||
const meta: Meta<typeof Comment> = {
|
||||
title: 'Tasks/Comment',
|
||||
component: Comment,
|
||||
};
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof CommentItem>;
|
||||
type Story = StoryObj<typeof Comment>;
|
||||
|
||||
interface CommentData {
|
||||
id: string;
|
||||
author: Person;
|
||||
when: string;
|
||||
text: string;
|
||||
mine?: boolean;
|
||||
}
|
||||
|
||||
const initial: CommentData[] = [
|
||||
{ id: 'c1', author: people.PM, when: 'vor 1 Std.', text: 'Kannst du die n:m-Beziehung zwischen Gruppe und Mitglied noch auflösen?' },
|
||||
{ id: 'c2', author: me, when: 'vor 40 Min.', text: 'Ja, ich lege eine Zwischentabelle „Mitgliedschaft“ an.', mine: true },
|
||||
{
|
||||
id: 'c1',
|
||||
author: people.PM,
|
||||
when: 'vor 1 Std.',
|
||||
text: 'Kannst du die n:m-Beziehung zwischen Gruppe und Mitglied noch auflösen?',
|
||||
},
|
||||
{
|
||||
id: 'c2',
|
||||
author: me,
|
||||
when: 'vor 40 Min.',
|
||||
text: 'Ja, ich lege eine Zwischentabelle „Mitgliedschaft“ an.',
|
||||
mine: true,
|
||||
},
|
||||
];
|
||||
|
||||
export const Verlauf: Story = {
|
||||
export const Thread: Story = {
|
||||
render: function Render() {
|
||||
const [comments, setComments] = useState(initial);
|
||||
const [draft, setDraft] = useState('');
|
||||
const empty = !draft.trim();
|
||||
const send = () => {
|
||||
if (empty) return;
|
||||
setComments((cs) => [
|
||||
...cs,
|
||||
{ id: `c${cs.length + 1}`, author: me, when: 'gerade eben', text: draft, mine: true },
|
||||
]);
|
||||
setDraft('');
|
||||
};
|
||||
return (
|
||||
<div className="flex max-w-[460px] flex-col gap-4">
|
||||
<ol aria-label="Kommentarverlauf" className="m-0 flex flex-col gap-3.5 p-0">
|
||||
<CommentList aria-label="Kommentarverlauf">
|
||||
{comments.map((c) => (
|
||||
<CommentItem key={c.id} comment={c} onDelete={(id) => setComments((cs) => cs.filter((x) => x.id !== id))} />
|
||||
<Comment key={c.id}>
|
||||
<PersonAvatar person={c.author} size={30} aria-hidden="true" />
|
||||
<CommentBody>
|
||||
<CommentHeader>
|
||||
<CommentAuthor>{c.author.name}</CommentAuthor>
|
||||
<CommentTime>{c.when}</CommentTime>
|
||||
{c.mine && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
className="ml-auto h-6 px-1.5 text-xs text-fg-subtle"
|
||||
aria-label="Kommentar löschen"
|
||||
onClick={() => setComments((cs) => cs.filter((x) => x.id !== c.id))}
|
||||
>
|
||||
Löschen
|
||||
</Button>
|
||||
)}
|
||||
</CommentHeader>
|
||||
<CommentBubble>{c.text}</CommentBubble>
|
||||
</CommentBody>
|
||||
</Comment>
|
||||
))}
|
||||
</ol>
|
||||
<CommentComposer
|
||||
me={me}
|
||||
value={draft}
|
||||
onChange={setDraft}
|
||||
onSend={() => {
|
||||
setComments((cs) => [...cs, { id: `c${cs.length + 1}`, author: me, when: 'gerade eben', text: draft, mine: true }]);
|
||||
setDraft('');
|
||||
}}
|
||||
/>
|
||||
</CommentList>
|
||||
<CommentComposer>
|
||||
<CommentComposerRow>
|
||||
<PersonAvatar person={me} size={30} aria-hidden="true" />
|
||||
<CommentInput value={draft} onChange={(e) => setDraft(e.target.value)} onSubmit={send} />
|
||||
<Button
|
||||
variant="primary"
|
||||
iconOnly
|
||||
aria-label="Kommentar senden"
|
||||
aria-disabled={empty}
|
||||
className={empty ? 'h-[38px] w-[38px] opacity-50' : 'h-[38px] w-[38px]'}
|
||||
onClick={send}
|
||||
>
|
||||
<SendHorizontal size={16} strokeWidth={2} />
|
||||
</Button>
|
||||
</CommentComposerRow>
|
||||
<CommentComposerHint />
|
||||
</CommentComposer>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user