# ThemeProvider

## Introduction

`ThemeProvider` is the root provider that supplies theme tokens across CDS components.
Internally, it applies Joy UI `CssVarsProvider` and `CssBaseline`, and also enables CDS-specific typography levels (`marketing-lg`, `marketing-md`, `marketing-sm`) consistently.
Because this is an internal design system with pre-defined brand identity, changing tokens via `CustomTheme` is considered an anti-pattern.

```tsx
<ThemeProvider>
    <DemoContent />
  </ThemeProvider>
```

| Field                        | Description | Default |
| ---------------------------- | ----------- | ------- |
| Controls resolved at runtime | —           | —       |

## Usage

```tsx
import { ThemeProvider } from '@ceed/cds';

function App() {
  return (
    <ThemeProvider>
      <YourRoutes />
    </ThemeProvider>
  );
}
```

## CDS-specific Typography

CDS extends `marketing-*` levels for landing and promotional UI typography.

```tsx
<ThemeProvider>
    <Stack spacing={1}>
      <Typography level="marketing-lg">Marketing Large</Typography>
      <Typography level="marketing-md">Marketing Medium</Typography>
      <Typography level="marketing-sm">Marketing Small</Typography>
    </Stack>
  </ThemeProvider>
```

```tsx
<Typography level="marketing-lg">Hero title</Typography>
<Typography level="marketing-md">Section title</Typography>
<Typography level="marketing-sm">Card title</Typography>
```

## Common Use Cases

### App Root

```tsx
import { ThemeProvider } from '@ceed/cds';

createRoot(document.getElementById('root')!).render(
  <ThemeProvider>
    <App />
  </ThemeProvider>,
);
```

### Storybook/Test Wrapper

```tsx
import { ThemeProvider } from '@ceed/cds';

const renderWithTheme = (ui: React.ReactElement) => {
  return render(<ThemeProvider>{ui}</ThemeProvider>);
};
```

## Best Practices

1. **Use a single provider at the app root**: multiple nested providers can cause unexpected token conflicts.
2. **Do not create custom themes**: CDS is a standardized internal system with built-in brand identity, and `CustomTheme` usage is an anti-pattern.
3. **Do not omit the provider**: CDS style consistency, including `marketing-*` levels, can break.
4. **Keep package usage consistent**: use only `@ceed/cds` ThemeProvider in CDS applications.

## Accessibility

1. **Check brand color contrast**: ensure text contrast remains accessible even with default tokens.
2. **Do not rely on color alone for state**: combine color with text, icons, or labels.
3. **Maintain typography hierarchy**: use marketing levels for emphasis and keep body text at body levels for readability.
4. **Keep focus indicators visible**: verify keyboard focus visibility is preserved.
