JavaScript and React course ยท Module 7: Styling and Animations

Building Your Own Design Systems - Visual Architecture of the Cosmic Future

13 min read ยท
In this lesson6

On our intergalactic journey through the world of React, we have arrived at one of the most important aspects of building advanced interfaces - design systems. If component frameworks are like ready-made space stations, then design systems are like blueprints for building entire civilizations - consistent, functional, and scalable.

What is a Design System?

A design system is a collection of standards, components, and guidelines that define how user interfaces are created across an entire application or product ecosystem. It is like a building code for space stations and vehicles - ensuring that all elements fit together, creating a consistent, functional, and aesthetic whole.

A good design system includes:

  1. Design principles - fundamental values and design philosophy
  2. Component system - a reusable UI element library
  3. Design tokens - standardized values for colors, typography, spacing, etc.
  4. Interaction patterns - standard ways for users to interact with the interface
  5. Documentation - instructions and guidelines for the team

Why Create Your Own Design System?

Creating your own design system may seem like a big challenge, but it brings numerous benefits:

  • Consistency - all interface elements speak the same visual language
  • Scalability - easier application development and adding new features
  • Efficiency - faster design and implementation thanks to ready components
  • Better collaboration - shared language and standards for designers and developers
  • Brand identity - a unique and recognizable user experience

Building a Design System from Scratch

Building your own design system is like terraforming a new planet - it requires vision, planning, and a systematic approach. Let's go through the key steps of this process.

1. Defining Design Principles

Start with fundamental principles that will guide the entire system. These are like the constitution of your cosmic civilization. Example principles:

  • Simplicity - Eliminate complexity whenever possible
  • Consistency - Solve similar problems in similar ways
  • Accessibility - The interface must be usable by everyone
  • Performance - Optimize for speed and responsiveness
  • Inclusivity - Design with diverse needs in mind

2. Creating Design Tokens

Design tokens are variables that store basic stylistic values. They are like chemical elements from which your world is built.

Colors

// design-tokens.js

export const colors = {
  // Primary palette
  primary: {
    50: '#e3f2fd',
    100: '#bbdefb',
    200: '#90caf9',
    300: '#64b5f6',
    400: '#42a5f5',
    500: '#2196f3',  // Main color
    600: '#1e88e5',
    700: '#1976d2',
    800: '#1565c0',
    900: '#0d47a1',
  },

  // Semantic colors
  success: '#4caf50',
  warning: '#ff9800',
  error: '#f44336',
  info: '#2196f3',

  // Neutrals
  neutral: {
    50: '#fafafa',
    100: '#f5f5f5',
    200: '#eeeeee',
    300: '#e0e0e0',
    400: '#bdbdbd',
    500: '#9e9e9e',
    600: '#757575',
    700: '#616161',
    800: '#424242',
    900: '#212121',
  },
};

Typography

// design-tokens.js

export const typography = {
  fontFamily: {
    base: '"Inter", system-ui, -apple-system, sans-serif',
    heading: '"Space Grotesk", sans-serif',
    monospace: '"Fira Code", monospace',
  },

  fontSize: {
    xs: '0.75rem',     // 12px
    sm: '0.875rem',    // 14px
    base: '1rem',      // 16px
    lg: '1.125rem',    // 18px
    xl: '1.25rem',     // 20px
    '2xl': '1.5rem',   // 24px
    '3xl': '1.875rem', // 30px
    '4xl': '2.25rem',  // 36px
    '5xl': '3rem',     // 48px
  },

  fontWeight: {
    light: 300,
    regular: 400,
    medium: 500,
    semibold: 600,
    bold: 700,
  },

  lineHeight: {
    none: 1,
    tight: 1.25,
    snug: 1.375,
    normal: 1.5,
    relaxed: 1.625,
    loose: 2,
  },
};

Spacing

// design-tokens.js

export const spacing = {
  px: '1px',
  0: '0',
  0.5: '0.125rem',  // 2px
  1: '0.25rem',     // 4px
  1.5: '0.375rem',  // 6px
  2: '0.5rem',      // 8px
  2.5: '0.625rem',  // 10px
  3: '0.75rem',     // 12px
  3.5: '0.875rem',  // 14px
  4: '1rem',        // 16px
  5: '1.25rem',     // 20px
  6: '1.5rem',      // 24px
  8: '2rem',        // 32px
  10: '2.5rem',     // 40px
  12: '3rem',       // 48px
  16: '4rem',       // 64px
  20: '5rem',       // 80px
  24: '6rem',       // 96px
  32: '8rem',       // 128px
  40: '10rem',      // 160px
  48: '12rem',      // 192px
  56: '14rem',      // 224px
  64: '16rem',      // 256px
};

