home / skills / hoodini / ai-agents-skills / ux-design-systems

ux-design-systems skill

/skills/ux-design-systems

This skill helps you build consistent design systems with tokens, components, and theming across projects.

npx playbooks add skill hoodini/ai-agents-skills --skill ux-design-systems

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
4.2 KB
---
name: ux-design-systems
description: Build consistent design systems with tokens, components, and theming. Use when creating component libraries, implementing design tokens, building theme systems, or ensuring design consistency. Triggers on design system, design tokens, component library, theming, dark mode.
---

# UX Design Systems

Build consistent, maintainable design systems with tokens, components, and theming.

## Design Tokens

### CSS Variables
```css
:root {
  /* Colors */
  --color-primary-50: #eff6ff;
  --color-primary-500: #3b82f6;
  --color-primary-900: #1e3a8a;
  
  /* Typography */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-4: 1rem;
  --space-8: 2rem;
  
  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}
```

### TypeScript Token System
```typescript
export const tokens = {
  colors: {
    primary: {
      50: '#eff6ff',
      500: '#3b82f6',
      900: '#1e3a8a',
    },
    gray: {
      50: '#f9fafb',
      500: '#6b7280',
      900: '#111827',
    },
  },
  spacing: {
    1: '0.25rem',
    2: '0.5rem',
    4: '1rem',
    8: '2rem',
  },
  fontSize: {
    sm: '0.875rem',
    base: '1rem',
    lg: '1.125rem',
    xl: '1.25rem',
  },
} as const;

type ColorToken = keyof typeof tokens.colors;
type SpaceToken = keyof typeof tokens.spacing;
```

## Component Patterns

### Button Component
```tsx
import { cva, type VariantProps } from 'class-variance-authority';

const buttonVariants = cva(
  'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50',
  {
    variants: {
      variant: {
        primary: 'bg-primary-500 text-white hover:bg-primary-600',
        secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200',
        outline: 'border border-gray-300 bg-transparent hover:bg-gray-50',
        ghost: 'hover:bg-gray-100',
        destructive: 'bg-red-500 text-white hover:bg-red-600',
      },
      size: {
        sm: 'h-8 px-3 text-sm',
        md: 'h-10 px-4 text-base',
        lg: 'h-12 px-6 text-lg',
      },
    },
    defaultVariants: {
      variant: 'primary',
      size: 'md',
    },
  }
);

interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof buttonVariants> {
  isLoading?: boolean;
}

export function Button({
  className,
  variant,
  size,
  isLoading,
  children,
  ...props
}: ButtonProps) {
  return (
    <button
      className={buttonVariants({ variant, size, className })}
      disabled={isLoading}
      {...props}
    >
      {isLoading && <Spinner className="mr-2 h-4 w-4" />}
      {children}
    </button>
  );
}
```

## Dark Mode

### CSS-Based Theme Switching
```css
:root {
  --bg-primary: #ffffff;
  --text-primary: #111827;
  --border-color: #e5e7eb;
}

[data-theme='dark'] {
  --bg-primary: #111827;
  --text-primary: #f9fafb;
  --border-color: #374151;
}
```

### React Theme Provider
```tsx
import { createContext, useContext, useEffect, useState } from 'react';

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

const ThemeContext = createContext<{
  theme: Theme;
  setTheme: (theme: Theme) => void;
}>({ theme: 'system', setTheme: () => {} });

export function ThemeProvider({ children }: { children: React.ReactNode }) {
  const [theme, setTheme] = useState<Theme>('system');

  useEffect(() => {
    const root = document.documentElement;
    
    if (theme === 'system') {
      const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
        ? 'dark'
        : 'light';
      root.setAttribute('data-theme', systemTheme);
    } else {
      root.setAttribute('data-theme', theme);
    }
  }, [theme]);

  return (
    <ThemeContext.Provider value={{ theme, setTheme }}>
      {children}
    </ThemeContext.Provider>
  );
}

export const useTheme = () => useContext(ThemeContext);
```

## Resources

- **Tailwind CSS**: https://tailwindcss.com
- **CVA (Class Variance Authority)**: https://cva.style

Overview

This skill helps teams build consistent, maintainable design systems with tokens, component patterns, and theming. It provides practical patterns for design tokens (CSS and TypeScript), component variants (example Button with CVA), and dark-mode theming using CSS or a React provider. Use it to accelerate component library creation and enforce UI consistency across products.

How this skill works

The skill inspects your design needs and suggests a token-first approach: centralized color, spacing, typography, radius, and shadow tokens as CSS variables or TypeScript objects. It demonstrates component patterns using class-variance-authority to define variants and sizes, and shows dark-mode handling via CSS data-attributes or a React ThemeProvider that syncs to system preferences. It returns concrete starter code and integration guidance for tokens, components, and theme switching.

When to use it

  • Creating a new component library or migrating an existing one to a token-driven system
  • Defining or normalizing design tokens (colors, spacing, typography, radius, shadows) across apps
  • Implementing variant-driven components (buttons, inputs, cards) with predictable APIs
  • Adding reliable dark-mode support that follows system preferences
  • Ensuring design consistency across teams and platforms

Best practices

  • Define a single source of truth for tokens (CSS variables + TypeScript mapping) to enable both runtime theming and compile-time checks
  • Use variant systems (CVA or similar) to encode visual variants and sizes, keeping markup simple and predictable
  • Keep tokens semantic (primary, surface, foreground) rather than purely numeric to ease theme swaps
  • Expose a compact ThemeProvider API that supports 'light', 'dark', and 'system' and persists user choice where appropriate
  • Document token usage and component variants with examples and visual snapshots to reduce integration friction

Example use cases

  • Bootstrap a new design system: export CSS variables and a typed tokens object for component libraries
  • Build a reusable Button component with variant and size props using CVA for consistent behavior
  • Implement dark mode by toggling a data-theme attribute and swapping CSS variables at runtime
  • Migrate legacy styles by mapping old values to new tokens and refactoring components incrementally
  • Provide theme-aware utilities for spacing, typography, and shadows consumed by both web and design tools

FAQ

Can I use these tokens with Tailwind?

Yes. Map token values to Tailwind config or reference CSS variables from utility classes so tokens remain the single source of truth.

How should I handle accessibility for components?

Ensure sufficient color contrast by testing token pairs, support keyboard focus states, and expose disabled/loading states in component APIs so consumers can handle interactions consistently.