Design-System-Architektur in der Praxis: Der vollständige Build-Pfad von Design Tokens zu Komponentenbibliotheken

前端工程

Die Drei-Schichten-Architektur von Design-Systemen

┌─────────────────────────────────┐
│  Komponenten-Schicht            │  Button, Card, Modal...
├─────────────────────────────────┤
│  Muster-Schicht                 │  Formulare, Navigation, Datentabellen
├─────────────────────────────────┤
│  Token-Schicht (Design Tokens)  │  Farben, Abstände, Schriftgrößen, Schatten
└─────────────────────────────────┘

Tokens sind das Fundament, Muster sind die Komposition, Komponenten sind der Endpunkt. Von unten nach oben aufbauen, von oben nach unten konsumieren.


Das Design-Token-System

1. Farb-Tokens

/* Dreischichtige semantische Tokens */

/* Schicht 1: Primitive Werte */
:root {
  --blue-50: #eff6ff;
  --blue-500: #3b82f6;
  --blue-700: #1d4ed8;
  --gray-50: #f9fafb;
  --gray-900: #111827;
  --red-500: #ef4444;
  --green-500: #22c55e;
}

/* Schicht 2: Semantisches Mapping */
:root {
  --color-primary: var(--blue-500);
  --color-primary-hover: var(--blue-700);
  --color-surface: var(--gray-50);
  --color-text: var(--gray-900);
  --color-danger: var(--red-500);
  --color-success: var(--green-500);
}

/* Schicht 3: Komponentenspezifisch */
:root {
  --button-bg: var(--color-primary);
  --button-bg-hover: var(--color-primary-hover);
  --button-text: white;
  --input-border: var(--color-border);
  --input-border-focus: var(--color-primary);
}

2. Abstands-Tokens (8pt-Rastersystem)

:root {
  --space-0: 0;
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */
  --space-8: 3rem;     /* 48px */
  --space-10: 4rem;    /* 64px */
}

3. Typography-Tokens

:root {
  /* Schriftgrößen */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */

  /* Zeilenhöhen */
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.75;

  /* Schriftgewichte */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
}

4. Schatten-Tokens

:root {
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.1), 0 8px 10px rgba(0,0,0,0.04);
}

Theme-Wechsel-Mechanismus

CSS-Variablen-Ansatz

/* Helles Theme (Standard) */
:root {
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-border: #e5e7eb;
  --color-primary: #3b82f6;
}

/* Dunkles Theme */
[data-theme="dark"] {
  --color-surface: #1f2937;
  --color-text: #f9fafb;
  --color-border: #374151;
  --color-primary: #60a5fa;
}

/* High-Contrast-Theme */
[data-theme="high-contrast"] {
  --color-surface: #000000;
  --color-text: #ffffff;
  --color-border: #ffffff;
  --color-primary: #ffff00;
}

React-Theme-Wechsel

import { useEffect, useState } from 'react';

type Theme = 'light' | 'dark' | 'system';

function useTheme() {
  const [theme, setTheme] = useState<Theme>(() => {
    return (localStorage.getItem('theme') as Theme) || 'system';
  });

  useEffect(() => {
    const root = document.documentElement;
    const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
    const resolved = theme === 'system' ? (systemDark ? 'dark' : 'light') : theme;

    root.setAttribute('data-theme', resolved);
    localStorage.setItem('theme', theme);
  }, [theme]);

  return { theme, setTheme };
}

Tailwind CSS v4 Dark Mode

/* tailwind.config.ts im CSS-Variablen-Modus */
@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));
<!-- Automatisch responsiv zum Theme -->
<div class="bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100">
  Inhalt passt sich automatisch dem aktuellen Theme an
</div>

Komponenten-API-Designprinzipien

1. Einzelverantwortung + Komposition zuerst

// ❌ Überkapselung: Alle Funktionen in eine Komponente gestopft
<SuperButton variant="primary" size="lg" icon="save" loading disabled />

// ✅ Kompositionsmuster: Über Kind-Komponenten zusammenbauen
<Button variant="primary" size="lg">
  <Icon name="save" />
  <Button.Label>Speichern</Button.Label>
  <Button.Loading />
</Button>

2. Controlled vs Uncontrolled

// Controlled-Modus: Zustand extern verwaltet
<Input value={value} onChange={setValue} />

// Uncontrolled-Modus: Zustand intern von der Komponente verwaltet
<Input defaultValue="hello" onChange={handleChange} />

// Kompatibel mit beiden
interface InputProps {
  value?: string;          // Controlled
  defaultValue?: string;   // Uncontrolled
  onChange?: (value: string) => void;
}

3. Polymorphe Komponenten

// Button kann als button, a oder Next.js Link rendern
type ButtonProps<C extends React.ElementType = 'button'> = {
  as?: C;
} & React.ComponentPropsWithoutRef<C>;