Shadows

// design-tokens.js

export const shadows = {
  sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
  md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
  lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
  xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
  '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
  inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
  outline: '0 0 0 3px rgba(66, 153, 225, 0.5)',
  none: 'none',
};

Breakpoints

// design-tokens.js

export const breakpoints = {
  xs: '0px',
  sm: '600px',
  md: '960px',
  lg: '1280px',
  xl: '1920px',
};

3. Building Atomic Components

Now let's move on to building basic, atomic components that will form the fundamental blocks of your system. This is like creating the first buildings on a new planet.

Button

import React from 'react';
import styled, { css } from 'styled-components';
import { colors, typography, spacing } from '../design-tokens';

// Define button variants
const variants = {
  primary: css`
    background-color: ${colors.primary[500]};
    color: white;

    &:hover {
      background-color: ${colors.primary[600]};
    }

    &:focus {
      box-shadow: 0 0 0 3px ${colors.primary[300]};
    }
  `,

  secondary: css`
    background-color: white;
    color: ${colors.primary[500]};
    border: 1px solid ${colors.primary[500]};

    &:hover {
      background-color: ${colors.primary[50]};
    }

    &:focus {
      box-shadow: 0 0 0 3px ${colors.primary[300]};
    }
  `,

  danger: css`
    background-color: ${colors.error};
    color: white;

    &:hover {
      background-color: #d32f2f;
    }

    &:focus {
      box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.4);
    }
  `,
};

// Define button sizes
const sizes = {
  small: css`
    padding: ${spacing[1]} ${spacing[2]};
    font-size: ${typography.fontSize.sm};
  `,

  medium: css`
    padding: ${spacing[2]} ${spacing[4]};
    font-size: ${typography.fontSize.base};
  `,

  large: css`
    padding: ${spacing[3]} ${spacing[6]};
    font-size: ${typography.fontSize.lg};
  `,
};

// Button component
const StyledButton = styled.button`
  font-family: ${typography.fontFamily.base};
  font-weight: ${typography.fontWeight.medium};
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  /* Apply variant */
  ${props => variants[props.variant || 'primary']}

  /* Apply size */
  ${props => sizes[props.size || 'medium']}
`;

const Button = ({ children, variant, size, ...rest }) => (
  <StyledButton variant={variant} size={size} {...rest}>
    {children}
  </StyledButton>
);

export default Button;

Card

import React from 'react';
import styled from 'styled-components';
import { spacing, shadows, colors } from '../design-tokens';

const StyledCard = styled.div`
  background-color: white;
  border-radius: 8px;
  box-shadow: ${shadows.md};
  overflow: hidden;
`;

const CardHeader = styled.div`
  padding: ${spacing[4]} ${spacing[4]} ${spacing[2]};
  border-bottom: 1px solid ${colors.neutral[200]};
`;

const CardTitle = styled.h3`
  margin: 0;
  font-size: ${props => props.theme.typography.fontSize.xl};
  font-weight: ${props => props.theme.typography.fontWeight.semibold};
`;

const CardSubtitle = styled.div`
  color: ${colors.neutral[600]};
  margin-top: ${spacing[1]};
`;

const CardContent = styled.div`
  padding: ${spacing[4]};
`;

const CardFooter = styled.div`
  padding: ${spacing[2]} ${spacing[4]};
  background-color: ${colors.neutral[50]};
  border-top: 1px solid ${colors.neutral[200]};
  display: flex;
  justify-content: flex-end;
`;

const Card = ({ children, ...rest }) => {
  return <StyledCard {...rest}>{children}</StyledCard>;
};

Card.Header = CardHeader;
Card.Title = CardTitle;
Card.Subtitle = CardSubtitle;
Card.Content = CardContent;
Card.Footer = CardFooter;

export default Card;

4. Building Complex Components

Once you have basic components, you can start building more complex interface elements, using atomic components as building blocks. This is like creating advanced structures after building the foundations.

Dialog

import React, { useEffect, useRef } from 'react';
import styled from 'styled-components';
import Button from './Button';
import { colors, spacing, shadows } from '../design-tokens';

