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

Project: Cosmic Mission Control Panel

4 min read ยท
In this lesson4

Congratulations, Navigator! You have reached the end of this module and it is time to combine all the styling techniques you have learned into one comprehensive project. Your task is to create a Cosmic Mission Control Panel - an interactive dashboard that utilizes knowledge from the entire module.

Project Goal

You will build a spaceship control panel that combines:

  • Styled Components with dynamic theming
  • CSS Animations with @keyframes
  • Responsive layout with CSS Grid and Flexbox
  • Theming (light/dark mode)
  • Interactive elements with hover effects and transitions

Project Architecture

The project consists of several key sections:

1. Theme System (Theming)

We use ThemeProvider from styled-components to manage colors and styles across the entire application:

const darkTheme = {
  bg: '#0a0a1a',
  surface: '#12122a',
  accent: '#00ff88',
  text: '#e0e0e0',
  danger: '#ff4444',
  warning: '#ffaa00'
};

const lightTheme = {
  bg: '#f0f4f8',
  surface: '#ffffff',
  accent: '#0066ff',
  text: '#1a1a2e',
  danger: '#cc0000',
  warning: '#cc8800'
};

2. CSS Animations

The panel uses several types of animations you learned in the module:

/* Status pulsing */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Slide in with offset */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Radar rotation */
@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

3. Styled Components with Props

Dynamic component styling based on passed props:

const StatusBadge = styled.span`
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
  background: ${props => props.active ? '#00ff8833' : '#ff444433'};
  color: ${props => props.active ? '#00ff88' : '#ff4444'};
  animation: pulse 2s infinite;
`;

const Card = styled.div`
  background: ${props => props.theme.surface};
  border: 1px solid ${props => props.theme.accent}33;
  border-radius: 12px;
  padding: 20px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 255, 136, 0.15);
  }
`;

4. Responsive Layout with CSS Grid

The panel automatically adapts to the screen width:

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  padding: 20px;
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

5. Complete Component Structure

The main App component brings all elements together:

function App() {
  const [isDark, setIsDark] = useState(true);

  return (
    <ThemeProvider theme={isDark ? darkTheme : lightTheme}>
      <GlobalStyle />
      <Header>
        <Title>Mission Control</Title>
        <ThemeToggle onClick={() => setIsDark(!isDark)}>
          {isDark ? 'Light' : 'Dark'}
        </ThemeToggle>
      </Header>
      <DashboardGrid>
        <StatusCard systems={systemsData} />
        <RadarCard />
        <MissionsCard missions={missionsData} />
        <CrewCard crew={crewData} />
      </DashboardGrid>
    </ThemeProvider>
  );
}

Key Techniques Used in the Project

TechniqueUsage in Project
Styled ComponentsAll UI components
ThemeProviderSwitching dark/light mode
@keyframesStatus pulsing, radar rotation, card entry
CSS GridDashboard layout
FlexboxInternal card layout
transitionHover effects on cards and buttons
Dynamic propsStatus colors, conditional styles
Responsivenessauto-fit and minmax in grid

Module Summary

In this module, you learned the full spectrum of styling techniques in React:

  1. Classic CSS and CSS Modules - the foundation of styling with class isolation
  2. Styled Components - CSS-in-JS with dynamic props and theming
  3. SCSS - preprocessor with variables, mixins, and nesting
  4. Tailwind CSS - utility-first approach for fast prototyping
  5. UI Frameworks - ready component libraries (MUI, Ant Design, Chakra)
  6. Design Systems - building consistent design systems
  7. React Transition Group - animating component lifecycle
  8. CSS Animations - @keyframes, transition, and advanced effects

Each of these techniques has its place in the arsenal of a cosmic programmer. The best engineers know how to combine them into a coherent system - exactly as in this project.

Try the panel below and experiment with the code - change the theme colors, add new animations, or expand the dashboard sections!

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

// ===== THEMES =====
const darkTheme = {
  bg: '#0a0a1a',
  surface: '#12122a',
  surfaceHover: '#1a1a3a',
  accent: '#00ff88',
  accentDim: 'rgba(0,255,136,0.15)',
  text: '#e0e0e0',
  textSecondary: '#8888aa',
  danger: '#ff4444',
  warning: '#ffaa00',
  border: 'rgba(0,255,136,0.2)',
};

