shadcn base
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { ChevronRight, MoreHorizontal } from 'lucide-react';
|
||||
import { swatches } from '../../lib/tokens';
|
||||
import { Swatch } from '../Badge/Badge';
|
||||
import { Button, ButtonLink } from '../Button/Button';
|
||||
import { StatusProgress } from '../Progress/Progress';
|
||||
import { Card, CardFooter, CardHeader } from './Card';
|
||||
|
||||
const meta: Meta<typeof Card> = {
|
||||
title: 'Grundlagen/Card',
|
||||
component: Card,
|
||||
argTypes: { padding: { control: 'inline-radio', options: ['none', 'sm', 'md'] } },
|
||||
};
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof Card>;
|
||||
|
||||
const more = (
|
||||
<Button variant="ghost" size="xs" iconOnly aria-label="Mehr Optionen" className="text-fg-subtle">
|
||||
<MoreHorizontal size={16} strokeWidth={2.5} />
|
||||
</Button>
|
||||
);
|
||||
|
||||
export const Leer: Story = {
|
||||
args: { padding: 'md', children: 'Inhalt' },
|
||||
decorators: [(Story) => <div className="max-w-[420px]">{Story()}</div>],
|
||||
};
|
||||
|
||||
export const Projektfortschritt: Story = {
|
||||
render: () => (
|
||||
<Card aria-labelledby="h-progress" innerClassName="gap-5">
|
||||
<CardHeader
|
||||
titleId="h-progress"
|
||||
title="Projektfortschritt"
|
||||
subtitle={
|
||||
<span className="flex items-center gap-2 text-fg-muted">
|
||||
<Swatch color={swatches.violet} size={10} />
|
||||
SWE · Collabry <span className="text-fg-subtle">Iteration 2</span>
|
||||
</span>
|
||||
}
|
||||
actions={more}
|
||||
className="items-start"
|
||||
/>
|
||||
<div className="flex flex-wrap items-center gap-x-12 gap-y-5">
|
||||
<div className="flex-none">
|
||||
<div className="text-hero font-bold tracking-[-0.03em] tabular-nums">56%</div>
|
||||
<div className="mt-2 text-fg-muted">
|
||||
<strong className="text-fg">9 von 16</strong> Aufgaben erledigt
|
||||
</div>
|
||||
</div>
|
||||
<StatusProgress counts={{ done: 9, review: 2, doing: 3, open: 2 }} className="flex-[1_1_320px]" />
|
||||
<div className="flex-none">
|
||||
<div className="text-sm text-fg-subtle">Abgabe Iteration 2</div>
|
||||
<div className="mt-0.5 text-[17px] font-bold">Fr, 27. November</div>
|
||||
<div className="mt-0.5 font-bold text-accent-fg">noch 26 Tage</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
),
|
||||
};
|
||||
|
||||
export const MitFusszeile: Story = {
|
||||
name: 'Mit Fußzeile',
|
||||
render: () => (
|
||||
<div className="max-w-[420px]">
|
||||
<Card aria-labelledby="h-dl" innerClassName="min-h-[220px]">
|
||||
<CardHeader titleId="h-dl" title="Anstehende Deadlines" count={6} actions={more} />
|
||||
<p className="m-0 text-fg-muted">Listeninhalt …</p>
|
||||
<CardFooter>
|
||||
<ButtonLink href="#" size="sm" className="h-[34px]" iconEnd={<ChevronRight size={14} strokeWidth={1.75} />}>
|
||||
Zum Kalender
|
||||
</ButtonLink>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</div>
|
||||
),
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';
|
||||
import { cn } from '../../lib/cn';
|
||||
import {
|
||||
Card as UiCard,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardFooter as UiCardFooter,
|
||||
CardHeader as UiCardHeader,
|
||||
CardTitle,
|
||||
} from '../ui/card';
|
||||
import { CountBadge } from '../Badge/Badge';
|
||||
|
||||
export interface CardProps extends HTMLAttributes<HTMLElement> {
|
||||
/** Element to render as; `section` for dashboard panels, `article` for group cards. */
|
||||
as?: 'div' | 'section' | 'article' | 'form' | 'aside';
|
||||
/** Inner padding. `none` lets rows run edge to edge (settings, task list). */
|
||||
padding?: 'none' | 'sm' | 'md';
|
||||
/** Classes for the inner surface. */
|
||||
innerClassName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The design's signature double frame: a dark 5px rim around a raised surface.
|
||||
* Use it for dashboard panels, settings sections, auth forms and group cards.
|
||||
*/
|
||||
export const Card = forwardRef<HTMLElement, CardProps>(function Card(
|
||||
{ as: Tag = 'section', padding = 'md', className, innerClassName, children, ...props },
|
||||
ref,
|
||||
) {
|
||||
return (
|
||||
<Tag
|
||||
ref={ref as never}
|
||||
className={cn('flex min-w-0 rounded-[18px] border border-line-frame bg-frame p-[5px]', className)}
|
||||
{...props}
|
||||
>
|
||||
<UiCard
|
||||
className={cn(
|
||||
padding === 'md' && 'gap-3.5 px-[22px] py-5',
|
||||
padding === 'sm' && 'gap-4 px-[18px] pt-[18px] pb-4',
|
||||
innerClassName,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</UiCard>
|
||||
</Tag>
|
||||
);
|
||||
});
|
||||
|
||||
export interface CardHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
||||
title: ReactNode;
|
||||
/** id for the heading, so the card can be `aria-labelledby` it. */
|
||||
titleId?: string;
|
||||
count?: ReactNode;
|
||||
/** Secondary line under the title. */
|
||||
subtitle?: ReactNode;
|
||||
/** Right side: filters, "more" button, add button. */
|
||||
actions?: ReactNode;
|
||||
/** Heading level. */
|
||||
level?: 2 | 3;
|
||||
}
|
||||
|
||||
export function CardHeader({ title, titleId, count, subtitle, actions, level = 2, ...props }: CardHeaderProps) {
|
||||
const H = level === 2 ? 'h2' : 'h3';
|
||||
return (
|
||||
<UiCardHeader {...props}>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<CardTitle asChild>
|
||||
<H id={titleId}>{title}</H>
|
||||
</CardTitle>
|
||||
{count !== undefined && <CountBadge>{count}</CountBadge>}
|
||||
</div>
|
||||
{subtitle && <CardDescription className="mt-1">{subtitle}</CardDescription>}
|
||||
</div>
|
||||
{actions && <CardAction>{actions}</CardAction>}
|
||||
</UiCardHeader>
|
||||
);
|
||||
}
|
||||
|
||||
/** Footer row that pins its content to the bottom of a card. */
|
||||
export const CardFooter = UiCardFooter;
|
||||
Reference in New Issue
Block a user