const Overlay = styled.div`
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
`;

const DialogContainer = styled.div`
  background-color: white;
  border-radius: 8px;
  box-shadow: ${shadows.xl};
  width: 100%;
  max-width: ${props =>
    props.size === 'small' ? '400px' : props.size === 'large' ? '800px' : '600px'};
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
`;

const DialogHeader = styled.div`
  padding: ${spacing[4]};
  border-bottom: 1px solid ${colors.neutral[200]};
  display: flex;
  align-items: center;
  justify-content: space-between;
`;

const DialogTitle = styled.h3`
  margin: 0;
  font-weight: 600;
`;

const CloseButton = styled.button`
  background: none;
  border: none;
  cursor: pointer;
  color: ${colors.neutral[500]};
  font-size: 1.5rem;
  line-height: 1;

  &:hover {
    color: ${colors.neutral[700]};
  }
`;

const DialogContent = styled.div`
  padding: ${spacing[4]};
  flex: 1;
`;

const DialogFooter = styled.div`
  padding: ${spacing[3]} ${spacing[4]};
  border-top: 1px solid ${colors.neutral[200]};
  display: flex;
  justify-content: flex-end;
  gap: ${spacing[2]};
`;

const Dialog = ({
  isOpen,
  onClose,
  title,
  children,
  size = 'medium',
  confirmText = 'Confirm',
  cancelText = 'Cancel',
  onConfirm,
  hideActions = false
}) => {
  const dialogRef = useRef(null);

  // Close dialog on ESC key press
  useEffect(() => {
    const handleKeyDown = (e) => {
      if (e.key === 'Escape') {
        onClose();
      }
    };

    if (isOpen) {
      window.addEventListener('keydown', handleKeyDown);
    }

    return () => {
      window.removeEventListener('keydown', handleKeyDown);
    };
  }, [isOpen, onClose]);

  // Stop click propagation inside dialog
  const handleDialogClick = (e) => {
    e.stopPropagation();
  };

  if (!isOpen) return null;

  return (
    <Overlay onClick={onClose}>
      <DialogContainer size={size} onClick={handleDialogClick} ref={dialogRef}>
        <DialogHeader>
          <DialogTitle>{title}</DialogTitle>
          <CloseButton onClick={onClose}>&times;</CloseButton>
        </DialogHeader>
        <DialogContent>{children}</DialogContent>
        {!hideActions && (
          <DialogFooter>
            <Button variant="secondary" onClick={onClose}>
              {cancelText}
            </Button>
            {onConfirm && (
              <Button variant="primary" onClick={onConfirm}>
                {confirmText}
              </Button>
            )}
          </DialogFooter>
        )}
      </DialogContainer>
    </Overlay>
  );
};

export default Dialog;

5. Implementing Interaction Patterns

Interaction patterns are standard ways in which users interact with the interface. Here is an example of implementing the "Notification" (Toast) pattern:

import React, { useState, useEffect } from 'react';
import styled, { css, keyframes } from 'styled-components';
import { colors, spacing, shadows } from '../design-tokens';

// Entry animation
const slideIn = keyframes`
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
`;

// Exit animation
const slideOut = keyframes`
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
`;

// Different notification types
const toastTypes = {
  success: css`
    background-color: ${colors.success};
    color: white;
  `,
  error: css`
    background-color: ${colors.error};
    color: white;
  `,
  warning: css`
    background-color: ${colors.warning};
    color: white;
  `,
  info: css`
    background-color: ${colors.info};
    color: white;
  `,
};

const ToastContainer = styled.div`
  position: fixed;
  top: ${spacing[4]};
  right: ${spacing[4]};
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: ${spacing[2]};
`;

const Toast = styled.div`
  min-width: 300px;
  max-width: 400px;
  padding: ${spacing[3]};
  border-radius: 4px;
  box-shadow: ${shadows.lg};
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: ${props => (props.leaving ? slideOut : slideIn)} 0.3s ease-in-out forwards;

  ${props => toastTypes[props.type || 'info']}
`;

const CloseButton = styled.button`
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 1.25rem;

  &:hover {
    opacity: 1;
  }
`;

// Context for notifications
const ToastContext = React.createContext();

