@rolder-kit/mantine
Version:
221 lines (164 loc) • 5.95 kB
Markdown
---
name: app-shell
description: Root app shell with DefaultApp, color scheme persistence, and default theme
type: foundation
library: "@rolder-kit/mantine"
library_version: "0.1.0-beta.1"
sources:
- stable/mantine/src/DefaultApp.tsx
- stable/mantine/src/AppDefaults.tsx
- stable/mantine/src/defaultTheme.ts
- stable/mantine/src/cookieColorSchemeManager.ts
requires:
- "@rolder-kit/tanstack/cookie"
---
## Setup
```tsx
// __root.tsx (TanStack Start root route)
import "@rolder-kit/mantine/styles.css";
import { DefaultApp } from "@rolder-kit/mantine";
import { createRootRoute } from "@tanstack/react-router";
export const Route = createRootRoute({
component: RootComponent,
});
function RootComponent() {
return (
<DefaultApp>
<Outlet />
</DefaultApp>
);
}
```
The `styles.css` import MUST come before any component imports that render Mantine elements. Without it, all Mantine components render unstyled.
## Core Patterns
### Minimal app shell
`DefaultApp` renders the full `<html>` document with `lang="ru"`, `<HeadContent />`, `<ColorSchemeScript />`, `<MantineProvider>`, and `<Scripts />`. It applies `defaultTheme` (centered modals, repositioned close button) and `cookieColorSchemeManager` automatically.
```tsx
import "@rolder-kit/mantine/styles.css";
import { DefaultApp } from "@rolder-kit/mantine";
function RootComponent() {
return (
<DefaultApp>
<Outlet />
</DefaultApp>
);
}
```
### Color scheme persistence
By default `saveColorScheme` is `true`. `DefaultApp` reads the `colorScheme` cookie on the server via `getCookie` and passes it to both `ColorSchemeScript` and `MantineProvider` to avoid flash. `AppDefaults` saves the computed color scheme back to a cookie on the client via `setCookies`.
To disable persistence:
```tsx
<DefaultApp saveColorScheme={false}>
<Outlet />
</DefaultApp>
```
When `saveColorScheme={false}`, the `defaultColorScheme` prop controls the initial scheme (defaults to `"auto"`).
### Extending the theme
Pass additional `MantineProviderProps` through `DefaultApp`. The `theme` prop merges with `defaultTheme` at the MantineProvider level:
```tsx
import "@rolder-kit/mantine/styles.css";
import { DefaultApp, defaultTheme } from "@rolder-kit/mantine";
import { mergeThemeOverrides } from "@mantine/core";
const customTheme = mergeThemeOverrides(defaultTheme, {
primaryColor: "blue",
fontFamily: "Inter, sans-serif",
});
function RootComponent() {
return (
<DefaultApp theme={customTheme}>
<Outlet />
</DefaultApp>
);
}
```
### Default theme details
`defaultTheme` configures Mantine's `Modal` component defaults:
- `Modal`: `centered: true`, `padding: "lg"`
- `Modal.Title`: `pr: 24` (padding-right to avoid overlap with close button)
- `Modal.CloseButton`: `pos: "absolute"`, `top: 4`, `right: 4`
These apply automatically to all `Modal` instances unless explicitly overridden per-component.
## Common Mistakes
### CRITICAL: Import from -kit/tanstack root (has no root export)
Wrong:
```tsx
import { getCookie } from "@rolder-kit/tanstack";
```
Correct:
```tsx
import { getCookie } from "@rolder-kit/tanstack/cookie";
```
`-kit/tanstack` has no `"."` export in its package.json -- only `"./cookie"` and `"./middlewares"` sub-paths exist.
Source: stable/tanstack/package.json
### HIGH: Forget to import styles.css
Wrong:
```tsx
import { DefaultApp } from "-kit/mantine";
function RootComponent() {
return <DefaultApp><Outlet /></DefaultApp>;
}
```
Correct:
```tsx
import "-kit/mantine/styles.css";
import { DefaultApp } from "-kit/mantine";
function RootComponent() {
return <DefaultApp><Outlet /></DefaultApp>;
}
```
Without `@rolder-kit/mantine/styles.css`, Mantine components render with no styling -- broken layout, invisible controls, raw HTML elements.
Source: stable/mantine/package.json (exports `"./styles.css"`)
### HIGH: Create multiple cookieColorSchemeManager instances
Wrong:
```tsx
import { cookieColorSchemeManager } from "-kit/mantine";
function RootComponent() {
// Creates a new instance on every render
const manager = cookieColorSchemeManager();
return <DefaultApp colorSchemeManager={manager}><Outlet /></DefaultApp>;
}
```
Correct:
```tsx
// DefaultApp already creates a single module-level instance internally.
// Do not pass your own colorSchemeManager.
import { DefaultApp } from "-kit/mantine";
function RootComponent() {
return <DefaultApp><Outlet /></DefaultApp>;
}
```
`DefaultApp` creates one `cookieColorSchemeManager()` at module scope. Passing another instance causes two managers to fight over the `colorScheme` cookie and nanostores atom.
Source: stable/mantine/src/DefaultApp.tsx (line 16)
### MEDIUM: Override defaultColorScheme without disabling saveColorScheme
Wrong:
```tsx
<DefaultApp defaultColorScheme="dark">
<Outlet />
</DefaultApp>
```
Correct:
```tsx
<DefaultApp defaultColorScheme="dark" saveColorScheme={false}>
<Outlet />
</DefaultApp>
```
When `saveColorScheme` is `true` (default), the cookie value overrides `defaultColorScheme` on the server. The prop only takes effect when no cookie exists yet, or when persistence is disabled.
Source: stable/mantine/src/DefaultApp.tsx (lines 24-26)
### MEDIUM: Pass theme prop expecting merge with defaultTheme
Wrong:
```tsx
// This replaces defaultTheme entirely
<DefaultApp theme={{ primaryColor: "blue" }}>
<Outlet />
</DefaultApp>
```
Correct:
```tsx
import { defaultTheme } from "-kit/mantine";
import { mergeThemeOverrides } from "/core";
const theme = mergeThemeOverrides(defaultTheme, { primaryColor: "blue" });
<DefaultApp theme={theme}>
<Outlet />
</DefaultApp>
```
`DefaultApp` spreads `{...props}` after `theme={defaultTheme}`, so a bare `theme` prop replaces the default Modal configuration. Use `mergeThemeOverrides` to preserve it.
Source: stable/mantine/src/DefaultApp.tsx (lines 35-39)