function Button<C extends React.ElementType = 'button'>(
  { as, ...props }: ButtonProps<C>
) {
  const Component = as || 'button';
  return <Component className="btn" {...props} />;
}

// Verwendung
<Button>Klicken</Button>
<Button as="a" href="/link">Link</Button>
<Button as={Link} to="/page">Routen-Link</Button>

4. Slots-Muster

// Card-Komponenten-Slots-Design
interface CardSlots {
  header?: React.ReactNode;
  media?: React.ReactNode;
  content: React.ReactNode;
  footer?: React.ReactNode;
  actions?: React.ReactNode;
}

function Card({ header, media, content, footer, actions }: CardSlots) {
  return (
    <div className="card">
      {header && <div className="card-header">{header}</div>}
      {media && <div className="card-media">{media}</div>}
      <div className="card-content">{content}</div>
      {footer && <div className="card-footer">{footer}</div>}
      {actions && <div className="card-actions">{actions}</div>}
    </div>
  );
}

Multi-Brand-Anpassung

Brand-Overlay-Schicht

/* Basis-Tokens (Brand A) */
:root {
  --brand-primary: #3b82f6;
  --brand-radius: 8px;
  --brand-font: 'Inter', sans-serif;
}

/* Brand B Überschreibung */
[data-brand="b"] {
  --brand-primary: #8b5cf6;
  --brand-radius: 12px;
  --brand-font: 'Poppins', sans-serif;
}

/* Brand C Überschreibung */
[data-brand="c"] {
  --brand-primary: #f59e0b;
  --brand-radius: 4px;
  --brand-font: 'Roboto', sans-serif;
}

Token-Kompilierungs-Pipeline

Design-Quelldateien (Figma)
  ↓
Style Dictionary Kompilierung
  ↓
├── CSS-Variablen (Web)
├── Tailwind-Konfiguration (Tailwind-Projekte)
├── iOS Swift-Dateien
├── Android Kotlin-Dateien
└── JSON (Dokumentationsseite)
// style-dictionary.config.js
const StyleDictionary = require('style-dictionary');

module.exports = {
  source: ['tokens/**/*.json'],
  platforms: {
    css: {
      transformGroup: 'css',
      buildPath: 'dist/css/',
      files: [{ destination: 'variables.css', format: 'css/variables' }],
    },
    tailwind: {
      transformGroup: 'js',
      buildPath: 'dist/tailwind/',
      files: [{ destination: 'theme.js', format: 'javascript/module' }],
    },
  },
};

ToolsKus Design-System-Praktiken

ToolsKu verwendet Tailwind CSS v4 + CSS-Variablen zum Aufbau seines Design-Systems:

/* ToolsKu Theme-Tokens */
:root {
  --color-primary: #2563eb;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --radius: 8px;
  --font-sans: 'Inter', system-ui, sans-serif;
}

/* Tool-Card-Komponente */
.tool-card {
  padding: var(--space-4);
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  transition: transform 0.2s, box-shadow 0.2s;
}

.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

Design-System-Governance

Versionsverwaltung

@toolsku/tokens     v2.4.0  → Design-Token-Paket
@toolsku/components v3.1.0  → Komponentenbibliothek
@toolsku/patterns   v1.2.0  → Musterbibliothek

Abhängigkeitskette: patterns → components → tokens

Änderungs-Workflow

1. Designer ändert Tokens in Figma
2. Auto-Sync zum Git-Repository (Figma-Plugin)
3. CI führt Style-Dictionary-Kompilierung aus
4. Visuelle Regressionstests (Chromatic/Storybook)
5. Auto-Veröffentlichung neuer Version (Changesets)

Dokumentationsseite

Storybook
├── Tokens      → Farbe, Abstand, Schriftgröße-Showcase
├── Components  → Komponenten-Interaktionsdokumentation
├── Patterns    → Muster-Verwendungsleitfaden
└── Guidelines  → Design-Spezifikationsdokumentation

Zusammenfassung

Ein Design-System ist nicht nur eine Komponentenbibliothek, sondern eine vollständige Architektur von Tokens über Komponenten bis zu Mustern. Dreischichtige Tokens (Primitiv → Semantisch → Komponente) sind das Fundament der Skalierbarkeit. Kompositionsmuster schlagen Überkapselung, und CSS-Variablen + Tailwind ist die praktischste Technologieentscheidung im Jahr 2026. Denken Sie daran: Ein gutes Design-System ermöglicht Designern und Entwicklern, dieselbe Sprache zu sprechen, und Tokens sind das Vokabular dieser Sprache.

Probiere diese browser-lokalen Tools aus — keine Registrierung erforderlich →

#设计系统#Design Token#组件库#Tailwind CSS#前端架构