Kurs JavaScript i React · Moduł 7: Stylowanie i animacje

Tworzenie własnych systemów design - Architektura wizualna kosmicznej przyszłości

12 min czytania ·
W tej lekcji6

W naszej międzygalaktycznej podróży przez świat Reacta, dotarliśmy do jednego z najważniejszych aspektów budowania zaawansowanych interfejsów - systemów design. Jeśli frameworki komponentów są jak gotowe stacje kosmiczne, to systemy design są jak plany do budowy całych cywilizacji - spójnych, funkcjonalnych i skalowalnych.

Czym jest system design?

System design (system projektowy) to zbiór standardów, komponentów i wytycznych, które definiują sposób tworzenia interfejsów użytkownika w całej aplikacji lub ekosystemie produktów. To jak kodeks budowlany dla kosmicznych stacji i pojazdów - zapewnia, że wszystkie elementy pasują do siebie, tworząc spójną, funkcjonalną i estetyczną całość.

Dobry system design obejmuje:

  1. Zasady projektowe - fundamentalne wartości i filozofia designu
  2. System komponentów - biblioteka wielokrotnego użytku elementów UI
  3. Tokeny designu - standaryzowane wartości dla kolorów, typografii, odstępów itp.
  4. Wzorce interakcji - standardowe sposoby interakcji użytkownika z interfejsem
  5. Dokumentację - instrukcje i wytyczne dla zespołu

Dlaczego warto tworzyć własny system design?

Tworzenie własnego systemu design może wydawać się dużym wyzwaniem, ale przynosi liczne korzyści:

  • Spójność - wszystkie elementy interfejsu mówią tym samym wizualnym językiem
  • Skalowalność - łatwiejsze rozwijanie aplikacji i dodawanie nowych funkcji
  • Efektywność - szybsze projektowanie i implementacja dzięki gotowym komponentom
  • Lepsza współpraca - wspólny język i standardy dla projektantów i deweloperów
  • Tożsamość marki - unikalne i rozpoznawalne doświadczenie użytkownika

Budowanie systemu design od podstaw

Zbudowanie własnego systemu design jest jak terraformowanie nowej planety - wymaga wizji, planowania i systematycznego podejścia. Przejdźmy przez kluczowe kroki tego procesu.

1. Definiowanie zasad projektowych

Zacznij od fundamentalnych zasad, które będą kierować całym systemem. To jak konstytucja twojej kosmicznej cywilizacji. Przykładowe zasady:

  • Prostota - Eliminuj złożoność, gdy tylko to możliwe
  • Spójność - Podobne problemy rozwiązuj w podobny sposób
  • Dostępność - Interfejs musi być użyteczny dla wszystkich
  • Wydajność - Optymalizuj dla szybkości i responsywności
  • Inkluzywność - Projektuj z myślą o różnorodnych potrzebach

2. Tworzenie tokenów designu

Tokeny designu to zmienne, które przechowują podstawowe wartości stylistyczne. To jak pierwiastki chemiczne, z których zbudowany jest twój świat.

Kolory

// design-tokens.js

export const colors = {
  // Podstawowa paleta
  primary: {
    50: '#e3f2fd',
    100: '#bbdefb',
    200: '#90caf9',
    300: '#64b5f6',
    400: '#42a5f5',
    500: '#2196f3',  // Główny kolor
    600: '#1e88e5',
    700: '#1976d2',
    800: '#1565c0',
    900: '#0d47a1',
  },

  // Kolory semantyczne
  success: '#4caf50',
  warning: '#ff9800',
  error: '#f44336',
  info: '#2196f3',

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

Typografia

// 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,
  },
};

Przestrzeń

// 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
};

Cienie

// 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',
};

Breakpointy

// design-tokens.js

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

3. Budowanie atomowych komponentów

Teraz przejdźmy do budowania podstawowych, atomowych komponentów, które będą stanowić fundamentalne bloki twojego systemu. To jak tworzenie pierwszych budynków na nowej planecie.

Przycisk (Button)

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

// Definiujemy warianty przycisku
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);
    }
  `,
};

// Definiujemy rozmiary przycisków
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};
  `,
};

// Komponent przycisku
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;
  }

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

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

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

export default Button;