const lightTheme = {
  bg: '#f0f4f8',
  surface: '#ffffff',
  surfaceHover: '#e8ecf0',
  accent: '#0066ff',
  accentDim: 'rgba(0,102,255,0.1)',
  text: '#1a1a2e',
  textSecondary: '#666688',
  danger: '#cc0000',
  warning: '#cc8800',
  border: 'rgba(0,102,255,0.2)',
};

// ===== GLOBAL STYLES =====
const GlobalStyle = createGlobalStyle`
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: ${props => props.theme.bg};
    color: ${props => props.theme.text};
    transition: background 0.3s ease, color 0.3s ease;
  }
`;

// ===== ANIMATIONS =====
const pulse = keyframes`
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
`;

const slideIn = keyframes`
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
`;

const rotate = keyframes`
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
`;

const glow = keyframes`
  0%, 100% { box-shadow: 0 0 5px ${() => 'rgba(0,255,136,0.3)'}; }
  50% { box-shadow: 0 0 20px ${() => 'rgba(0,255,136,0.6)'}; }
`;

// ===== LAYOUT COMPONENTS =====
const Header = styled.header`
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: ${p => p.theme.surface};
  border-bottom: 1px solid ${p => p.theme.border};
`;

const Title = styled.h1`
  font-size: 20px;
  color: ${p => p.theme.accent};
  letter-spacing: 2px;
  text-transform: uppercase;
`;

const ThemeToggle = styled.button`
  background: ${p => p.theme.accentDim};
  border: 1px solid ${p => p.theme.accent};
  color: ${p => p.theme.accent};
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
  &:hover {
    background: ${p => p.theme.accent};
    color: ${p => p.theme.bg};
  }
`;

const DashboardGrid = styled.div`
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  padding: 24px;
`;

const Card = styled.div`
  background: ${p => p.theme.surface};
  border: 1px solid ${p => p.theme.border};
  border-radius: 12px;
  padding: 20px;
  animation: ${slideIn} 0.5s ease ${p => p.delay || '0s'} both;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px ${p => p.theme.accentDim};
  }
`;

const CardTitle = styled.h3`
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: ${p => p.theme.accent};
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
`;

// ===== STATUS COMPONENTS =====
const StatusBadge = styled.span`
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
  background: ${p => p.active ? 'rgba(0,255,136,0.15)' : 'rgba(255,68,68,0.15)'};
  color: ${p => p.active ? '#00ff88' : '#ff4444'};
  animation: ${pulse} 2s infinite;
`;

const SystemRow = styled.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid ${p => p.theme.border};
  &:last-child { border-bottom: none; }
`;

// ===== RADAR COMPONENTS =====
const RadarWrapper = styled.div`
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid ${p => p.theme.accent};
  position: relative;
  margin: 0 auto 16px;
  overflow: hidden;
  background: radial-gradient(circle, ${p => p.theme.accentDim} 0%, transparent 70%);
`;

const RadarSweep = styled.div`
  position: absolute;
  top: 0; left: 50%;
  width: 2px; height: 50%;
  background: ${p => p.theme.accent};
  transform-origin: bottom center;
  animation: ${rotate} 3s linear infinite;
`;

const RadarDot = styled.div`
  position: absolute;
  width: 6px; height: 6px;
  background: ${p => p.theme.accent};
  border-radius: 50%;
  top: ${p => p.y}%;
  left: ${p => p.x}%;
  animation: ${pulse} 1.5s infinite;
`;

// ===== PROGRESS BAR =====
const ProgressOuter = styled.div`
  width: 100%;
  height: 6px;
  background: ${p => p.theme.border};
  border-radius: 3px;
  margin-top: 6px;
`;

const ProgressInner = styled.div`
  height: 100%;
  width: ${p => p.value || 0}%;
  background: ${p =>
    p.value > 75 ? '#00ff88' :
    p.value > 40 ? '#ffaa00' : '#ff4444'};
  border-radius: 3px;
  transition: width 0.5s ease;