// Notification provider
export const ToastProvider = ({ children }) => {
  const [toasts, setToasts] = useState([]);

  const addToast = (message, type = 'info', duration = 5000) => {
    const id = Date.now();
    setToasts(prev => [...prev, { id, message, type, duration }]);

    if (duration !== Infinity) {
      setTimeout(() => removeToast(id), duration);
    }

    return id;
  };

  const removeToast = (id) => {
    setToasts(prev => {
      const toast = prev.find(t => t.id === id);
      if (toast) {
        // Mark the toast as leaving
        return prev.map(t => t.id === id ? { ...t, leaving: true } : t);
      }
      return prev;
    });

    // Remove toast after animation ends
    setTimeout(() => {
      setToasts(prev => prev.filter(t => t.id !== id));
    }, 300); // Animation duration
  };

  return (
    <ToastContext.Provider value={{ addToast, removeToast }}>
      {children}
      <ToastContainer>
        {toasts.map(toast => (
          <Toast key={toast.id} type={toast.type} leaving={toast.leaving}>
            <span>{toast.message}</span>
            <CloseButton onClick={() => removeToast(toast.id)}>&times;</CloseButton>
          </Toast>
        ))}
      </ToastContainer>
    </ToastContext.Provider>
  );
};

// Hook for using notifications
export const useToast = () => {
  const context = React.useContext(ToastContext);
  if (!context) {
    throw new Error('useToast must be used within a ToastProvider');
  }
  return context;
};

// Usage example:
// const { addToast } = useToast();
// addToast('Operation completed successfully!', 'success');

6. Design System Documentation

The last but no less important step is creating documentation that allows other developers and designers to use your design system. Popular tools for creating documentation include:

  • Storybook - interactive component documentation
  • Docusaurus - documentation site generator
  • Docz - a tool dedicated to React component documentation

Example of a component configuration in Storybook:

// Button.stories.js

import React from 'react';
import Button from './Button';

export default {
  title: 'Atoms/Button',
  component: Button,
  argTypes: {
    variant: {
      control: { type: 'select', options: ['primary', 'secondary', 'danger'] },
      description: 'Button variant determining its style and purpose',
      table: {
        type: { summary: 'string' },
        defaultValue: { summary: 'primary' },
      },
    },
    size: {
      control: { type: 'select', options: ['small', 'medium', 'large'] },
      description: 'Button size',
      table: {
        type: { summary: 'string' },
        defaultValue: { summary: 'medium' },
      },
    },
    disabled: {
      control: 'boolean',
      description: 'Whether the button is disabled',
      table: {
        type: { summary: 'boolean' },
        defaultValue: { summary: false },
      },
    },
  },
};

// Basic usage
export const Primary = () => <Button variant="primary">Primary button</Button>;

// Variants
export const Variants = () => (
  <div style={{ display: 'flex', gap: '8px' }}>
    <Button variant="primary">Primary</Button>
    <Button variant="secondary">Secondary</Button>
    <Button variant="danger">Danger</Button>
  </div>
);

// Sizes
export const Sizes = () => (
  <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
    <Button size="small">Small</Button>
    <Button size="medium">Medium</Button>
    <Button size="large">Large</Button>
  </div>
);

// Disabled state
export const Disabled = () => <Button disabled>Disabled button</Button>;

Design System Implementation Strategies

Implementing a design system in an existing project is like modernizing a working space station - it requires planning and a gradual approach:

  1. Incremental implementation - start with small, isolated components
  2. Parallel development - first build the system in a separate branch or project
  3. Page-by-page migration - migrate one page or section at a time
  4. Component by component - replace old components with new ones one by one

Best Practices for Creating Design Systems

  • Start with research - analyze competitors and proven patterns
  • Collaborate from the start - involve designers and developers
  • Think systemically - design a system, not individual screens
  • Test early and often - gather feedback from users
  • Document everything - not just code, but also decisions and justifications
  • Evolve, don't revolutionize - a design system should be a living, evolving entity

Practical Exercise: Create a Micro Design System for a Space Application

Design and implement a small design system for a cosmic mission monitoring application. Your system should contain:

  1. Design tokens - define basic variables for colors, typography, and spacing
  2. Atomic components - create at least 3 basic components (e.g., Button, Card, Input)
  3. One complex component - use atomic components to create a more complex component (e.g., Dashboard Card, Mission Status)
  4. Documentation - describe your system and components

Remember that a good design system is not just about aesthetics, but above all about functionality, consistency, and ease of use. Create the system with future application development in mind.

