diff --git a/README.md b/README.md index 9e15ba4..bcc2f58 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @collabry/components -React + Tailwind CSS component library for the Collabry UI, built on [shadcn/ui](https://ui.shadcn.com) (Radix UI, cmdk, Sonner), with a Storybook catalogue. +React 19 + Tailwind CSS component library for the Collabry UI, built on [shadcn/ui](https://ui.shadcn.com) (Radix UI, cmdk, Sonner), with a Storybook catalogue. ```sh npm install @@ -25,32 +25,69 @@ import '@fontsource/lato/900.css'; ; ``` -`react`, `react-dom` are peer dependencies; `radix-ui`, `cmdk`, `sonner`, `class-variance-authority`, `lucide-react`, `clsx` and `tailwind-merge` are installed with the package. +`react` and `react-dom` (19) are peer dependencies; `radix-ui`, `cmdk`, `sonner`, `class-variance-authority`, `lucide-react`, `clsx` and `tailwind-merge` come with the package. Dialogs, menus and popovers portal into the nearest `ThemeProvider` element, so they keep its theme, accent and tint. +## Composition + +Components are small parts you assemble, like shadcn/ui. They don't take data objects or config props; each part renders one element, takes `className` and `ref`, and has a `data-slot` (`card-title`, `nav-item`, …) to target it from outside. Parts that are often links or headings accept `asChild`. The design (spacing, colors, states) lives in the parts; structure and data live in your code. + +```tsx + + +
+ + + Meine Aufgaben 6 + + … + + + + + + + + {task.title} + … + + … + + +
+
+
+``` + +Conventions: + +- State flows down through context where it's shared: `Field` wires label, control and messages (`id`, `aria-describedby`, `aria-invalid`); `Sidebar` tells its parts whether it's collapsed; `TaskTable` sets the column grid of its rows. +- Overlays use the Radix pattern: `Dialog` + `DialogTrigger` + `DialogContent`, `Menu` + `MenuTrigger` + `MenuContent`, `Popover` + `PopoverTrigger` + `PopoverContent`. Controlled (`open` / `onOpenChange`) or not. +- Text the user sees is German by default (labels like "Schließen"); pass your own children or `aria-label` to change it. +- The stories are the reference compositions; `src/stories/examples.tsx` holds the bigger ones (notification panel, account menu). + ## Structure - `src/styles/tokens.css`: design tokens (`--cl-*`) for dark and light, with accent and tint derived via `color-mix` -- `src/styles/index.css`: Tailwind v4 theme mapping tokens to utilities (`bg-surface`, `text-fg-muted`, `border-line`, …) -- `src/components/ui/`: shadcn/ui primitives (`components.json`), restyled to the Collabry tokens. Accessibility, focus and keyboard handling come from Radix / cmdk. -- `src/components//.tsx` + `.stories.tsx`: Collabry components composed from `ui/` -- `src/stories/`: introduction, token overview and sample data from the design +- `src/styles/index.css`: Tailwind v4 theme mapping tokens to utilities (`bg-surface`, `text-fg-muted`, `border-line`, …) and to shadcn's token names +- `src/components/ui/`: shadcn/ui primitives (`components.json`), restyled to the Collabry tokens +- `src/components//.tsx` + `.stories.tsx`: Collabry parts built from `ui/` ## Components -| Area | Components | +| Area | Parts | | --- | --- | -| Grundlagen | `ThemeProvider`, `Button`, `ButtonLink`, `Card`, `CardHeader`, `CardFooter`, `PageHeader`, `EmptyState`, `Spinner`, `Logo` | -| Formulare | `Field`, `Input`, `PasswordInput`, `Textarea`, `Select`, `Checkbox`, `TaskCheckbox`, `SegmentedControl` | -| Anzeige | `StatusBadge`, `CountBadge`, `RoleBadge`, `Swatch`, `Kbd`, `Avatar`, `AvatarStack`, `ProgressBar`, `StatusProgress` | -| Overlays | `Menu`, `Dialog`, `Drawer`, `Toast`, `Toaster`, `toast()`, `CommandPalette`, `SearchTrigger`, `NotificationPanel`, `NotificationItem` | -| Navigation | `Sidebar`, `NavItem`, `UserMenu`, `MobileHeader`, `MobileTabBar`, `SettingsNav` | -| Aufgaben | `TaskTable`, `TaskRow`, `TaskSectionHeader`, `PriorityLabel`, `DeadlineItem`, `DateTile`, `CommentItem`, `CommentComposer` | -| Gruppen | `GroupCard`, `GroupRow`, `NewGroupTile`, `InviteBanner` | -| Kalender | `CalendarMonth`, `CalendarToolbar`, `CalendarLegend`, `GroupFilterChip`, `DayEventItem` | -| Einstellungen | `SettingsSection`, `SettingsRow`, `ThemePicker`, `ColorSchemePicker`, `SaveStatus` | -| Anmeldung | `AuthBrandPanel`, `FeatureItem`, `PasswordRules` | +| Foundations | `ThemeProvider`, `Button`, `CardFrame`, `Card`, `CardHeader`, `CardHeading`, `CardTitle`, `CardDescription`, `CardAction`, `CardFooter`, `PageHeader`, `PageHeading`, `PageEyebrow`, `PageTitle`, `PageDescription`, `PageActions`, `Empty*`, `SectionLabel`, `MetaSeparator`, `Spinner`, `Logo` | +| Forms | `Field`, `FieldHeader`, `FieldLabel`, `FieldNote`, `FieldDescription`, `FieldError`, `Input`, `InputGroup`, `InputGroupAddon`, `InputGroupButton`, `PasswordInput`, `Textarea`, `Select`, `SelectOption`, `Checkbox`, `TaskCheckbox`, `SegmentedControl`, `SegmentedControlItem`, `SegmentedControlCount` | +| Display | `StatusBadge`, `CountBadge`, `RoleBadge`, `Swatch`, `Kbd`, `KbdGroup`, `IndicatorDot`, `Avatar`, `AvatarImage`, `AvatarFallback`, `PersonAvatar`, `AvatarGroup`, `ProgressBar`, `StatusProgress`, `StatusBar`, `StatusLegend` | +| Overlays | `Dialog*`, `AlertDialog*`, `Drawer*`, `Menu*`, `Popover*`, `Command*`, `SearchTrigger`, `Toast`, `ToastAction`, `ToastClose`, `Toaster`, `toast()`, `Notification*` | +| Navigation | `Sidebar`, `SidebarHeader`, `SidebarLogo`, `SidebarActions`, `SidebarButton`, `SidebarToggle`, `SidebarNav`, `NavItem`, `NavItemLabel`, `SidebarFooter`, `SidebarUserButton`, `SidebarUserName`, `MobileHeader*`, `MobileTabBar`, `MobileTab` | +| Tasks | `TaskTable`, `TaskTableHeader`, `TaskTableHead`, `TaskRow`, `TaskCell`, `TaskOpenButton`, `TaskTitle`, `TaskMeta`, `TaskCommentCount`, `TaskAssignee`, `TaskDue`, `TaskTableEmpty`, `TaskSection*`, `PriorityLabel`, `Deadline*`, `DateTile`, `Comment*` | +| Groups | `GroupRow*`, `GroupCard*`, `NewGroupTile*`, `InviteBanner*` | +| Calendar | `CalendarGrid`, `CalendarWeekday`, `CalendarDay*`, `CalendarChip`, `CalendarMarker`, `CalendarLegend*`, `CalendarToolbar`, `CalendarNav`, `CalendarRangeLabel`, `FilterChip`, `FilterChipSwatch`, `DayEvent*` | +| Settings | `SettingsNav*`, `SettingsSection*`, `SettingsRow*`, `ThemePicker`, `ThemeOption`, `ThemePreview`, `ThemeOptionLabel`, `ColorSchemePicker`, `ColorSchemeOption`, `SaveStatus` | +| Auth | `AuthBrandPanel`, `AuthBrandContent`, `AuthHeadline`, `Feature*`, `PasswordRules`, `PasswordRule`, `passwordRules()` | ## Adding shadcn/ui components diff --git a/package-lock.json b/package-lock.json index 88df7e7..bb107ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,11 +27,11 @@ "@storybook/test": "8.6.14", "@tailwindcss/vite": "4.1.11", "@types/node": "22.10.5", - "@types/react": "18.3.18", - "@types/react-dom": "18.3.5", + "@types/react": "19.2.2", + "@types/react-dom": "19.2.2", "@vitejs/plugin-react": "4.3.4", - "react": "18.3.1", - "react-dom": "18.3.1", + "react": "19.2.0", + "react-dom": "19.2.0", "storybook": "8.6.14", "tailwindcss": "4.1.11", "typescript": "5.7.3", @@ -4192,32 +4192,24 @@ "undici-types": "~6.20.0" } }, - "node_modules/@types/prop-types": { - "version": "15.7.15", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", - "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "devOptional": true, - "license": "MIT" - }, "node_modules/@types/react": { - "version": "18.3.18", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.18.tgz", - "integrity": "sha512-t4yC+vtgnkYjNSKlFx1jkAhH8LgTo2N/7Qvi83kdEaUtMDiwpbLAktKDaAMlRcJ5eSxZkH74eEGt1ky31d7kfQ==", + "version": "19.2.2", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.2.tgz", + "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", "devOptional": true, "license": "MIT", "dependencies": { - "@types/prop-types": "*", "csstype": "^3.0.2" } }, "node_modules/@types/react-dom": { - "version": "18.3.5", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.5.tgz", - "integrity": "sha512-P4t6saawp+b/dFrUr2cvkVsfvPguwsxtH6dNIYRllMsefqFzkZk5UIjzyDOv5g1dXIPdG4Sp1yCR4Z6RCUsG/Q==", + "version": "19.2.2", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.2.tgz", + "integrity": "sha512-9KQPoO6mZCi7jcIStSnlOWn2nEF3mNmyr3rIAsGnAbQKYbRLyqmeSc39EVgtxXVia+LMT8j3knZLAZAh+xLmrw==", "devOptional": true, "license": "MIT", "peerDependencies": { - "@types/react": "^18.0.0" + "@types/react": "^19.2.0" } }, "node_modules/@types/resolve": { @@ -5790,6 +5782,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true, "license": "MIT" }, "node_modules/jsdoc-type-pratt-parser": { @@ -6146,18 +6139,6 @@ "dev": true, "license": "MIT" }, - "node_modules/loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "license": "MIT", - "dependencies": { - "js-tokens": "^3.0.0 || ^4.0.0" - }, - "bin": { - "loose-envify": "cli.js" - } - }, "node_modules/loupe": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz", @@ -6678,13 +6659,10 @@ } }, "node_modules/react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", - "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "version": "19.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz", + "integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==", "license": "MIT", - "dependencies": { - "loose-envify": "^1.1.0" - }, "engines": { "node": ">=0.10.0" } @@ -6722,16 +6700,15 @@ } }, "node_modules/react-dom": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", - "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "version": "19.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.0.tgz", + "integrity": "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ==", "license": "MIT", "dependencies": { - "loose-envify": "^1.1.0", - "scheduler": "^0.23.2" + "scheduler": "^0.27.0" }, "peerDependencies": { - "react": "^18.3.1" + "react": "^19.2.0" } }, "node_modules/react-is": { @@ -6962,13 +6939,10 @@ } }, "node_modules/scheduler": { - "version": "0.23.2", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", - "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", - "license": "MIT", - "dependencies": { - "loose-envify": "^1.1.0" - } + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", + "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", + "license": "MIT" }, "node_modules/semver": { "version": "6.3.2", diff --git a/package.json b/package.json index 02d2519..7ed9a60 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "typecheck": "tsc --noEmit" }, "peerDependencies": { - "react": "^18.2.0 || ^19.0.0", - "react-dom": "^18.2.0 || ^19.0.0" + "react": "^19.0.0", + "react-dom": "^19.0.0" }, "dependencies": { "class-variance-authority": "0.7.1", @@ -51,11 +51,11 @@ "@storybook/test": "8.6.14", "@tailwindcss/vite": "4.1.11", "@types/node": "22.10.5", - "@types/react": "18.3.18", - "@types/react-dom": "18.3.5", + "@types/react": "19.2.2", + "@types/react-dom": "19.2.2", "@vitejs/plugin-react": "4.3.4", - "react": "18.3.1", - "react-dom": "18.3.1", + "react": "19.2.0", + "react-dom": "19.2.0", "storybook": "8.6.14", "tailwindcss": "4.1.11", "typescript": "5.7.3", diff --git a/src/components/Auth/Auth.stories.tsx b/src/components/Auth/Auth.stories.tsx index 6e79560..270c62d 100644 --- a/src/components/Auth/Auth.stories.tsx +++ b/src/components/Auth/Auth.stories.tsx @@ -1,12 +1,29 @@ import type { Meta, StoryObj } from '@storybook/react'; +import { ListChecks, Target, Users } from 'lucide-react'; import { useState, type FormEvent, type ReactNode } from 'react'; import { Button, type ButtonState } from '../Button/Button'; +import { Card, CardFrame } from '../Card/Card'; import { Checkbox } from '../Checkbox/Checkbox'; -import { Field, Input, PasswordInput } from '../Field/Field'; -import { AuthBrandPanel, PasswordRules, passwordRules } from './Auth'; +import { Field, FieldError, FieldHeader, FieldLabel, Input, PasswordInput } from '../Field/Field'; +import { PageDescription, PageTitle } from '../Layout/Layout'; +import { Logo } from '../Logo/Logo'; +import { + AuthBrandContent, + AuthBrandPanel, + AuthHeadline, + FeatureContent, + FeatureDescription, + FeatureIcon, + FeatureItem, + FeatureList, + FeatureTitle, + PasswordRule, + PasswordRules, + passwordRules, +} from './Auth'; const meta: Meta = { - title: 'Anmeldung/Anmeldung', + title: 'Auth/Auth', component: AuthBrandPanel, parameters: { layout: 'fullscreen' }, }; @@ -14,18 +31,56 @@ export default meta; type Story = StoryObj; -function FormCard({ label, onSubmit, children }: { label: string; onSubmit: (e: FormEvent) => void; children: ReactNode }) { +const fi = { size: 18, strokeWidth: 1.75, 'aria-hidden': true } as const; +const features = [ + { + icon: , + title: 'Alles an einem Ort', + description: 'Team, Aufgaben und Deadlines. Endlich gebündelt!', + }, + { icon: , title: 'Immer im Bild', description: 'Wer macht was bis wann? Ein Blick genügt!' }, + { icon: , title: 'Mehr Fokus', description: 'Weniger Chaos, mehr Zeit fürs Wesentliche.' }, +]; + +function Brand() { return ( -
-
- {children} -
-
+ + + + Gruppenarbeit, die einfach funktioniert! + + {features.map((f) => ( + + {f.icon} + + {f.title} + {f.description} + + + ))} + + + + ); +} + +function FormCard({ + label, + onSubmit, + children, +}: { + label: string; + onSubmit: (e: FormEvent) => void; + children: ReactNode; +}) { + return ( + + +
+ {children} +
+
+
); } @@ -47,46 +102,42 @@ export const Login: Story = { }; return (
- +
-

Willkommen zurück

-

Melde dich an, um mit deinem Team weiterzuarbeiten.

+ Willkommen zurück + Melde dich an, um mit deinem Team weiterzuarbeiten.
- - {({ id, invalid, describedBy }) => ( - setEmail(e.target.value)} - invalid={invalid} - aria-describedby={describedBy} - /> - )} + + E-Mail + setEmail(e.target.value)} + /> + {emailBad && Bitte gib eine gültige E-Mail-Adresse ein.} - Passwort vergessen?} - error={pwBad ? 'Bitte gib dein Passwort ein.' : undefined} - > - {({ id, invalid, describedBy }) => ( - setPw(e.target.value)} - invalid={invalid} - aria-describedby={describedBy} - /> - )} + + + Passwort + Passwort vergessen? + + setPw(e.target.value)} + /> + {pwBad && Bitte gib dein Passwort ein.} + + + + Angemeldet bleiben - @@ -104,19 +155,18 @@ export const Login: Story = { }, }; -export const Registrierung: Story = { +export const Register: Story = { render: function Render() { const [pw, setPw] = useState('Collabry'); const [tried, setTried] = useState(false); - const rules = passwordRules(pw); return (
- +
-

Konto erstellen

-

Sicher registrieren und direkt mit deinem Team loslegen.

+ Konto erstellen + Sicher registrieren und direkt mit deinem Team loslegen.
- {({ id }) => } - {({ id }) => } -
- - {({ id }) => } - -
- - {({ id }) => ( - setPw(e.target.value)} - aria-describedby="reg-pw-rules" - /> - )} + + Vorname + + + + Nachname + -
+ + E-Mail + + + + Passwort + setPw(e.target.value)} + aria-describedby="reg-pw-rules" + /> + + {passwordRules(pw).map((r) => ( + + {r.label} + + ))} + + @@ -164,14 +223,20 @@ export const Registrierung: Story = { }, }; -export const Passwortregeln: Story = { +export const Rules: Story = { parameters: { layout: 'padded' }, render: function Render() { const [pw, setPw] = useState('abc'); return (
setPw(e.target.value)} /> - + + {passwordRules(pw).map((r) => ( + + {r.label} + + ))} +
); }, diff --git a/src/components/Auth/Auth.tsx b/src/components/Auth/Auth.tsx index d1e8306..cfd2245 100644 --- a/src/components/Auth/Auth.tsx +++ b/src/components/Auth/Auth.tsx @@ -1,76 +1,93 @@ -import type { ReactNode } from 'react'; -import { Check, ListChecks, Target, Users } from 'lucide-react'; +import type { ComponentProps } from 'react'; +import { Check } from 'lucide-react'; import { cn } from '../../lib/cn'; -import { Logo } from '../Logo/Logo'; -export interface FeatureItemProps { - icon: ReactNode; - title: string; - description: string; -} - -/** Icon tile + title + one line, used on the login brand panel. */ -export function FeatureItem({ icon, title, description }: FeatureItemProps) { - return ( -
  • - - {icon} - -
    -
    {title}
    -
    {description}
    -
    -
  • - ); -} - -const featureIcon = { size: 18, strokeWidth: 1.75, 'aria-hidden': true } as const; - -export const defaultFeatures: FeatureItemProps[] = [ - { icon: , title: 'Alles an einem Ort', description: 'Team, Aufgaben und Deadlines. Endlich gebündelt!' }, - { icon: , title: 'Immer im Bild', description: 'Wer macht was bis wann? Ein Blick genügt!' }, - { icon: , title: 'Mehr Fokus', description: 'Weniger Chaos, mehr Zeit fürs Wesentliche.' }, -]; - -export interface AuthBrandPanelProps { - headline?: string; - features?: FeatureItemProps[]; - className?: string; -} - -/** Left half of the login and register screens. */ -export function AuthBrandPanel({ - headline = 'Gruppenarbeit, die einfach funktioniert!', - features = defaultFeatures, - className, -}: AuthBrandPanelProps) { +/** + * Left half of the login and register screens. + * + * + * + * + * Gruppenarbeit, die einfach funktioniert! + * … + * + * + */ +export function AuthBrandPanel({ className, ...props }: ComponentProps<'div'>) { return (
    - -
    -

    {headline}

    -
      - {features.map((f) => ( - - ))} -
    -
    -
    + {...props} + /> ); } -export interface PasswordRule { +export function AuthBrandContent({ className, ...props }: ComponentProps<'div'>) { + return ( +
    + ); +} + +export function AuthHeadline({ className, ...props }: ComponentProps<'p'>) { + return ( +

    + ); +} + +export function FeatureList({ className, ...props }: ComponentProps<'ul'>) { + return

      ; +} + +export function FeatureItem({ className, ...props }: ComponentProps<'li'>) { + return
    • ; +} + +export function FeatureIcon({ className, ...props }: ComponentProps<'span'>) { + return ( + + ); +} + +export function FeatureContent(props: ComponentProps<'div'>) { + return
      ; +} + +export function FeatureTitle({ className, ...props }: ComponentProps<'div'>) { + return
      ; +} + +export function FeatureDescription({ className, ...props }: ComponentProps<'div'>) { + return ( +
      + ); +} + +export interface PasswordRuleCheck { label: string; met: boolean; } /** Checks a password against the design's three rules. */ -export function passwordRules(pw: string): PasswordRule[] { +export function passwordRules(pw: string): PasswordRuleCheck[] { return [ { label: 'Mindestens 8 Zeichen', met: pw.length >= 8 }, { label: 'Groß- und Kleinbuchstaben', met: /[a-zäöü]/.test(pw) && /[A-ZÄÖÜ]/.test(pw) }, @@ -78,42 +95,49 @@ export function passwordRules(pw: string): PasswordRule[] { ]; } -export interface PasswordRulesProps { - rules: PasswordRule[]; - id?: string; - /** Show unmet rules in red (after a submit attempt). */ - showErrors?: boolean; - className?: string; -} - -/** Live checklist under the password field. */ -export function PasswordRules({ rules, id, showErrors, className }: PasswordRulesProps) { +/** Live checklist under a password field: `PasswordRule`s. Link it with `aria-describedby`. */ +export function PasswordRules({ className, ...props }: ComponentProps<'ul'>) { return ( -
        - {rules.map((r) => ( -
      • + ); +} + +export interface PasswordRuleProps extends ComponentProps<'li'> { + met: boolean; + /** Show it in red while unmet (after a submit attempt). */ + showError?: boolean; +} + +export function PasswordRule({ met, showError, className, children, ...props }: PasswordRuleProps) { + return ( +
      • + {met ? ( + + + ) : ( + - {r.met ? ( - - - ) : ( - - )} - {r.label} - {r.met ? 'erfüllt' : 'nicht erfüllt'} -
      • - ))} -
      + /> + )} + {children} + {met ? 'erfüllt' : 'nicht erfüllt'} +
    • ); } diff --git a/src/components/Avatar/Avatar.stories.tsx b/src/components/Avatar/Avatar.stories.tsx index 19909b3..ac14137 100644 --- a/src/components/Avatar/Avatar.stories.tsx +++ b/src/components/Avatar/Avatar.stories.tsx @@ -1,40 +1,61 @@ import type { Meta, StoryObj } from '@storybook/react'; import { me, people } from '../../stories/fixtures'; -import { Avatar, AvatarStack } from './Avatar'; +import { Avatar, AvatarFallback, AvatarGroup, AvatarImage, PersonAvatar } from './Avatar'; -const meta: Meta = { - title: 'Anzeige/Avatar', - component: Avatar, +const meta: Meta = { + title: 'Display/Avatar', + component: PersonAvatar, args: { person: people.LB, size: 36 }, argTypes: { person: { control: false } }, }; export default meta; -type Story = StoryObj; +type Story = StoryObj; -export const Initialen: Story = {}; +export const Initials: Story = {}; -export const MitFoto: Story = { - name: 'Mit Foto', +export const Photo: Story = { args: { person: me, size: 64 }, }; -export const Groessen: Story = { - name: 'Größen', +export const Sizes: Story = { render: () => (
      {[22, 24, 26, 30, 32, 36].map((s) => ( - + ))}
      ), }; -export const Stapel: Story = { +export const Group: Story = { render: () => (
      - - + + {Object.values(people).map((p) => ( + + ))} + + + {Object.values(people).map((p) => ( + + ))} + +
      + ), +}; + +/** The parts `PersonAvatar` is made of. */ +export const Parts: Story = { + render: () => ( +
      + + + NH + + + KB +
      ), }; diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx index df03718..6833443 100644 --- a/src/components/Avatar/Avatar.tsx +++ b/src/components/Avatar/Avatar.tsx @@ -1,6 +1,6 @@ -import type { HTMLAttributes } from 'react'; +import { Children, isValidElement, type ComponentProps, type CSSProperties } from 'react'; import { cn } from '../../lib/cn'; -import { Avatar as UiAvatar, AvatarFallback, AvatarImage } from '../ui/avatar'; +import { Avatar as UiAvatar, AvatarFallback as UiAvatarFallback, AvatarImage } from '../ui/avatar'; export interface Person { name: string; @@ -11,14 +11,6 @@ export interface Person { image?: string; } -export interface AvatarProps extends HTMLAttributes { - person: Person; - /** Diameter in px. The design uses 22, 24, 26, 30, 32 and 36. */ - size?: number; - /** Ring that separates stacked avatars. */ - ring?: boolean; -} - function fontSizeFor(size: number) { if (size <= 22) return 8; if (size <= 26) return 10; @@ -26,51 +18,102 @@ function fontSizeFor(size: number) { return 12; } -export function Avatar({ person, size = 32, ring = false, className, style, ...props }: AvatarProps) { +const sizeStyle = (size: number) => + ({ width: size, height: size, '--avatar-font-size': `${fontSizeFor(size)}px` }) as CSSProperties; + +export interface AvatarProps extends ComponentProps { + /** Diameter in px. The design uses 22, 24, 26, 30, 32 and 36. */ + size?: number; +} + +/** Round avatar: put an `AvatarImage` and an `AvatarFallback` inside. Photos get a hairline ring. */ +export function Avatar({ size = 32, className, style, ...props }: AvatarProps) { return ( - {person.image && } - - - - + /> ); } -export interface AvatarStackProps extends HTMLAttributes { - people: Person[]; - size?: number; - /** Show at most this many, then "+n". */ - max?: number; +export { AvatarImage }; + +export interface AvatarFallbackProps extends ComponentProps { + /** Background color, usually the person's color. */ + color?: string; } -/** Overlapping avatars for group members. */ -export function AvatarStack({ people, size = 22, max = 5, className, ...props }: AvatarStackProps) { - const shown = people.slice(0, max); - const rest = people.length - shown.length; +/** Initials shown until (or instead of) the image. */ +export function AvatarFallback({ color, className, style, ...props }: AvatarFallbackProps) { return ( - - {shown.map((p) => ( - - ))} - {rest > 0 && ( - - +{rest} - + + ); +} + +export interface PersonAvatarProps extends Omit { + person: Person; +} + +/** `Avatar` for a `Person`: photo if there is one, else initials on their color. Labelled with the name. */ +export function PersonAvatar({ person, ...props }: PersonAvatarProps) { + return ( + + {person.image && } + + + + + ); +} + +export interface AvatarGroupProps extends ComponentProps<'span'> { + /** Show at most this many avatars, then an `AvatarGroupCount` with the rest. */ + max?: number; + /** Size of the "+n" bubble; match the avatars. */ + size?: number; +} + +/** Overlapping avatars with a ring that separates them. */ +export function AvatarGroup({ max, size = 22, className, children, ...props }: AvatarGroupProps) { + const items = Children.toArray(children).filter(isValidElement); + const shown = max === undefined ? items : items.slice(0, max); + const rest = items.length - shown.length; + return ( + + {shown} + {rest > 0 && +{rest}} ); } + +export interface AvatarGroupCountProps extends ComponentProps<'span'> { + size?: number; +} + +/** "+n" bubble at the end of an `AvatarGroup`. */ +export function AvatarGroupCount({ size = 22, className, style, ...props }: AvatarGroupCountProps) { + return ( + + ); +} diff --git a/src/components/Badge/Badge.stories.tsx b/src/components/Badge/Badge.stories.tsx index 97a3a41..f6758df 100644 --- a/src/components/Badge/Badge.stories.tsx +++ b/src/components/Badge/Badge.stories.tsx @@ -1,9 +1,9 @@ import type { Meta, StoryObj } from '@storybook/react'; import { swatches } from '../../lib/tokens'; -import { CountBadge, Kbd, RoleBadge, StatusBadge, Swatch } from './Badge'; +import { CountBadge, Kbd, KbdGroup, RoleBadge, StatusBadge, Swatch } from './Badge'; const meta: Meta = { - title: 'Anzeige/Badges', + title: 'Display/Badge', component: StatusBadge, args: { status: 'doing' }, argTypes: { status: { control: 'inline-radio', options: ['done', 'review', 'doing', 'open'] } }, @@ -14,8 +14,7 @@ type Story = StoryObj; export const Status: Story = {}; -export const AlleStatus: Story = { - name: 'Alle Status', +export const AllStatuses: Story = { render: () => (
      @@ -26,8 +25,7 @@ export const AlleStatus: Story = { ), }; -export const Zaehler: Story = { - name: 'Zähler & Rollen', +export const CountsAndRoles: Story = { render: () => (
      @@ -44,8 +42,7 @@ export const Zaehler: Story = { ), }; -export const Farbfelder: Story = { - name: 'Farbfelder & Tasten', +export const SwatchesAndKeys: Story = { render: () => (
      @@ -58,8 +55,10 @@ export const Farbfelder: Story = {
      - ⌘ - K + + ⌘ + K + ↵ Öffnen diff --git a/src/components/Badge/Badge.tsx b/src/components/Badge/Badge.tsx index f7c5173..ca26a3a 100644 --- a/src/components/Badge/Badge.tsx +++ b/src/components/Badge/Badge.tsx @@ -1,8 +1,8 @@ -import type { HTMLAttributes, ReactNode } from 'react'; +import type { ComponentProps } from 'react'; import { cn } from '../../lib/cn'; +import { taskStatusLabel, type TaskStatus } from '../../lib/tokens'; import { Badge } from '../ui/badge'; import { Kbd as UiKbd } from '../ui/kbd'; -import { taskStatusLabel, type TaskStatus } from '../../lib/tokens'; const statusStyles: Record = { done: 'text-success-fg bg-[rgba(74,222,128,0.08)] border-[rgba(74,222,128,0.22)]', @@ -11,46 +11,45 @@ const statusStyles: Record = { open: 'text-fg-open bg-status-open border-line-strong', }; -export interface StatusBadgeProps extends HTMLAttributes { +type BadgeProps = Omit, 'variant'>; + +export interface StatusBadgeProps extends BadgeProps { status: TaskStatus; - /** Overrides the default German label. */ - label?: string; } -/** Task status tag: Erledigt, Review, In Arbeit, Offen. */ -export function StatusBadge({ status, label, className, ...props }: StatusBadgeProps) { +/** Task status tag. Defaults to the German label (Erledigt, Review, In Arbeit, Offen); `children` override it. */ +export function StatusBadge({ status, className, children, ...props }: StatusBadgeProps) { return ( - - {label ?? taskStatusLabel[status]} + + {children ?? taskStatusLabel[status]} ); } -export interface CountBadgeProps extends HTMLAttributes { - children: ReactNode; +export interface CountBadgeProps extends BadgeProps { /** `accent` is used for unread counts. */ tone?: 'neutral' | 'accent'; } /** Small pill showing a count next to a heading. */ -export function CountBadge({ tone = 'neutral', className, children, ...props }: CountBadgeProps) { +export function CountBadge({ tone = 'neutral', className, ...props }: CountBadgeProps) { return ( - {children} - + /> ); } -export interface RoleBadgeProps extends HTMLAttributes { +export interface RoleBadgeProps extends BadgeProps { role?: 'admin' | 'member'; - children?: ReactNode; } -/** "Admin" / "Mitglied" tag on group cards and member lists. */ +/** "Admin" / "Mitglied" tag on group cards and member lists; `children` override the label. */ export function RoleBadge({ role = 'member', className, children, ...props }: RoleBadgeProps) { return ( { +export interface SwatchProps extends ComponentProps<'span'> { color: string; /** 8px in meta lines, 10px next to headings. */ size?: 8 | 10; @@ -74,20 +73,46 @@ export function Swatch({ color, size = 8, className, style, ...props }: SwatchPr return (