@soroush.design/mcp 0.1.4-alpha.1 → 0.1.4-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +4 -4
- package/dist/index.cjs +4 -4
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
// src/content.ts
|
|
6
6
|
const content = {
|
|
7
|
-
"version": "0.1.0-alpha.
|
|
7
|
+
"version": "0.1.0-alpha.3",
|
|
8
8
|
"components": [
|
|
9
9
|
{
|
|
10
10
|
"name": "ScrollArea",
|
|
@@ -1336,7 +1336,7 @@ const content = {
|
|
|
1336
1336
|
"id": "theming",
|
|
1337
1337
|
"title": "Theming",
|
|
1338
1338
|
"summary": "The Theme type, the scales it carries, and how createTheme composes one.",
|
|
1339
|
-
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1339
|
+
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\nThe marks are what a style function's `theme` is typed by: a part that is not marked is a `var(--...)` reference in the type, so it cannot be used as a number (`theme.chart.size * 2` is a type error), and a part marked `asIs()` or `val()` keeps its real type (see [the theme a style function is given](./style.md#the-theme-a-style-function-is-given)).\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1340
1340
|
"url": "https://gild-ui.soroush.design/react/theme/"
|
|
1341
1341
|
},
|
|
1342
1342
|
{
|
|
@@ -1350,7 +1350,7 @@ const content = {
|
|
|
1350
1350
|
"id": "setup",
|
|
1351
1351
|
"title": "New app setup",
|
|
1352
1352
|
"summary": "End-to-end checklist for a new app: fonts, global reset, providers, theme.",
|
|
1353
|
-
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1353
|
+
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n### Right to left\n\nAn app with pages in a right-to-left language adds one option to the same call, `plugins: [rtl()]`\n(`rtl` is exported by `@gild-ui/react/engine`), and writes `dir` on `<html>` for each page\n(`<html lang=\"ar\" dir=\"rtl\">`). Every class then holds both directions, so the one server sends the same CSS for a\npage in either direction. `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction. See\n[the engine entry](../engine.md#right-to-left).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1354
1354
|
},
|
|
1355
1355
|
{
|
|
1356
1356
|
"id": "layout-kit",
|
|
@@ -1374,7 +1374,7 @@ const content = {
|
|
|
1374
1374
|
"id": "design-system-overview",
|
|
1375
1375
|
"title": "Design system overview",
|
|
1376
1376
|
"summary": "The package README: what ships, the import contract, and the component inventory.",
|
|
1377
|
-
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1377
|
+
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nRight to left is opt-in: `configure({ serverTheme, plugins: [rtl()] })` (`rtl` and `dir` are exported by `@gild-ui/react/engine`) has every class hold both directions, the page picks by the `dir` attribute of `<html>`, and `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction ([docs](./docs/engine.md#right-to-left)).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1378
1378
|
"url": "https://gild-ui.soroush.design/react/"
|
|
1379
1379
|
},
|
|
1380
1380
|
{
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk
|
|
|
3
3
|
let zod = require("zod");
|
|
4
4
|
// src/content.ts
|
|
5
5
|
const content = {
|
|
6
|
-
"version": "0.1.0-alpha.
|
|
6
|
+
"version": "0.1.0-alpha.3",
|
|
7
7
|
"components": [
|
|
8
8
|
{
|
|
9
9
|
"name": "ScrollArea",
|
|
@@ -1335,7 +1335,7 @@ const content = {
|
|
|
1335
1335
|
"id": "theming",
|
|
1336
1336
|
"title": "Theming",
|
|
1337
1337
|
"summary": "The Theme type, the scales it carries, and how createTheme composes one.",
|
|
1338
|
-
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1338
|
+
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\nThe marks are what a style function's `theme` is typed by: a part that is not marked is a `var(--...)` reference in the type, so it cannot be used as a number (`theme.chart.size * 2` is a type error), and a part marked `asIs()` or `val()` keeps its real type (see [the theme a style function is given](./style.md#the-theme-a-style-function-is-given)).\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1339
1339
|
"url": "https://gild-ui.soroush.design/react/theme/"
|
|
1340
1340
|
},
|
|
1341
1341
|
{
|
|
@@ -1349,7 +1349,7 @@ const content = {
|
|
|
1349
1349
|
"id": "setup",
|
|
1350
1350
|
"title": "New app setup",
|
|
1351
1351
|
"summary": "End-to-end checklist for a new app: fonts, global reset, providers, theme.",
|
|
1352
|
-
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1352
|
+
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n### Right to left\n\nAn app with pages in a right-to-left language adds one option to the same call, `plugins: [rtl()]`\n(`rtl` is exported by `@gild-ui/react/engine`), and writes `dir` on `<html>` for each page\n(`<html lang=\"ar\" dir=\"rtl\">`). Every class then holds both directions, so the one server sends the same CSS for a\npage in either direction. `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction. See\n[the engine entry](../engine.md#right-to-left).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1353
1353
|
},
|
|
1354
1354
|
{
|
|
1355
1355
|
"id": "layout-kit",
|
|
@@ -1373,7 +1373,7 @@ const content = {
|
|
|
1373
1373
|
"id": "design-system-overview",
|
|
1374
1374
|
"title": "Design system overview",
|
|
1375
1375
|
"summary": "The package README: what ships, the import contract, and the component inventory.",
|
|
1376
|
-
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1376
|
+
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nRight to left is opt-in: `configure({ serverTheme, plugins: [rtl()] })` (`rtl` and `dir` are exported by `@gild-ui/react/engine`) has every class hold both directions, the page picks by the `dir` attribute of `<html>`, and `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction ([docs](./docs/engine.md#right-to-left)).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1377
1377
|
"url": "https://gild-ui.soroush.design/react/"
|
|
1378
1378
|
},
|
|
1379
1379
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
// src/content.ts
|
|
4
4
|
const content = {
|
|
5
|
-
"version": "0.1.0-alpha.
|
|
5
|
+
"version": "0.1.0-alpha.3",
|
|
6
6
|
"components": [
|
|
7
7
|
{
|
|
8
8
|
"name": "ScrollArea",
|
|
@@ -1334,7 +1334,7 @@ const content = {
|
|
|
1334
1334
|
"id": "theming",
|
|
1335
1335
|
"title": "Theming",
|
|
1336
1336
|
"summary": "The Theme type, the scales it carries, and how createTheme composes one.",
|
|
1337
|
-
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1337
|
+
"body": "# Theming\n\nThe theme belongs to you - the package ships defaults, every part is replaceable, and the type system widens with your extensions. This guide covers the full ladder, from using the built-ins to owning every token.\n\n`ThemeProvider`, the hooks that read the theme, the `Theme` type and the configured styling live in `@gild-ui/react`, which an app can also use for its own components, built on the tokens with `styled`. The tokens, `baseTheme` and `createTheme` are `@gild-ui/core`'s, imported from `@gild-ui/core/theme`; each component adds the typing of its own slots to `theme.components`.\n\n## The ladder\n\n1. **Use the default** - `<ThemeProvider>` with no props renders the built-in `baseTheme` (dark-schemed).\n2. **Override values** - build your theme with `createTheme(base, overrides)` (tokens only), collect your themes with `defineThemes` and pass one via `theme`.\n3. **Repoint component defaults** - `theme.defaults` / the provider's `defaults` prop change what components fall back to.\n4. **Extend the type system** - declaration merging adds palette colors, scale keys, and whole scales.\n5. **Customize single components** - `theme.components` (see [customization.md](./customization.md)).\n\n---\n\n## One theme, yours\n\n`ThemeProvider` provides exactly one theme. The package ships a single complete default - `baseTheme` - and you derive every mode from it; switching (dark/light, or ten brand modes) is your state:\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\nconst dark = createTheme(baseTheme, { name: 'dark' /* your palettes */ })\nconst light = createTheme(baseTheme, { name: 'light', colorScheme: 'light' /* your palettes */ })\nexport const themes = defineThemes({ dark, light }, {})\n\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\n## Building themes with `createTheme`\n\n`createTheme(base, overrides)` deep-merges sparse patches onto a base theme:\n\n```ts\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\nexport const brandDark = createTheme(baseTheme, {\n palette: { primary: { main: '#00ff88' } }, // sibling fields (light/dark/contrastText) survive\n radii: { md: '10px' },\n shadows: ['none'], // arrays replace wholesale, never merge\n})\n```\n\nMerge rules: plain objects recurse; arrays (`shadows`, `fontSizes`) and functions replace wholesale; `undefined` values are ignored - keys are added or replaced, never removed. Neither argument is mutated.\n\n## Component defaults (`theme.defaults`)\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)`. The optional `theme.defaults` map overrides any of them globally - essential when your theme uses entirely different size or palette keys:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\nThe full key table lives in the [README's Theming section](../README.md#component-defaults). The built-in `baseTheme` carries no `defaults` - the literals apply until you say otherwise. For _per-component_ defaults (only Buttons compact), use `theme.components.X.defaultProps` instead ([customization.md](./customization.md)).\n\n## Defining and registering your themes\n\n`defineThemes(themes, components)` collects the themes of an app, one or many, and gives every one the same `components` (see [customization.md](./customization.md)). It returns new objects and changes none of its arguments. Register the result once, and every component, hook and `styled` callback knows what your themes add:\n\n```ts\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst light = createTheme(baseTheme, {\n palette: { brand: { main: '#0a7a5a', light: '#3d9b80', dark: '#075640', contrastText: '#fff' } },\n})\nconst dark = createTheme(baseTheme, {\n palette: {\n brand: { main: '#3ddc97', light: '#7ae8b9', dark: '#1fa86f', contrastText: '#06231a' },\n },\n})\n\nexport const themes = defineThemes({ light, dark }, {\n Tabs: { variants: [{ props: { variant: 'pill' }, style: { borderRadius: 999 } }] },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nNow `<Button color=\"brand\">` and `<Tabs variant=\"pill\">` typecheck, `<Button color=\"brnad\">` does not, and `useTheme()` carries your custom tokens. The colors, sizes, spacing keys, breakpoints, typography variants and component looks are read from the themes, so adding one is an edit of a theme, not of a declaration. `<ThemeProvider theme={themes.dark}>` takes any registered theme, and a theme object with a key the registered themes do not have is an error.\n\n**The server theme.** A server component has no provider above it to read, so the app gives the engine one theme for it, once, in its setup module: `configure({ serverTheme: themes.light })` from `@gild-ui/react/engine` (see [the engine entry](./engine.md)). `serverTheme` is the theme of anything with no provider above it, on the server and in the browser: server components, a client component with no provider, and the first render of the page. The setup module is its own file next to the themes (`src/theme/setup.ts`), and each entry of the app that runs first calls its `setup()`; `defineThemes` only defines the themes: it records nothing.\n\nPass the themes to `ThemeProvider` as usual: the tokens are CSS variables, so the page's theme decides their values, and `components` and `defaults` are read from the server theme. The engine then holds one theme for every render outside a provider. It is always your server theme, never the built-in one, so a server component reads the keys only your themes have (`useTheme().chart.grid`). `ThemeProvider` is a client component: a server component does not render it, and needs no provider.\n\n**Nested providers.** A `ThemeProvider` gives its theme to what is below it, and a provider inside another one renders its own theme at all times; only the outermost one stands in for the server theme until the browser has hydrated (below).\n\nIn development, the first `ThemeProvider` on an engine that `configure` never set up warns once: `[soroush] configure(...) was never called: call it once, in the setup module of your app, with your default theme (configure({ serverTheme: themes.light })).` There is no warning in production.\n\n**The server renders the default theme; the browser corrects it.** The server never knows which theme the browser chose (no cookie, no request header carries it), so it always renders your default theme. The outermost `ThemeProvider` does the same while the browser hydrates, whatever its `theme` prop is, so the HTML matches and React warns of nothing; right after hydration it renders its `theme` prop, once. A provider inside another one renders its own theme at all times. When the prop is the default theme, nothing changes. Nested providers are not affected: they render their own theme at all times.\n\nTwo things follow. A visitor whose theme is not the default can see the default for a moment before the page is corrected (a flash); keep the choice in state your client code reads after hydration (`useSyncExternalStore` with the default as the server snapshot), never during the first render. And a server component is not corrected: only its HTML reaches the browser. Its colours, spacing and font sizes are CSS variables, so they follow the provider's theme; its raw tokens (breakpoints, sizes, typography, layout, transitions and `defaults`) are written into its classes with the default theme's values. Keep raw tokens the same in every theme: in development `defineThemes` compares every theme with the first (the one you pass to `configure` as `serverTheme`) and warns once when one differs (`[soroush] Theme \"dark\" and \"light\" differ at typography.h1.fontSize: ...`), and there is no warning in production.\n\n**Raw parts: `$modes`.** A token is a CSS variable, except what is not a CSS value: breakpoints, transitions, sizes, typography, layout, `components` and `defaults` stay real values (`asIs`). That is data in the theme, under the reserved key `$modes`, which `baseTheme` carries (the library marks those parts with `asIs()` through `defineTheme`). `$modes` is plain data, so it survives `createTheme`, `defineThemes`, a spread, `JSON.stringify` and a server sending its theme to the browser, and it is never a token: it is no variable, no scale, no entry of the token pages. An app adds its own raw parts with the same helpers in its own theme: mark the part where you write it (`asIs`, `val`, `fallback`, `variable`) and call `defineTheme` on the theme once:\n\n```ts\nimport { asIs, defineTheme } from '@gild-ui/react/engine'\nimport { baseTheme, createTheme } from '@gild-ui/core/theme'\n\n// `chart.grid` is a real value in JavaScript, not a CSS variable.\nconst light = defineTheme(createTheme(baseTheme, { chart: asIs({ grid: '#222222' }) }))\n```\n\nThe marks are what a style function's `theme` is typed by: a part that is not marked is a `var(--...)` reference in the type, so it cannot be used as a number (`theme.chart.size * 2` is a type error), and a part marked `asIs()` or `val()` keeps its real type (see [the theme a style function is given](./style.md#the-theme-a-style-function-is-given)).\n\n`defineTheme` keeps the `$modes` the theme already has (the library's) and adds yours; it returns plain data, so the result goes to `defineThemes` as any theme does. A CSS-wide keyword (`inherit`, `initial`, `unset`, `revert`) is written as itself with no mark, so `text.inherit` needs nothing.\n\nThe outermost provider declares its theme on `:root`, so the page (`<body>`) follows the switch; a provider inside another one scopes its theme to its own subtree.\n\n**Every theme has the same keys.** The types check it at the `defineThemes` call, at every depth, and the error names the theme and the key: `Theme \"dark\" is missing palette.brand, which \"light\" has`. The values may differ. Without a registration the components accept only the built-in values.\n\n**Limits**\n\n- A misspelt key in a lone theme becomes a new key (`palette.primray`): the other themes catch it, since they lack it; with one theme, a use of it does.\n- Some values are checked where the theme is used, not in the theme file: the `defaultProps` values and variant `props` values of the props the registered themes widen (`color`, `size`, `variant`, `mb`, `marginThreshold`). In development `ThemeProvider` warns about a default outside the catalog's listed values.\n- In the registered theme's own style callbacks, reading a derived `ownerState` prop (`variant`, `color`, `size`) makes TypeScript read the theme it is building. Write the callback's return type (`({ ownerState }): CSSObject => ...`) to break the loop. The other `ownerState` fields (`fullWidth`) read fine.\n- `theme` in a `components` callback is the built-in `Theme`, not the registered one.\n- Do not annotate a theme with `Theme` (`const light: Theme = ...`): the annotation erases the keys the theme adds.\n\n**Style props follow the registered themes.** Once you register, `p`, `m`, `gap`, `bg`, `color`, `fontSize`, `borderRadius` and the other style props of every component take the keys of your themes' scales, in strict mode: `<View p=\"huge\" />` compiles when a theme has `space.huge`; `p=\"nope\"` and a raw value (`p=\"13px\"`) are errors, and a responsive value takes your breakpoint names (`p={{ xs: 'huge', md: 2 }}`). The size props (`width`, `height`, `minWidth`, ...) still take lengths (`width=\"320px\"`) beside the `sizes` keys. Write nothing beyond the registration above. A value that is not a token goes in a `styled` component or a `StyleSheet` entry. To take raw values back, opt out in the `Register` of the style props, for every scale or for some:\n\n```ts\ndeclare module '@soroush.tech/styled-system' {\n interface Register {\n values: 'wide' // or { space: 'wide' }\n }\n}\n```\n\nAn app that registers no themes keeps the loose types.\n\n## Extending the type system\n\nEvery scale is an open interface owned by `@gild-ui/core/theme` - that module (not the styling engine, an internal implementation detail) is the augmentation surface, and it merges reliably across tsdown's chunked d.ts for every consumer:\n\n```ts\nimport type { PaletteEntry, SizeEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface ThemeSizes {\n xl: SizeEntry // new size step\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nComponent prop unions derive via `keyof Theme['scale']`, so `color=\"brand\"`, `bg=\"tertiary\"`, and `size=\"xl\"` typecheck everywhere automatically. Then supply the values:\n\n```ts\nconst brand = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n sizes: { xl: { paddingTop: 2, paddingBottom: 2, paddingLeft: 4, paddingRight: 4, fontSize: 2 } },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n defaults: { size: 'xl' }, // components may default to augmented keys\n})\n```\n\nTwo rules: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was supplied - **always pair an augmentation with the matching override**.\n\n## Reading the theme and the window\n\n`useTheme` returns the active theme, `useDefaultProps(name)` a component's `theme.components[name].defaultProps`, and `withTheme` hands the theme to a class component. For what a style cannot do - render one structure or another - `useMediaQuery(query, { defaultMatches })` answers a media query: `defaultMatches` (false unless given) on the server and in the first render of a hydration, so the HTML of the server and the hydration agree, and the browser's answer at once after. Prefer a CSS media query or a container query from `theme.breakpoints` whenever a style is enough.\n\n```tsx\nimport { useMediaQuery } from '@gild-ui/react'\n\nconst isWide = useMediaQuery('(min-width: 900px)')\n```\n\n## Breakpoints and layout\n\n`theme.breakpoints` and `theme.layout` hold the page's layout system: where it changes, how many\ncolumns it has, its margins and gutters, its side panels and the top bar. Everything responsive is\nCSS - no component measures the window in JavaScript - so a prerendered page lays out the same\nwith JavaScript off. Gild UI ships these as tokens and building blocks (`AppBar`,\n`Sidebar`, `Drawer`, `Grid`, `Flex`); each app composes its own pages from them.\n\n### `theme.breakpoints` - window classes\n\nEach key is a range: its value is where the range starts, and it holds until the next key. The\ntheme writes the start because media queries are min-width. `xs` starts at 0, so it applies\neverywhere until `sm` overrides it.\n\n```ts\nbreakpoints: { xs: '0px', sm: '600px', md: '840px', lg: '1200px', xl: '1600px' }\n```\n\n| Key | Range | Material 3 window class |\n| ---- | ----------- | ----------------------- |\n| `xs` | 0-599px | compact |\n| `sm` | 600-839px | medium |\n| `md` | 840-1199px | expanded |\n| `lg` | 1200-1599px | large |\n| `xl` | 1600px+ | extra-large |\n\nThey are window classes, not devices: a class is about the space the window has. Responsive props\nuse them by name - each key from its size up - or by position:\n\n```tsx\n<View display={{ xs: 'none', md: 'block' }} />\n<View p={[2, 3, 4]} /> // xs, sm, md\n<View p={{ xs: 2, cqSm: 4 }} /> // cq keys: container queries on the same sizes\n```\n\nFor hand-written styles, `theme.breakpoints` carries the query helpers (also exported for\n`baseTheme` as `up`, `down`, `only`, `between`, `not` and `containerQueries`):\n\n```ts\nconst Panel = styled.div(({ theme }) => ({\n padding: 16,\n [theme.breakpoints.down('sm')]: { padding: 8 }, // @media (width < 600px)\n [theme.breakpoints.only('md')]: { padding: 24 }, // @media (840px <= width < 1200px)\n}))\n```\n\nEvery form, the container queries, the units and the order blocks are written in are covered in\nthe styled-system [Breakpoints](https://github.com/soroush-tech/styled-system/blob/main/docs/breakpoints.md) guide.\n\n### `theme.layout` - layout tokens per window class\n\n`xs` is complete; each later class lists only what changes and is merged over the ones before it.\nWith `baseTheme`:\n\n| Class | Columns | Margin / gutter | Content | Start panel | End panel | Top bar |\n| ----- | ------- | --------------- | ---------- | ----------- | ----------- | ------- |\n| `xs` | 4 | 16 / 16 | fluid | hidden | hidden | 64 |\n| `sm` | 8 | 32 / 16 | fluid | rail 72 | hidden | 64 |\n| `md` | 12 | 24 / 24 | fluid | rail 72 | overlay 360 | 64 |\n| `lg` | 12 | 24 / 24 | fixed 1200 | rail 72 | overlay 412 | 64 |\n| `xl` | 12 | 24 / 24 | fixed 1600 | inline 280 | inline 412 | 64 |\n\n- **Units** - `margin` and `gutter` are `theme.space` keys, so they move with the spacing scale.\n Bar heights, panel widths and `maxWidth` take a space key or any CSS length.\n- **Columns** - 1 to 16. 12 is the default from `md` up.\n- **Panels** - `start` and `end` follow the writing direction (they swap in RTL). `mode` is\n `inline` (beside the content at `width`), `collapsed` (a rail at `railWidth`), `overlay` (over\n the content at `width`) or `hidden`. A panel first declared at a later class needs its `mode`,\n `width` and `railWidth` there.\n- **Bars** - `top` (and an optional `bottom`) heights; `0` removes an inherited bar.\n\nThese are tokens: the app places its own `AppBar`, `Sidebar` and `Drawer` with them, and the\ndesign studio draws them on its frames.\n\n### The `layout` prop - the page frame everywhere, the columns on a Grid\n\n`layout` turns the content tokens into CSS per window class. On any `View`-based component -\n`Flex` included - it is the **frame**: the margin and the max width, and the element keeps its\nown display. `Grid` adds the **columns** on top of that frame:\n\n```tsx\n<View layout>...</View> // the theme's frame\n<Flex layout gap={3}>...</Flex> // the frame, a flex column inside\n<Grid layout>...</Grid> // the frame and the theme's columns\n<Grid layout gap={2}>...</Grid> // its own gutter: 16px at every class\n<Grid layout gap={{ xs: 2, md: 4 }}>...</Grid> // 16px, then 32px from md up\n<Grid layout={{ lg: { columns: 16 } }}>...</Grid> // 16 columns from lg up\n<Grid layout={{ maxWidth: '1280px', md: { columns: 6 } }}>...</Grid> // both\n```\n\n- **The frame** - the full width of its parent (`width: 100%`, border-box) with the margin as\n `padding-inline`; in fixed mode capped by `max-width` and centred. It spans its parent in any\n context - a block, a grid item, a flex column or row - so the frame owns its width: size it\n with `maxWidth`, not `width`.\n- **Grid** - `grid-template-columns: repeat(N, minmax(0, 1fr))` and the gutter as `column-gap`.\n- **The gutter is the grid's `gap`** - its own `gap` or `columnGap` (`columnGap` wins), single,\n per class (`{ md: 4 }`) or as an array, sets `column-gap` at every class it covers; where it is\n not set, the theme's gutter applies. Rows take `gap`'s row half or `rowGap`. On a `Flex` or a\n `View`, `gap` is plain flexbox spacing.\n- **Children take `span`** - how many columns of a grid an element takes, on any `View`-based\n component: `span={6}`, per class `span={{ xs: 4, md: 6 }}`, or `span=\"full\"` for the whole row\n whatever the column count (`grid-column: 1 / -1`, in any grid).\n- A field in the value (`maxWidth: '1280px'`) replaces the theme's at every class; whatever it\n does not set still follows the theme. An entry under a class name replaces it **from that class\n up**, mobile-first like every responsive prop, on top of the fields.\n- **The layout owns the column tracks, inline padding and max width** it writes: an explicit\n `gridTemplateColumns`, padding or `maxWidth` on the same element does not override them from the\n second class up. A grid with tracks of its own leaves `layout` off and sits inside a frame.\n\n### Layout: one way per intent\n\nGenerated code, agents and people write each layout intent one way:\n\n| Intent | Write | Not |\n| ------------------------------------------------ | ----------------------------------------------------------- | --------------------------------------------------------- |\n| Content on the page frame, no columns | `<View layout>`, or `<Flex layout>` for a flex stack or row | `maxWidth` + `mx=\"auto\"` + `px`, a custom frame component |\n| A section on the theme's columns | `<Grid layout>` | hand-written tracks on a page section, `Flex` with widths |\n| The app's layout | `theme.layout`, built with `createTheme` | layout values written on every page |\n| A page's (or a region's) own layout | `<LayoutProvider layout={...}>` around the page | the same `layout` value on each section, a nested theme |\n| A section's own columns, margin or max width | `layout={{ md: { columns: 6 } }}`, `layout={{ maxWidth }}` | helpers that repeat a value per class |\n| A section's own gutter | `gap={2}` / `gap={{ xs: 2, md: 4 }}` on the `Grid` | a `gutter` field, `gap` and `columnGap` both |\n| A child taking N columns | `span={6}` / `span={{ xs: 4, md: 6 }}` | `gridColumn=\"span 6\"` |\n| A child taking the whole row | `span=\"full\"` | `grid-column: 1 / -1`, `style`, column-count objects |\n| Space between rows only | `rowGap` | margins on the children |\n| A grid with tracks of its own (`auto-fill`, ...) | a plain `Grid` without `layout`, inside a frame | `layout` plus `gridTemplateColumns` |\n\nThe same page without the prop needs every value written out - and stops following the theme:\n\n```tsx\n<Grid\n gridTemplateColumns={{\n xs: 'repeat(4, minmax(0, 1fr))',\n sm: 'repeat(8, minmax(0, 1fr))',\n md: 'repeat(12, minmax(0, 1fr))',\n }}\n columnGap={{ xs: 2, md: 3 }}\n px={{ xs: 2, sm: 4, md: 3 }}\n>\n ...\n</Grid>\n```\n\n### Your own breakpoints and layout\n\nOverride values with `createTheme`, like any scale:\n\n```ts\nconst theme = createTheme(baseTheme, {\n breakpoints: { md: '900px' },\n layout: { lg: { content: { maxWidth: '1280px' } } },\n})\n```\n\nThe helpers on `theme.breakpoints` are rebuilt from the merged sizes. `createTheme` merges, so\nit can change values and add a larger breakpoint after the existing ones, but not remove or rename\none. To use your own names, declare them by augmenting `BreakpointOverrides` (`true` adds a name,\n`false` removes a default) and replace the scale and the layout on the base:\n\n```ts\ndeclare module '@gild-ui/core/theme' {\n interface BreakpointOverrides {\n mobile: true\n tablet: true\n web: true\n xs: false\n sm: false\n md: false\n lg: false\n xl: false\n }\n}\n\nconst theme = createTheme(\n {\n ...baseTheme,\n breakpoints: withBreakpointHelpers({ mobile: '0px', tablet: '768px', web: '1280px' }),\n layout: { mobile: { ...a complete entry... }, tablet: { ... }, web: { ... } },\n },\n {}\n)\n```\n\nResponsive props, `cq` keys (`cqTablet`), the helpers and the `layout` keys all follow the new\nnames.\n\n## The scale interfaces\n\n| Scale | Key in Theme | Interface |\n| --------------- | ---------------------- | ------------------------- |\n| Palette | `theme.palette` | `ThemePalette` |\n| Text colors | `theme.text` | `ThemeText` |\n| Backgrounds | `theme.background` | `ThemeBackground` |\n| Borders | `theme.border` | `ThemeBorder` |\n| Space | `theme.space` | `ThemeSpace` |\n| Breakpoints | `theme.breakpoints` | `ThemeBreakpoints` |\n| Layout | `theme.layout` | `ThemeLayout` |\n| Sizes | `theme.sizes` | `ThemeSizes` |\n| Radii | `theme.radii` | `ThemeRadii` |\n| Border widths | `theme.borderWidths` | `ThemeBorderWidths` |\n| Fonts | `theme.fonts` | `ThemeFonts` |\n| Font weights | `theme.fontWeights` | `ThemeFontWeights` |\n| Line heights | `theme.lineHeights` | `ThemeLineHeights` |\n| Letter spacings | `theme.letterSpacings` | `ThemeLetterSpacings` |\n| Typography | `theme.typography` | `ThemeTypographyVariants` |\n| Avatar sizes | `theme.avatar` | `ThemeAvatarSizes` |\n| Icon sizes | `theme.icon` | `ThemeIconSizes` |\n| Switch tokens | `theme.switch` | `ThemeSwitch` |\n| Shadow tokens | `theme.shadow` | `ThemeShadow` |\n\n## The spacing scale\n\n`theme.space` steps on an 8px unit, and every step is a whole pixel. The same steps serve padding,\nmargin, `gap` / `rowGap` / `columnGap`, the `layout` margin and the grid's gutter:\n\n| Step | `0` | `0.125` | `0.25` | `0.5` | `0.75` | `1` | `1.25` | `1.5` | `1.75` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `10` |\n| ---- | --- | ------- | ------ | ----- | ------ | --- | ------ | ----- | ------ | --- | --- | --- | --- | --- | --- | --- | --- | ---- |\n| px | 0 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n\nBelow 4px, lines are border widths (`theme.borderWidths`). Use `0.125` and `0.25` only for a gap\nthat should be a hairline - a 1px or 2px gap the background shows through, as in a grid of tiles\non a coloured `Grid`: `<Grid layout gap={0.125} bg=\"grid\">`.\n| Defaults | `theme.defaults` | `ThemeDefaults` |\n| Components | `theme.components` | `ThemeComponents` |\n\nThe contract is verified against the real published d.ts by `type-tests/augmentation.ts` (`pnpm test:types`), so it can't silently break in a release.\n",
|
|
1338
1338
|
"url": "https://gild-ui.soroush.design/react/theme/"
|
|
1339
1339
|
},
|
|
1340
1340
|
{
|
|
@@ -1348,7 +1348,7 @@ const content = {
|
|
|
1348
1348
|
"id": "setup",
|
|
1349
1349
|
"title": "New app setup",
|
|
1350
1350
|
"summary": "End-to-end checklist for a new app: fonts, global reset, providers, theme.",
|
|
1351
|
-
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1351
|
+
"body": "# New-app checklist\n\nReference wiring: a Next.js App Router app on React 19, with server components. The pages and the\nroot layout are server components; Gild UI's static components render on the server with\nthe app's theme, and its interactive components are client components that a server component can\nimport and render.\n\n## 1. Install\n\n```jsonc\n// package.json\n\"dependencies\": {\n \"@gild-ui/core\": \"^0.1.0\",\n \"@gild-ui/react\": \"^0.1.0\",\n \"react\": \"^19.2.8\",\n \"react-dom\": \"^19.2.8\"\n}\n```\n\nThe styling engine (UmberStyle, the `@umber-style/*` packages) comes in as a dependency\nof Gild UI - don't add it directly, and don't import it: what an app needs of it comes from\n`@gild-ui/react`. React 19.2 or later is required.\n\n## 2. Theme\n\nCopy `theme.ts` to the app root so it imports as `@/theme`.\nIt exports `light` and `dark`. The color ramps at the top (`carbonBlack`,\n`cyberCyan`, `kineticGreen`, `forestGreen`, `solarAmber`, `neonRed`, `softGreen`,\n`deepCrimson`, `lightSurface`, `kineticSurface`, `blackAlpha`) are the brand: every\napp that copies them shares one color set. Change which ramp fills a palette slot if\nthe app needs to, never the ramp values.\n\nThe theme module only defines the themes. A `configure({ serverTheme: themes.light })` call, once for\nthe whole program, is what makes server components themed. A server component has no provider above\nit to read, so `useTheme()` and every component's styles read one theme, the `serverTheme` you give\n`configure`: its `components` (the looks of the components) and its `defaults` are real values there,\nand its tokens are CSS variables, so which theme the page is in (light or dark) decides their colors.\nName the theme the app starts in. An app that never calls `configure` renders with the library's\nbuilt-in theme, which lacks the app's own keys, and warns once in development.\n\nWrite the call in a module of its own, next to the themes, and have every entry call it first:\n\n```ts\n// app/setup.ts\nimport { configure } from '@gild-ui/react/engine'\nimport { themes } from './theme'\n\nexport function setup(): void {\n configure({ serverTheme: themes.light })\n}\n```\n\nOne call configures the server components build, the server render of client components and the\nbrowser: the options are kept once for the process, and the same call again does nothing. A Next.js\napp calls `setup()` in three places. `instrumentation.ts` (next to `app`) runs it when the server\nstarts, `instrumentation-client.ts` runs it in the browser before the app hydrates, and the root\nlayout runs it too, because `next build` never calls `register()` while it prerenders:\n\n```ts\n// instrumentation.ts\nimport { setup } from './app/setup'\n\nexport function register(): void {\n setup()\n}\n```\n\n```ts\n// instrumentation-client.ts\nimport { setup } from './app/setup'\n\nsetup()\n```\n\nA component defines its styles when its module is imported and binds the engine at its first render,\nso the order of the imports does not matter: the call only comes before the first render. See\n[the engine entry](../engine.md) for every framework.\n\n## 3. Layout and provider\n\nCopy `providers.tsx` and `scheme.ts` to `app/`. `Providers` is a client component that imports the\nthemes (`components` can hold functions, and a function cannot cross from a server component to a\nclient one, so the browser's bundle takes the themes from the module). It configures nothing: `setup()`\ndoes. It renders one `ThemeProvider` with the theme the visitor chose, kept in `localStorage`, and the\npage's `Global` styles.\n\nThen in `app/layout.tsx`, a server component. It calls `setup()` too (the build prerenders without\n`register()`) and renders `Providers`. The server never knows the visitor's theme: it renders your\n`serverTheme`, and `Providers` corrects it in the browser, once, right after hydration. Server\ncomponents need no provider: they read the `serverTheme`. A provider inside another one renders its\nown theme at all times.\n\n```tsx\nimport { StyleRegistry } from '@gild-ui/react/next'\nimport './nonce'\nimport Providers from './providers'\nimport { setup } from './setup'\n\n// Every page of the build loads the layout, and the build never calls register().\nsetup()\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <body>\n <StyleRegistry>\n <Providers>\n <TopBar />\n {children}\n </Providers>\n </StyleRegistry>\n </body>\n </html>\n )\n}\n```\n\n`StyleRegistry` wraps everything, once (see the next section), and `Global` in `Providers` is the reset:\n`border-box` everywhere, zero body margin, `fonts.body` and the page's `background.primary` and\n`text.initial` on `<body>`. Route groups then supply their own inner layout (rail + `Main`).\n\n**Light and dark.** The choice is client state: `app/scheme.ts` keeps it in `localStorage` and `useScheme()` reads it with `useSyncExternalStore`, with the default theme as the server snapshot, so the first render of the browser is the server's and the stored theme follows. A button calls `setScheme('dark')`. The first load of a visitor whose theme is not the default shows the default for a moment. The outermost `ThemeProvider` renders the `serverTheme` on the server and while it hydrates, then the theme it was given, and declares that theme on `:root`, so the page follows the switch. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, `defaults`) the same in every theme: a server component is not corrected, and `defineThemes` warns in development when one differs. See [Theming](../theming.md).\n\n**Server and client components.** Import every component from its subpath, in a server component\ntoo. Each component's README says which it is. The static ones - `Typography`, `View`, `Flex`,\n`Grid`, `Paper`, `Card`, `Skeleton`, `Icon`, `Link`, `Badge`, `AppBar`, `Quote`, the progress\nindicators - are server components: they render on the server with the registered theme and send no\nJavaScript of their own. The ones with state, effects, events or a family context - `Button`,\n`Tabs`, `Menu`, `Table`, the form controls - are client components: their entry starts with\n`'use client'`, so a server component renders them as it renders any client component, with props\nthat can cross (text, numbers, elements - not functions). A handler goes in a client component of\nyour own, as `Counter` does in `apps/next-fixture`.\n\n**The style registry, and a strict style policy.** Add `StyleRegistry` from `@gild-ui/react/next`\nonce, in the root layout, as above. It collects the styles of each request - of the server components\nand of the client components - and writes them with the HTML, in the head for the first piece of the\nstream and before each later one, so a page is styled before any JavaScript runs. It needs Next.js\n16.3 or later: `next` is an optional peer of `@gild-ui/react`, needed only by an app that imports this\nentry.\n\nA policy whose `style-src` has a nonce and no `'unsafe-inline'` works with it, in three small files.\nThe nonce module tells the engine where the nonce of the request is, once, at module level, and the\nlayout imports it (the `import './nonce'` above):\n\n```ts\n// app/nonce.ts\nimport { setNonceSource } from '@gild-ui/react/engine'\nimport { headers } from 'next/headers'\n\n// Where the nonce of a request comes from: the `x-nonce` header that proxy.ts sets.\nsetNonceSource(async () => (await headers()).get('x-nonce') ?? undefined)\n```\n\n`proxy.ts` makes a new nonce for each request, puts it in the policy of the response, and passes it\non in the request headers, which the render reads:\n\n```ts\n// proxy.ts\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport function proxy(request: NextRequest) {\n const nonce = Buffer.from(crypto.randomUUID()).toString('base64')\n const policy = `style-src 'nonce-${nonce}'; script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`\n const requestHeaders = new Headers(request.headers)\n requestHeaders.set('x-nonce', nonce)\n requestHeaders.set('content-security-policy', policy)\n const response = NextResponse.next({ request: { headers: requestHeaders } })\n response.headers.set('content-security-policy', policy)\n return response\n}\n\nexport const config = {\n matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico).*)' }],\n}\n```\n\nUnder this policy the page's `<style>` elements carry the nonce, and no style is blocked. Two notes: `next dev`\nalso needs `'unsafe-eval'` in `script-src` (the development server evaluates code; a production\nbuild does not), and partial prerendering does not support a nonce policy, because a prerendered\nshell cannot know the nonce of a later request.\n\nThis set-up is tested by `apps/next-fixture` on Next.js 16.4 with React 19.3, in a production\nbuild, with JavaScript off (computed styles of the static and the client components, and the default\ntheme whatever cookie the request carries) and on (no console error, no hydration warning, a click, the switch, a stored dark theme after reload), and under the\nstrict policy above (no console error, no blocked style, a new nonce on every request).\n\n### Right to left\n\nAn app with pages in a right-to-left language adds one option to the same call, `plugins: [rtl()]`\n(`rtl` is exported by `@gild-ui/react/engine`), and writes `dir` on `<html>` for each page\n(`<html lang=\"ar\" dir=\"rtl\">`). Every class then holds both directions, so the one server sends the same CSS for a\npage in either direction. `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction. See\n[the engine entry](../engine.md#right-to-left).\n\n## 4. Fonts\n\n`theme.fonts` names _Space Grotesk_ and _JetBrains Mono_, but the package does not\nload them. An app that never loads them renders in the system sans and mono fonts.\nTo get the intended look, load them once in the root layout -\n`@fontsource-variable/space-grotesk` + `@fontsource-variable/jetbrains-mono`, or\n`next/font`. Leaving the system fonts is also a valid choice; just make it deliberately.\n\n## 5. Layout scaffold\n\n```\ncomponents/\n chrome/constants.ts TOPBAR_HEIGHT = \"3.5rem\"\n chrome/TopBar.tsx sticky AppBar, brand wordmark, breadcrumb, session cluster\n chrome/Main.tsx 1600px column, 20→40px gutters\n chrome/<Rail>.tsx optional icon rail, bottom bar on mobile\n ui.tsx NavLink, TokenCode, StatusBadge + STATUS_TONE map\n PageCard.tsx PageHeader.tsx SectionLabel.tsx Pill.tsx\n StatStrip.tsx TabNav.tsx SettingCard.tsx SearchInput.tsx Skeletons.tsx\n```\n\nSources in `layout-kit.md`.\n\n## 6. tsconfig\n\n`@/*` path alias to the app root - every import above assumes it.\n\n## 7. Verify\n\n`pnpm typecheck` (`tsc --noEmit`) catches the common mistakes: a `tone` string that\nisn't a `PaletteColor`, a `theme.text.*` key that doesn't exist, a missing\n`shouldForwardProp`. The theme is fully typed - lean on it instead of eyeballing.\n"
|
|
1352
1352
|
},
|
|
1353
1353
|
{
|
|
1354
1354
|
"id": "layout-kit",
|
|
@@ -1372,7 +1372,7 @@ const content = {
|
|
|
1372
1372
|
"id": "design-system-overview",
|
|
1373
1373
|
"title": "Design system overview",
|
|
1374
1374
|
"summary": "The package README: what ships, the import contract, and the component inventory.",
|
|
1375
|
-
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1375
|
+
"body": "**Your design system. Your tokens. Your rules.**\nA fully typed React component library where nothing is hardcoded - every color, scale, and default belongs to you, not the package.\n\nTired of forking a component library just to change a color? Every token here is designed to be overridden - theming isn't an afterthought, it's the whole point.\n\n## Install\n\n```sh\nnpm i @gild-ui/react @gild-ui/core\n```\n\n`@gild-ui/core` holds the theme your app writes (`createTheme`, `defineThemes`), imported as `@gild-ui/core/theme`. `react` and `react-dom` are peer dependencies, and React 19.2 or later is required. The styling engine (UmberStyle, the `@umber-style/*` packages) is an internal implementation detail - it ships as a regular dependency, not a peer, so you never install it yourself.\n\n---\n\n## Use it with AI tools\n\nTwo skills teach a coding agent how to build with this library: a house-style skill, and a\nWCAG 2.2 AA skill for contrast, labels, landmarks and accessibility tests. Both install for\nwhichever agents you use:\n\n```sh\nnpx skills add soroush-tech/design-system\n```\n\nAn MCP server serves this library's component inventory, every component's props\nreference, and the live token contract, so an AI assistant writes against the real API\ninstead of guessing. Add the hosted server, `https://mcp.soroush.design/mcp`, to any MCP\nclient; in Claude Code:\n\n```sh\nclaude mcp add --transport http soroush https://mcp.soroush.design/mcp\n```\n\nIt also runs locally over stdio (`npx -y @soroush.design/mcp`). Claude Code users can\ninstall the plugin instead, which brings the skills, the server and a UI review agent in\none step:\n\n```sh\nclaude plugin marketplace add soroush-tech/design-system\nclaude plugin install soroush-design-system@soroush-tech\n```\n\nAny other tool can read [gild-ui.soroush.design/llms.txt](https://gild-ui.soroush.design/llms.txt).\nSee [`@soroush.design/mcp`](../mcp) for the full tool list.\n\n---\n\n## Importing\n\nImport components by subpath, the styling system from the root:\n\n```ts\nimport { Typography } from '@gild-ui/react/Typography'\nimport { Flex } from '@gild-ui/react/Flex'\n```\n\nThe styling system comes from the root `@gild-ui/react` - `ThemeProvider`, `LayoutProvider`, `useTheme`, `useDefaultProps`, `useMediaQuery`, `withTheme`, `styled`, `css`, `keyframes`, `Global`, `StyleSheet`, `useStyle` and `withStyle` - and each name is also an entry point of its own (`@gild-ui/react/useTheme`). The style-prop functions (`space`, `system`, ...) are `@soroush.tech/styled-system`'s, and the theme (`baseTheme`, `createTheme`, the `Theme` type) is `@gild-ui/core/theme`'s: this package re-exports neither.\n\n```ts\nimport { styled, css } from '@gild-ui/react'\nimport { type Theme } from '@gild-ui/core/theme'\n```\n\n`ThemeProvider` and the theme-value hooks (`useTheme`, `useDefaultProps`, `withTheme`):\n\n```ts\nimport { ThemeProvider, useTheme } from '@gild-ui/react'\n```\n\nOverriding a component: its `style` prop takes entries of `StyleSheet.create` only, and `slotProps` takes a `style`, a `className` and `data-*` and `aria-*` attributes for each slot a theme can style. A sheet that reads the theme (`StyleSheet.create((theme) => ...)`) gives a handle for each name, which `style` takes as it is (`style={sheet.card}`); `useStyle` reads the entries where a handle cannot go:\n\n```ts\nimport { StyleSheet, useStyle } from '@gild-ui/react'\n```\n\n`withStyle` and `withTheme` are the class-component twins of `useStyle` and `useTheme`: `withStyle(sheet)` hands a class the entries of a sheet as `styles`. See [Styling and overriding](./docs/style.md).\n\n`Global` is on the root. The raw engine primitives for building your own global styles - `globalStyles`, and the SSR-only `CacheProvider`/`styleCache` pairing - live at `/engine`, with `configure`, which the app calls once, in its setup module (`configure({ serverTheme: themes.light })`, [docs](./docs/engine.md)):\n\n```ts\nimport { Global } from '@gild-ui/react'\nimport { configure, globalStyles, CacheProvider, styleCache } from '@gild-ui/react/engine'\n```\n\n`Global` (retyped against this package's `Theme`) applies app-wide CSS and should render inside `ThemeProvider` so it resolves against the active theme. `globalStyles(theme)` is the base reset this package owns - box-sizing, margin/table resets, and theme-driven body colors - compose it into your own `Global` styles array alongside your app's own concerns (font-family, webfont loading, and anything else app-specific stay entirely app policy).\n\nThe component catalog - every component as data, for tools that place and write components (a\ndesign tool's palette, a source writer) - lives at its own subpath and loads in plain Node\n([docs](./docs/catalog.md)):\n\n```ts\nimport { catalog } from '@gild-ui/react/catalog'\n```\n\nServer rendering with critical CSS (a Vike or other static or server renderer) is a separate, opt-in concern - that's what `CacheProvider` and its paired `styleCache` instance are for. Give `CacheProvider` the `styleCache` (the cache the library's own engine writes to, so there is one cache on the page), render, then read the CSS of the page from the same cache with `styleServer` from `@gild-ui/react/server`: `extractCriticalToChunks(html)` and `constructStyleTagsFromChunks(chunks)` give the `<style data-umber>` tags to put in the head ([docs](./docs/server.md)). Next.js App Router apps collect the styles with `StyleRegistry` from `@gild-ui/react/next` instead, which also works under a strict nonce policy ([docs](./docs/next.md), and `docs/consumer/setup.md`).\n\nRight to left is opt-in: `configure({ serverTheme, plugins: [rtl()] })` (`rtl` and `dir` are exported by `@gild-ui/react/engine`) has every class hold both directions, the page picks by the `dir` attribute of `<html>`, and `Direction` (`@gild-ui/react/Direction`) keeps an area in its own direction ([docs](./docs/engine.md#right-to-left)).\n\nThe cache key and class prefix is `soroush`. Server-rendered style elements carry `data-umber=\"soroush ...\"`, and the live element in the browser is `<style data-style=\"soroush\">`.\n\nThe engine packages are regular dependencies of this package, not peers, on purpose: an app installs nothing extra to render the components, and has no version to keep in step. An app never imports an engine package: what it needs of the engine is exported from this package (`StyleSheet`, `setNonceSource`, `styleCache`, `styleServer`, `StyleRegistry`).\n\n---\n\n## Component inventory\n\n### Layout & surfaces\n\n| Component | Purpose |\n| ------------ | ----------------------------------------------------------------------- |\n| `ScrollArea` | A scrolling area with scrollbars drawn over its content, shown on hover |\n| `View` | Styled `div` primitive - the base building block |\n| `Flex` | `View` with flexbox defaults |\n| `Grid` | CSS grid container |\n| `Paper` | Elevated surface with background and shadow |\n| `Card` | Content container built on `Paper` |\n| `Quote` | Bordered quote / terminal-panel surface on `View` |\n| `AppBar` | Top application bar |\n| `Drawer` | Slide-in side panel |\n\n### Content & data display\n\n| Component | Purpose |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Typography` | Text with variant → element mapping - the reference implementation for all components |\n| `Link` | Anchor with theme-aware styling |\n| `Icon` | Icon renderer |\n| `Image` | Image with styled-system props |\n| `Avatar` | User/entity avatar |\n| `Table` | Compound data table - exports `TableContainer`, `TableHead`, `TableBody`, `TableFooter`, `TableRow`, `TableCell`, `TablePagination`, `TablePaginationActions`, `TableSortLabel`, and `TableControl` from `@gild-ui/react/Table` |\n| `Accordion` | A heading that opens and closes a region - exports `AccordionSummary`, `AccordionDetails`, `AccordionActions` and `AccordionGroup` from `@gild-ui/react/Accordion` |\n\n### Inputs & forms\n\n| Component | Purpose |\n| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `Autocomplete` | A field whose text finds an option in a list - one, several as chips, or free text |\n| `Fab` | A floating action button: the one main action of a page, circular or extended |\n| `Button`, `ButtonGroup`, `ToggleButton` | Actions and toggles |\n| `TextInput` | Text field |\n| `Checkbox`, `Radio`, `Switch` | Selection controls |\n| `RangeInput` | A slider - one value on a range, or two or more thumbs for a range of values |\n| `TransferList` | Two lists and the buttons that move the checked items from one to the other |\n| `NumberInput` | A field for a number - read in its locale, clamped to a range, stepped by keys or buttons |\n| `Rating` | A row of icons the user sets as a rating, or a read-only display of one |\n| `NativeSelect` | Low-level platform `<select>` - not recommended; use `Select native` |\n| `Select` | The select to use - custom listbox, or `native` for the platform picker |\n| `MenuItem` | Option row for `Select`'s listbox, and a menu row in a `MenuList` |\n| `Form`, `FormControl`, `FormLabel`, `FormHelperText` | Form composition and labeling |\n| `Pagination` | Page navigation control |\n\n### Navigation & menus\n\n| Component | Purpose |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `NavTree` | A tree of links to the pages of a site - groups of links, which can fold |\n| `Breadcrumbs` | The trail of links from a site's root to the current page - a long one collapses behind a button that shows it all |\n| `Menu` | A trigger and the list of commands it opens - exports `MenuList` (the `role=\"menu\"` list that owns the keyboard), `MenuDivider`, `MenuItems` (rows from data) and `ContextMenu` (the same list, opened at the pointer by a right-click) from `@gild-ui/react/Menu` |\n| `Tabs` | A row of tabs - exports `Tab`, `TabContext` (holds the value for a `TabList` and its panels), `TabList` (the `Tabs` of a `TabContext`), `TabPanel` (the content a tab shows) and `TabScrollButton` from `@gild-ui/react/Tabs` |\n\n### Feedback\n\n| Component | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |\n| `FabMenu` | A fab that opens a stack of actions from the corner of a page |\n| `Snackbar` | A transient message in a corner of the window, with auto-hide and an action |\n| `Alert` | An inline message with a severity, an icon, a title and an action - exports `AlertTitle` from `@gild-ui/react/Alert` |\n| `Badge` | A count or a dot anchored over another element |\n| `Chip` | A compact tag: a label, an icon or avatar, a click and a delete |\n| `CircularProgress`, `LinearProgress` | Determinate/indeterminate progress indicators |\n| `Skeleton` | Loading placeholder with pulse/wave animations |\n| `Backdrop` | Dimmed overlay behind modal surfaces |\n\n### Transitions\n\n| Component | Purpose |\n| ------------------------------- | ------------------------------------------------------------------ |\n| `Collapse` | Opens and closes its content by its height, or its width |\n| `Fade`, `Grow`, `Slide`, `Zoom` | Show and hide one child by opacity, scale, an edge or from nothing |\n\n### Overlay & behavior primitives\n\n| Component | Purpose |\n| --------------- | ----------------------------------------------------------------------------------- |\n| `Tooltip` | A short description of one element, shown on hover, keyboard focus and a long touch |\n| `Portal` | Renders children into a DOM node outside the parent hierarchy |\n| `FocusTrap` | Keeps focus inside a subtree |\n| `Modal` | Dialog primitive composing `Portal`, `Backdrop`, and `FocusTrap` |\n| `Popover` | Anchored floating surface built on `Modal` |\n| `ThemeProvider` | Supplies the theme and global styles to the app |\n\n---\n\n## Theme tokens\n\nComponents never hardcode colors or sizes - props resolve against scales on the `Theme` object:\n\n| Group | Scales |\n| ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| Color | `palette` (main/light/dark/contrastText per color) · `text` · `background` · `border` · `colorScheme` |\n| Typography | `typography` (variant map) · `fonts` · `fontSizes` · `fontWeights` · `lineHeights` · `letterSpacings` |\n| Space & shape | `space` · `sizes` · `radii` · `borderWidths` · `shadows` |\n| Layout | `breakpoints` (xs/sm/md/lg/xl window classes) · `layout` (columns, margins, panels, top bar per class) |\n| Component scales | `avatar` (size steps) · `skeleton` (wave highlight) |\n| Layering & effects | `zOrder` (appBar/drawer/modal/snackbar/tooltip) · `blur` · `logoFilter` · `portraitBlend` · `portraitOpacity` |\n\nProp types are derived from the interface (`keyof Theme['text']`), so adding a token to `themes.ts` propagates everywhere automatically. See [`design-system.md`](./design-system.md) for the full scale table and the palette rules.\n\n---\n\n## Theming\n\nThe theme belongs to you - the package only ships defaults. This section is the overview; the full guides are [`docs/theming.md`](./docs/theming.md) and [`docs/customization.md`](./docs/customization.md).\n\n### One theme, yours\n\n`ThemeProvider` provides exactly one theme - the built-in dark theme when you pass nothing. Bring one theme, or as many as you like: switching between them is your state, not the provider's.\n\n```tsx\nimport { ThemeProvider } from '@gild-ui/react'\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\n\n// Your themes - written from scratch or extended from the base, gathered by `defineThemes`.\nexport const themes = defineThemes(\n {\n light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),\n dark: createTheme(baseTheme, { palette: { primary: { main: '#00ff88' } } }),\n },\n {}\n)\n\n// Once, in your setup module (`setup()`, which each entry of the app calls first): the theme server\n// components read, which have no provider above them: `configure({ serverTheme: themes.dark })`.\n\n// Mode switching is app policy - own the state and pass the active theme:\nconst [isDark, setIsDark] = useState(true)\n<ThemeProvider theme={isDark ? themes.dark : themes.light}>{app}</ThemeProvider>\n```\n\nWith no theme, `ThemeProvider` provides the built-in dark theme. Themes are not annotated with `Theme`: their own type is what the registration (below) hands to every component.\n\n`createTheme(base, overrides)` (exported from `@gild-ui/core/theme`) is the merge primitive: plain objects recurse, arrays (`shadows`, `fontSizes`) and functions replace wholesale, `undefined` values are ignored - keys are added or replaced, never removed.\n\n### Breakpoints and layout\n\n`theme.breakpoints` are Material 3's window classes, each a range from its start until the next:\n`xs` 0-599px (compact, the base), `sm` 600-839 (medium), `md` 840-1199 (expanded), `lg`\n1200-1599 (large), `xl` 1600+ (extra-large). Responsive props use them by name or position -\n`p={{ xs: 2, md: 4 }}`, `p={[2, 3, 4]}` - and `cqSm`-style keys write container queries;\n`theme.breakpoints.up('md')` and its siblings write queries for hand-written styles. Everything is\nCSS, so pages work with JavaScript off. `theme.layout` holds the layout tokens per class (columns,\nmargins, gutters, side panels, top bar); `Grid` and `Flex` apply the column grid with\n`layout` / `layout={{ lg: { columns: 16 } }}`, and apps place `AppBar`, `Sidebar` and `Drawer`\nthemselves. The full guide is the\n[Breakpoints and layout](./docs/theming.md#breakpoints-and-layout) section of the theming guide.\n\n### Component defaults\n\nComponents carry visible literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) resolved through `themeDefault(theme, key, fallback)` - so every default, including behavioral variants, is overridable via the optional `theme.defaults` map or the provider's `defaults` prop:\n\n| Key | Fallback | Drives |\n| -------------------------------------------- | ---------------------------------- | -------------------------------------- |\n| `size` / `compactSize` | `'md'` / `'sm'` | sized components / dense table actions |\n| `color` / `neutralColor` | `'primary'` / `'default'` | accent controls / toggle controls |\n| `textColor` / `accentTextColor` | `'initial'` / `'primary'` | body text / icons + input labels |\n| `bg` / `surfaceBg` / `inputBg` | `'default'`/`'paper'`/`'terminal'` | switch track / paper surfaces / inputs |\n| `borderRadius` / `surfaceRadius` | `'md'` / `'sq'` | grouped controls / surfaces |\n| `avatarSize` / `borderColor` / `borderWidth` | `'md'` / `'primary'` / `'thin'` | avatars and rings |\n| `iconSize` | `'lg'` | Icon default glyph size (`theme.icon`) |\n| `inputMinWidth` | `'12rem'` | least width of an input not full width |\n| `buttonVariant` / `switchVariant` | `'contained'` / `'outside'` | Button / Switch visual variants |\n| `inputVariant` | `'default'` | TextInput, Select, NativeSelect frames |\n| `avatarVariant` / `cardVariant` | `'circular'` / `'paper'` | Avatar shape / Card treatment |\n| `linkUnderline` | `'always'` | Link underline behavior |\n| `paginationVariant` / `paginationShape` | `'text'` / `'circular'` | Pagination items |\n\nThe built-in themes carry no `defaults` - the literals apply. A theme with entirely different size or palette keys stays valid by pointing the keys at its own tokens:\n\n```tsx\n<ThemeProvider defaults={{ size: 'compact', color: 'brand', switchVariant: 'inside' }}>\n```\n\nTwo `defaults` objects with the same contents give the same theme, so an inline literal costs nothing per render: the provider derives one theme for each theme and `defaults` contents, and the engine declares its tokens once.\n\n### Per-component customization (`theme.components`)\n\nCustomize one component for the whole app - default prop values, per-slot CSS, and new variant values - without wrapping or forking:\n\n```tsx\nimport { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'\nimport type { ThemeComponents } from '@gild-ui/react'\n\nconst brand = createTheme(baseTheme, { name: 'brand' })\n\n// The components are set once for all your themes, and checked with `satisfies ThemeComponents`.\nexport const themes = defineThemes({ brand }, {\n Button: {\n // Buttons default to sm + rounded; explicit props and ButtonGroup still win.\n defaultProps: { size: 'sm', shape: 'rounded' },\n\n // Per-slot CSS merged after Button's own styles - the theme wins the cascade,\n // but per-instance props (m, p, width, ...) still beat the theme.\n styleOverrides: {\n root: ({ theme, ownerState }) => ({\n letterSpacing: theme.letterSpacings.wide,\n ...(ownerState.variant === 'contained' && { textTransform: 'none' }),\n }),\n label: { fontStyle: 'italic' },\n },\n\n // A new variant value - register the themes (below) and `variant=\"dashed\"` typechecks:\n variants: [\n {\n props: { variant: 'dashed' },\n style: ({ theme }) => ({\n backgroundColor: 'transparent',\n border: `${theme.borderWidths.thin} dashed ${theme.border.primary}`,\n }),\n },\n ],\n },\n} satisfies ThemeComponents)\n\ndeclare module '@gild-ui/core/theme' {\n interface Register {\n themes: typeof themes\n }\n}\n```\n\nStyle callbacks receive `{ theme, ownerState }`, where `ownerState` is the styled root's **resolved** props (after group context, `defaultProps`, and `theme.defaults`). `defaultProps` sits in the standard precedence chain: explicit prop → group context → `defaultProps` → `theme.defaults.*` → the component's literal fallback.\n\nYour own components can join the same mechanism: create their roots with this package's `styled(tag, { name: 'MyWidget', slot: 'root' })` and register the name by augmenting `ThemeComponents`. Zero-config themes pay nothing - the resolver bails out on the first check when `theme.components` is absent.\n\n### Extending tokens (declaration merging)\n\nEvery scale is an open interface declared on `@gild-ui/core/theme`, so you can add palette colors, tokens, or whole scales - and every component prop union (`color`, `bg`, `size`, ...) widens automatically:\n\n```ts\nimport type { PaletteEntry } from '@gild-ui/core/theme'\n\ndeclare module '@gild-ui/core/theme' {\n interface ThemePalette {\n brand: PaletteEntry // new palette color\n }\n interface ThemeBackground {\n tertiary: string // new background token\n }\n interface Theme {\n elevations: Record<'low' | 'mid' | 'high', string> // whole new scale\n }\n}\n```\n\nThen supply the values with `createTheme` and use the new keys:\n\n```tsx\nconst brandDark = createTheme(baseTheme, {\n palette: { brand: { main: '#00ff88', light: '#66ffb2', dark: '#00b25f', contrastText: '#000' } },\n background: { tertiary: '#101418' },\n elevations: { low: '0 1px 2px', mid: '0 2px 6px', high: '0 6px 18px' },\n})\n\n<ThemeProvider theme={brandDark}>\n <Button color=\"brand\" />\n <View bg=\"tertiary\" />\n</ThemeProvider>\n```\n\nNotes: new object-valued keys (like a `PaletteEntry`) must be supplied complete - components read `.main`/`.contrastText` at runtime; and TypeScript cannot verify at runtime that an augmented token was actually supplied, so always pair an augmentation with the matching override.\n\n---\n\n## Adding a component\n\nScaffold with the skill - it reads the live `Typography` files and `design-system.md` so output matches the codebase:\n\n```\n/new_theme_component ComponentName\n```\n\nThen work through the checklist at the bottom of [`design-system.md`](./design-system.md).\n\n---\n\nThe library takes inspiration from [Material UI](https://mui.com/) - its component vocabulary and prop conventions will feel familiar - but it is written entirely in house. It is not a clone or a fork: every component is built from scratch on our own engine and token system, and the API is free to diverge wherever it serves its consumers better.\n\n---\n\n## Release notes\n\nPer-version notes for every published release live in\n[`release-notes/`](https://github.com/soroush-tech/design-system/tree/main/packages/react/release-notes).\n",
|
|
1376
1376
|
"url": "https://gild-ui.soroush.design/react/"
|
|
1377
1377
|
},
|
|
1378
1378
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soroush.design/mcp",
|
|
3
|
-
"version": "0.1.4-alpha.
|
|
3
|
+
"version": "0.1.4-alpha.2",
|
|
4
4
|
"description": "MCP server for Gild UI - serves the component inventory, every component README, and the theme token contract to AI coding tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|