When you create your own design system, you become not only a programmer but also an architect of the cosmic future of interfaces. Like the creators of the first colonies on other planets, you are building the foundations upon which future generations of developers and users will build.

Code for this lesson: App.jsx
import React, { useState } from 'react';
import styled, { ThemeProvider, createGlobalStyle } from 'styled-components';

// ===== DESIGN TOKENS =====
// Design tokens are variables storing base style values
const tokens = {
  colors: {
    primary: '#6c5ce7',
    primaryLight: '#a29bfe',
    secondary: '#00cec9',
    success: '#00b894',
    warning: '#fdcb6e',
    danger: '#d63031',
    text: '#2d3436',
    textLight: '#636e72',
    background: '#f8f9fa',
    surface: '#ffffff',
    border: '#dfe6e9',
  },
  spacing: {
    xs: '4px',
    sm: '8px',
    md: '16px',
    lg: '24px',
    xl: '32px',
    xxl: '48px',
  },
  radius: {
    sm: '4px',
    md: '8px',
    lg: '16px',
    full: '9999px',
  },
  fontSize: {
    xs: '0.75rem',
    sm: '0.875rem',
    base: '1rem',
    lg: '1.125rem',
    xl: '1.5rem',
    xxl: '2rem',
  },
  fontWeight: {
    normal: 400,
    medium: 500,
    semibold: 600,
    bold: 700,
  },
  shadows: {
    sm: '0 1px 3px rgba(0,0,0,0.12)',
    md: '0 4px 6px rgba(0,0,0,0.1)',
    lg: '0 10px 25px rgba(0,0,0,0.15)',
  },
};

// ===== GLOBAL STYLES =====
const GlobalStyle = createGlobalStyle`
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: ${tokens.colors.background};
    color: ${tokens.colors.text};
  }
`;

// ===== COMPONENT: BUTTON =====
// Button with variants: primary, secondary, danger
const Button = styled.button`
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: ${tokens.spacing.sm} ${tokens.spacing.lg};
  font-size: ${tokens.fontSize.sm};
  font-weight: ${tokens.fontWeight.semibold};
  border-radius: ${tokens.radius.md};
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;

  background: ${p => {
    if (p.variant === 'secondary') return 'transparent';
    if (p.variant === 'danger') return tokens.colors.danger;
    return tokens.colors.primary;
  }};

  color: ${p => {
    if (p.variant === 'secondary') return tokens.colors.primary;
    return '#ffffff';
  }};

  border-color: ${p => {
    if (p.variant === 'secondary') return tokens.colors.primary;
    return 'transparent';
  }};

  &:hover {
    transform: translateY(-2px);
    box-shadow: ${tokens.shadows.md};
    opacity: 0.9;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
  }
`;

// ===== COMPONENT: CARD =====
const Card = styled.div`
  background: ${tokens.colors.surface};
  border-radius: ${tokens.radius.lg};
  padding: ${tokens.spacing.lg};
  box-shadow: ${tokens.shadows.sm};
  border: 1px solid ${tokens.colors.border};
  transition: all 0.3s ease;

  &:hover {
    box-shadow: ${tokens.shadows.lg};
    transform: translateY(-4px);
  }
`;

// ===== COMPONENT: INPUT =====
const Input = styled.input`
  width: 100%;
  padding: ${tokens.spacing.sm} ${tokens.spacing.md};
  font-size: ${tokens.fontSize.base};
  border: 2px solid ${tokens.colors.border};
  border-radius: ${tokens.radius.md};
  background: ${tokens.colors.surface};
  color: ${tokens.colors.text};
  transition: border-color 0.2s ease;
  outline: none;

  &:focus {
    border-color: ${tokens.colors.primary};
    box-shadow: 0 0 0 3px ${tokens.colors.primaryLight}40;
  }

  &::placeholder {
    color: ${tokens.colors.textLight};
  }
`;

// TODO: Create a Badge component with variants
// Badge should display small status labels
// Warianty: success, warning, danger
// Use tokens from the tokens object
const Badge = styled.span`
  display: inline-block;
  padding: 2px ${tokens.spacing.sm};
  font-size: ${tokens.fontSize.xs};
  font-weight: ${tokens.fontWeight.bold};
  border-radius: ${tokens.radius.full};
  /* TODO: Add a dynamic background color based on props.variant */
  /* Use tokens.colors[props.variant] with 20% opacity */
  /* e.g. success -> green background, warning -> yellow background */
  background: ${p => (tokens.colors[p.variant] || tokens.colors.primary) + '33'};
  color: ${p => tokens.colors[p.variant] || tokens.colors.primary};
`;

