Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/ui/src/stories/Textarea.stories.tsx
T

77 lines
1.8 KiB
TypeScript

import type { Meta, StoryObj } from "@storybook/react";
import { Textarea } from "~/components/ui/textarea";
function Field({
label,
hint,
error,
htmlFor,
children,
}: {
label: string;
hint?: string;
error?: string;
htmlFor: string;
children: React.ReactNode;
}) {
return (
<label className="flex max-w-sm flex-col gap-1.5 text-sm" htmlFor={htmlFor}>
<span className="font-medium">{label}</span>
{children}
{hint && !error ? <span className="text-muted-foreground text-xs">{hint}</span> : null}
{error ? (
<span className="text-destructive text-xs" role="alert">
{error}
</span>
) : null}
</label>
);
}
const meta: Meta<typeof Textarea> = {
title: "UI / Inputs / Textarea",
component: Textarea,
tags: ["autodocs"],
argTypes: {
disabled: { control: "boolean" },
},
args: { placeholder: "Tell us what happened…", rows: 4 },
};
export default meta;
type Story = StoryObj<typeof Textarea>;
export const Default: Story = {
render: (args) => (
<Field label="Message" htmlFor="msg-default">
<Textarea id="msg-default" {...args} />
</Field>
),
};
export const WithCharacterHint: Story = {
render: (args) => (
<Field label="Bio" hint="Max 280 characters." htmlFor="bio-hint">
<Textarea id="bio-hint" {...args} maxLength={280} />
</Field>
),
};
export const WithError: Story = {
render: (args) => (
<Field label="Message" error="Message can not be empty." htmlFor="msg-error">
<Textarea id="msg-error" {...args} aria-invalid="true" />
</Field>
),
};
export const Disabled: Story = {
args: { disabled: true, defaultValue: "Submission already locked — read-only." },
render: (args) => (
<Field label="Message" htmlFor="msg-disabled">
<Textarea id="msg-disabled" {...args} />
</Field>
),
};