Karta (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. Budowanie złożonych komponentów

Gdy masz już podstawowe komponenty, możesz zacząć budować bardziej złożone elementy interfejsu, wykorzystując atomowe komponenty jako budulce. To jak tworzenie zaawansowanych struktur po zbudowaniu fundamentów.

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 = 'Potwierdź',
  cancelText = 'Anuluj',
  onConfirm,
  hideActions = false
}) => {
  const dialogRef = useRef(null);

  // Zamykanie dialogu po kliknięciu ESC
  useEffect(() => {
    const handleKeyDown = (e) => {
      if (e.key === 'Escape') {
        onClose();
      }
    };

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

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

  // Zatrzymanie propagacji kliknięcia wewnątrz dialogu
  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. Implementacja wzorców interakcji

Wzorce interakcji to standardowe sposoby, w jakie użytkownicy wchodzą w interakcję z interfejsem. Oto przykład implementacji wzorca "Powiadomienia" (Toast):

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

// Animacja wejścia
const slideIn = keyframes`
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
`;

// Animacja wyjścia
const slideOut = keyframes`
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
`;

// Różne typy powiadomień
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;
  }
`;

// Kontekst dla powiadomień
const ToastContext = React.createContext();

// Provider powiadomień
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) {
        // Oznaczenie tosta jako wychodzącego
        return prev.map(t => t.id === id ? { ...t, leaving: true } : t);
      }
      return prev;
    });

    // Usuń toast po zakończeniu animacji
    setTimeout(() => {
      setToasts(prev => prev.filter(t => t.id !== id));
    }, 300); // Czas trwania animacji
  };

  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 do używania powiadomień
export const useToast = () => {
  const context = React.useContext(ToastContext);
  if (!context) {
    throw new Error('useToast must be used within a ToastProvider');
  }
  return context;
};

// Przykład użycia:
// const { addToast } = useToast();
// addToast('Operacja zakończona sukcesem!', 'success');

6. Dokumentacja systemu design

Ostatnim, ale nie mniej ważnym krokiem, jest stworzenie dokumentacji, która pozwoli innym deweloperom i projektantom korzystać z twojego systemu design. Popularnymi narzędziami do tworzenia dokumentacji są:

  • Storybook - interaktywna dokumentacja komponentów
  • Docusaurus - generator stron dokumentacji
  • Docz - narzędzie dedykowane do dokumentacji komponentów React

Przykład konfiguracji komponentu w 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: 'Wariant przycisku określający jego styl i przeznaczenie',
      table: {
        type: { summary: 'string' },
        defaultValue: { summary: 'primary' },
      },
    },
    size: {
      control: { type: 'select', options: ['small', 'medium', 'large'] },
      description: 'Rozmiar przycisku',
      table: {
        type: { summary: 'string' },
        defaultValue: { summary: 'medium' },
      },
    },
    disabled: {
      control: 'boolean',
      description: 'Czy przycisk jest wyłączony',
      table: {
        type: { summary: 'boolean' },
        defaultValue: { summary: false },
      },
    },
  },
};

// Podstawowe użycie
export const Primary = () => <Button variant="primary">Przycisk główny</Button>;

// Warianty
export const Variants = () => (
  <div style={{ display: 'flex', gap: '8px' }}>
    <Button variant="primary">Główny</Button>
    <Button variant="secondary">Drugorzędny</Button>
    <Button variant="danger">Niebezpieczny</Button>
  </div>
);

// Rozmiary
export const Sizes = () => (
  <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
    <Button size="small">Mały</Button>
    <Button size="medium">Średni</Button>
    <Button size="large">Duży</Button>
  </div>
);

// Stan wyłączony
export const Disabled = () => <Button disabled>Przycisk wyłączony</Button>;

Strategie wdrażania systemu design

Wdrożenie systemu design w istniejącym projekcie to jak modernizacja działającej stacji kosmicznej - wymaga planowania i stopniowego podejścia:

  1. Inkrementalne wdrażanie - zacznij od małych, izolowanych komponentów
  2. Równoległy rozwój - najpierw zbuduj system w oddzielnej gałęzi lub projekcie
  3. Migracja stronami - migruj jedną stronę lub sekcję na raz
  4. Komponent po komponencie - zastępuj stare komponenty nowymi jeden po drugim

Najlepsze praktyki w tworzeniu systemów design

  • Zacznij od badań - analizuj konkurencję i sprawdzone wzorce
  • Współpracuj od początku - włącz projektantów i deweloperów
  • Myśl systemowo - projektuj system, a nie pojedyncze ekrany
  • Testuj wcześnie i często - zbieraj feedback od użytkowników
  • Dokumentuj wszystko - nie tylko kod, ale też decyzje i uzasadnienia
  • Ewoluuj, nie rewolucjonizuj - system design powinien być żywym, ewoluującym bytem

Zadanie praktyczne: Stwórz mikro-system design dla aplikacji kosmicznej

Zaprojektuj i zaimplementuj mały system design dla aplikacji do monitorowania kosmicznych misji. Twój system powinien zawierać:

  1. Tokeny designu - zdefiniuj podstawowe zmienne dla kolorów, typografii i odstępów
  2. Komponenty atomowe - stwórz przynajmniej 3 podstawowe komponenty (np. Button, Card, Input)
  3. Jeden złożony komponent - wykorzystaj komponenty atomowe do stworzenia bardziej złożonego komponentu (np. Dashboard Card, Mission Status)
  4. Dokumentację - opisz swój system i komponenty

Pamiętaj, że dobry system design to nie tylko estetyka, ale przede wszystkim funkcjonalność, spójność i łatwość użycia. Twórz system z myślą o rozwoju aplikacji w przyszłości.

Gdy tworzysz własny system design, stajesz się nie tylko programistą, ale również architektem kosmicznej przyszłości interfejsów. Podobnie jak twórcy pierwszych kolonii na innych planetach, tworzysz fundamenty, na których będą budować przyszłe pokolenia deweloperów i użytkowników.

Kod do tej lekcji: App.jsx
import React, { useState } from 'react';
import styled, { ThemeProvider, createGlobalStyle } from 'styled-components';

// ===== DESIGN TOKENS =====
// Tokeny designu to zmienne przechowujące podstawowe wartości stylistyczne
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};
  }
`;

// ===== KOMPONENT: BUTTON =====
// Przycisk z wariantami: 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;
  }
`;

// ===== KOMPONENT: 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);
  }
`;

// ===== KOMPONENT: 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: Stwórz komponent Badge z wariantami
// Badge powinien wyświetlać małe etykiety statusu
// Warianty: success, warning, danger
// Użyj tokenów z obiektu tokens
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: Dodaj dynamiczny kolor tła na podstawie props.variant */
  /* Użyj tokens.colors[props.variant] z opacity 20% */
  /* np. success -> zielone tło, warning -> żółte tło */
  background: ${p => (tokens.colors[p.variant] || tokens.colors.primary) + '33'};
  color: ${p => tokens.colors[p.variant] || tokens.colors.primary};
`;

// TODO: Stwórz komponent Alert do wyświetlania komunikatów
// Alert powinien mieć warianty: success, warning, danger
// Użyj tokenów spacing, colors i radius
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: Dodaj tło z lekką przezroczystością koloru wariantu */
  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};
`;

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

  return (
    <>
      <GlobalStyle />
      <Container>
        <Title>Kosmiczny Design System</Title>
        <Subtitle>Spójny zestaw komponentów UI</Subtitle>

        {/* Sekcja: Alerty */}
        <Section>
          <SectionTitle>Alerty</SectionTitle>
          <Alert variant="success">Misja zakończona sukcesem!</Alert>
          <Alert variant="warning">Niski poziom paliwa</Alert>
          <Alert variant="danger">Wykryto anomalię grawitacyjną</Alert>
        </Section>

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

        {/* Sekcja: 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>

        {/* Sekcja: Input */}
        <Section>
          <SectionTitle>Input</SectionTitle>
          <Input
            placeholder="Wpisz współrzędne celu..."
            value={inputValue}
            onChange={e => setInputValue(e.target.value)}
          />
        </Section>

        {/* Sekcja: Karty */}
        <Section>
          <SectionTitle>Karty</SectionTitle>
          <Grid>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Nawigacja</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                System nawigacji kosmicznej
              </p>
              <Badge variant="success">Active</Badge>
            </Card>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Silniki</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                Napęd warp drive
              </p>
              <Badge variant="warning">Standby</Badge>
            </Card>
            <Card>
              <h3 style={{ marginBottom: 8 }}>Tarcze</h3>
              <p style={{ color: tokens.colors.textLight, fontSize: 14, marginBottom: 12 }}>
                Osłony elektromagnetyczne
              </p>
              <Badge variant="danger">Offline</Badge>
            </Card>
          </Grid>
        </Section>
      </Container>
    </>
  );
}

export default DesignSystemDemo;

Hasła z dokumentacji w tej lekcji

Widzisz błąd w tej lekcji?

Sprawdź się

Odpowiedz na pytania z tej lekcji. Wybierz odpowiedź, a od razu zobaczysz, czy jest poprawna.

  1. 1. Co stanowi fundament (bazę) każdego design systemu?

  2. 2. Które narzędzie przeglądarki pozwala zobaczyć końcowe (computed) style zastosowane do elementu HTML?

To 2 z 3 pytań do tej lekcji. Pozostałe rozwiążesz w grze.

  1. PytanieFundament design systemu
  2. PytanieDebugowanie CSS w przeglądarce
  3. PytanieStrategia kompatybilności przeglądarek

Przydatne artykuły