// TODO: Create an Alert component for displaying messages
// Alert should have variants: success, warning, danger
// Use spacing, colors, and radius tokens
const Alert = styled.div`
  padding: ${tokens.spacing.md};
  border-radius: ${tokens.radius.md};
  margin-bottom: ${tokens.spacing.md};
  border-left: 4px solid ${p => tokens.colors[p.variant] || tokens.colors.primary};
  /* TODO: Add a background with slight transparency of the variant color */
  background: ${p => (tokens.colors[p.variant] || tokens.colors.primary) + '15'};
  color: ${tokens.colors.text};
`;

// ===== LAYOUT =====
const Container = styled.div`
  max-width: 700px;
  margin: 0 auto;
  padding: ${tokens.spacing.xl};
`;

const Title = styled.h1`
  font-size: ${tokens.fontSize.xxl};
  font-weight: ${tokens.fontWeight.bold};
  color: ${tokens.colors.primary};
  text-align: center;
  margin-bottom: ${tokens.spacing.xs};
`;

const Subtitle = styled.p`
  text-align: center;
  color: ${tokens.colors.textLight};
  margin-bottom: ${tokens.spacing.xl};
`;

const Section = styled.div`
  margin-bottom: ${tokens.spacing.xl};
`;

const SectionTitle = styled.h2`
  font-size: ${tokens.fontSize.lg};
  margin-bottom: ${tokens.spacing.md};
  color: ${tokens.colors.text};
`;

const ButtonGroup = styled.div`
  display: flex;
  gap: ${tokens.spacing.sm};
  flex-wrap: wrap;
`;

const Grid = styled.div`
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: ${tokens.spacing.md};
`;

// ===== APPLICATION =====
function DesignSystemDemo() {
  const [inputValue, setInputValue] = useState('');

  return (
    <>
      <GlobalStyle />
      <Container>
        <Title>Space Design System</Title>
        <Subtitle>A consistent set of UI components</Subtitle>

        {/* Section: Alerts */}
        <Section>
          <SectionTitle>Alerts</SectionTitle>
          <Alert variant="success">Mission completed successfully!</Alert>
          <Alert variant="warning">Low fuel level</Alert>
          <Alert variant="danger">Gravitational anomaly detected</Alert>
        </Section>

        {/* Section: Buttons */}
        <Section>
          <SectionTitle>Buttons</SectionTitle>
          <ButtonGroup>
            <Button>Primary</Button>
            <Button variant="secondary">Secondary</Button>
            <Button variant="danger">Danger</Button>
            <Button disabled>Disabled</Button>
          </ButtonGroup>
        </Section>

        {/* Section: Badge */}
        <Section>
          <SectionTitle>Badge</SectionTitle>
          <ButtonGroup>
            <Badge variant="success">Online</Badge>
            <Badge variant="warning">Standby</Badge>
            <Badge variant="danger">Offline</Badge>
            <Badge>Default</Badge>
          </ButtonGroup>
        </Section>

        {/* Section: Input */}
        <Section>
          <SectionTitle>Input</SectionTitle>
          <Input
            placeholder="Enter target coordinates..."
            value={inputValue}
            onChange={e => setInputValue(e.target.value)}
          />
        </Section>

        {/* Section: Cards */}
        <Section>
          <SectionTitle>Cards</SectionTitle>
          <Grid>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Navigation</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                Space navigation system
              </p>
              <Badge variant="success">Active</Badge>
            </Card>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Engines</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                Warp drive propulsion
              </p>
              <Badge variant="warning">Standby</Badge>
            </Card>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Shields</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                Electromagnetic shields
              </p>
              <Badge variant="danger">Offline</Badge>
            </Card>
          </Grid>
        </Section>
      </Container>
    </>
  );
}

export default DesignSystemDemo;

Docs entries used in this lesson

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What is the foundation (base) of every design system?

  2. 2. Which browser tool lets you see the final (computed) styles applied to an HTML element?

These are 2 of 3 questions for this lesson. Solve the rest in the game.

  1. QuestionDesign System Foundation
  2. QuestionDebugging CSS in the Browser
  3. QuestionBrowser Compatibility Strategy

Useful articles