`;

// ===== CREW AVATAR =====
const AvatarCircle = styled.div`
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: ${p => p.color || p.theme.accent};
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
`;

const CrewRow = styled.div`
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
`;

const CrewInfo = styled.div`
  flex: 1;
  & span { display: block; font-size: 12px; color: ${p => p.theme.textSecondary}; }
`;

// ===== DATA =====
const systems = [
  { name: 'Warp engines', active: true },
  { name: 'Energy shields', active: true },
  { name: 'Navigation systems', active: true },
  { name: 'Long-range communications', active: false },
  { name: 'Life support', active: true },
];

const missions = [
  { name: 'X-7 Nebula Exploration', progress: 87 },
  { name: 'Supply Transport', progress: 45 },
  { name: 'Asteroid Mapping', progress: 62 },
  { name: 'Relay Station Repair', progress: 15 },
];

const crew = [
  { name: 'Cpt. Nova', role: 'Commander', color: '#e74c3c', initial: 'N' },
  { name: 'Lt. Orion', role: 'Navigator', color: '#3498db', initial: 'O' },
  { name: 'Dr. Stella', role: 'Medic', color: '#9b59b6', initial: 'S' },
  { name: 'Ing. Vega', role: 'Engineer', color: '#2ecc71', initial: 'V' },
];

// ===== APP =====
function App() {
  const [isDark, setIsDark] = useState(true);
  const theme = isDark ? darkTheme : lightTheme;

  return (
    <ThemeProvider theme={theme}>
      <GlobalStyle />
      <Header>
        <Title>Mission Control</Title>
        <ThemeToggle onClick={() => setIsDark(!isDark)}>
          {isDark ? 'Light Mode' : 'Dark Mode'}
        </ThemeToggle>
      </Header>

      <DashboardGrid>
        {/* Systems Status */}
        <Card delay="0s">
          <CardTitle>Ship systems</CardTitle>
          {systems.map((s, i) => (
            <SystemRow key={i}>
              <span>{s.name}</span>
              <StatusBadge active={s.active}>
                {s.active ? 'ONLINE' : 'OFFLINE'}
              </StatusBadge>
            </SystemRow>
          ))}
        </Card>

        {/* Radar */}
        <Card delay="0.1s">
          <CardTitle>Radar</CardTitle>
          <RadarWrapper>
            <RadarSweep />
            <RadarDot x={30} y={25} />
            <RadarDot x={65} y={40} />
            <RadarDot x={45} y={70} />
          </RadarWrapper>
          <p style={{ textAlign: 'center', fontSize: 13, opacity: 0.7 }}>
            3 objects within scanner range
          </p>
        </Card>

        {/* Missions Progress */}
        <Card delay="0.2s">
          <CardTitle>Missions</CardTitle>
          {missions.map((m, i) => (
            <div key={i} style={{ marginBottom: 12 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13 }}>
                <span>{m.name}</span>
                <span style={{ fontWeight: 'bold' }}>{m.progress}%</span>
              </div>
              <ProgressOuter>
                <ProgressInner value={m.progress} />
              </ProgressOuter>
            </div>
          ))}
        </Card>

        {/* Crew */}
        <Card delay="0.3s">
          <CardTitle>Crew</CardTitle>
          {crew.map((c, i) => (
            <CrewRow key={i}>
              <AvatarCircle color={c.color}>{c.initial}</AvatarCircle>
              <CrewInfo>
                <strong>{c.name}</strong>
                <span>{c.role}</span>
              </CrewInfo>
              <StatusBadge active={true}>On duty</StatusBadge>
            </CrewRow>
          ))}
        </Card>
      </DashboardGrid>
    </ThemeProvider>
  );
}

export default App;

Docs entries used in this lesson

Spotted a mistake in this lesson?

Hands-on tasks in the game

  • Code editor

    Build a comprehensive Design System including: styled-components for component-level styling, CSS-in-JS patterns, theme provider with dark/light modes, responsive design with breakpoints, CSS Grid and Flexbox layouts, animations with @keyframes, typography system, color tokens, spacing system, and accessibility features (focus states, ARIA). Create a design system worthy of the most advanced Deep Space Nine interfaces!

  1. Coding taskProject: Styling System
  2. Project to submitMentor Project: Deep Space Style Laboratory
  3. VideoVideo: Module Summary

Useful articles