# StackedLayout

> Page-scale chrome for top-nav pages - optional header, flex-grow main, optional footer. Use for marketing pages, articles, and any view that doesn't need a persistent side rail.

- Category: layout
- Status: stable (since 0.3.0)
- A11y pattern: https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/
- Tokens: --background-primary, --foreground-primary, --foreground-secondary, --border-width-thin, --fs-sm
- Playground: https://design.freecodecamp.org/playground#stacked-layout
- npm dependencies: `react@>=18 <20`
- Registry dependencies: [theme](https://design.freecodecamp.org/registry/theme.md)
- Files:
  - `StackedLayout.tsx` → `src/ui/stacked-layout/StackedLayout.tsx` (raw: https://design.freecodecamp.org/registry/stacked-layout/StackedLayout.tsx)
  - `stacked-layout.css` → `src/ui/stacked-layout/stacked-layout.css` (raw: https://design.freecodecamp.org/registry/stacked-layout/stacked-layout.css)

## Install (copy source)

1. Ensure the theme is installed once per project - tokens.css + base.css imported globally, fonts available. See https://design.freecodecamp.org/registry/theme.md and https://design.freecodecamp.org/registry/starter.md.
2. Copy the files below into `src/ui/stacked-layout/` (adjust to your project layout) and import the CSS once from your global stylesheet, e.g. `@import './ui/stacked-layout/stacked-layout.css';`.
3. Colors, spacing and type come from tokens - tailor the component by editing the copied source; recolour by editing tokens.css, not the component CSS.

## Usage

StackedLayout is the full-page shell for top-nav pages - a Navbar on
top, a flex-grow `<main>` for the content, and an optional footer
row. Reach for it on marketing pages, blogs, and content-heavy views
where a persistent side rail would only compete for attention.

## Accessibility

Semantic landmarks come from slot contents - Navbar brings
`role="banner"`, the main column is a native `<main>`, and the
footer slot is a plain container (wrap with your own `<footer>` when
you need `role="contentinfo"`).

## Example

```tsx
import { StackedLayout } from './ui/stacked-layout/StackedLayout';
import { Navbar } from './ui/navbar/Navbar';

<StackedLayout
  header={<Navbar … />}
  footer={<footer>…</footer>}
>
  {children}
</StackedLayout>
```

## Props

| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `header` | `ReactNode` | no | - |  |
| `footer` | `ReactNode` | no | - |  |

## Source: StackedLayout.tsx

```tsx
import React, { forwardRef } from 'react';

export interface StackedLayoutProps extends React.HTMLAttributes<HTMLDivElement> {
  header?: React.ReactNode;
  footer?: React.ReactNode;
}

export const StackedLayout = forwardRef<HTMLDivElement, StackedLayoutProps>(
  ({ header, footer, className = '', children, ...rest }, ref) => {
    const classes = ['stacked-layout', className].filter(Boolean).join(' ');
    return (
      <div ref={ref} className={classes} {...rest}>
        {header !== undefined && (
          <div className='stacked-layout__header'>{header}</div>
        )}
        <main className='stacked-layout__main'>{children}</main>
        {footer !== undefined && (
          <div className='stacked-layout__footer'>{footer}</div>
        )}
      </div>
    );
  }
);
StackedLayout.displayName = 'StackedLayout';
```

## Source: stacked-layout.css

```css
.stacked-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--background-primary);
  color: var(--foreground-primary);
}
.stacked-layout__header {
  flex: 0 0 auto;
}
.stacked-layout__main {
  flex: 1 1 auto;
  padding: 24px;
  min-width: 0;
}
.stacked-layout__footer {
  flex: 0 0 auto;
  padding: 16px 24px;
  border-top: var(--border-width-thin) solid var(--foreground-secondary);
  color: var(--foreground-secondary);
  font-size: var(--fs-sm);
}
```

## HTML / vanilla variant

```html
<div class="stacked-layout">
  <header class="stacked-layout__header">…</header>
  <main class="stacked-layout__main">…</main>
  <footer class="stacked-layout__footer">…</footer>
</div>
```

Interactive behaviours for plain HTML come from the vanilla runtime (data-uikit-* attributes): https://design.freecodecamp.org/registry/vanilla.md - or download https://design.freecodecamp.org/cdn/uikit.global.js once and self-host it (do not hotlink).

## For coding agents

This library is distributed as copyable source, not an npm package. Start at https://design.freecodecamp.org/registry/starter.md, discover components via https://design.freecodecamp.org/llms.txt, and copy files into the consuming project. Keep token names intact; recolour by editing the copied tokens.css.
