Token exports
@codeui/solid v0.3.0
The JavaScript token objects and the @codeui/solid/tokens entry.
The kit exports its tokens as JavaScript objects, so TypeScript and vanilla-extract code can reference them by path. Every leaf is a var(--cui-…) string. The values themselves are listed on Tokens.
| Export | Status | What it holds |
|---|---|---|
tokens | Current | Every --cui-* token, by role. |
themeTokens | Deprecated | The old scale names. |
themeVars | Deprecated | The old color names. |
breakpoints | Current | Viewport widths in pixels. |
layoutVars | Current | One layout variable, layoutBackgroundColor. |
responsiveStyle | Current | A helper that writes min-width media queries. |
The @codeui/solid/tokens entry
import { style } from "@vanilla-extract/css";
import {
tokens,
themeVars,
themeTokens,
layoutVars,
breakpoints,
responsiveStyle,
} from "@codeui/solid/tokens";
export const consumer = style({
color: tokens.text.default,
background: themeVars.background,
borderColor: themeTokens.colors.background,
padding: tokens.space["2"],
vars: { [layoutVars.layoutBackgroundColor]: tokens.surface.canvas },
"@media": {
[`(min-width: ${breakpoints.md}px)`]: { margin: themeTokens.spacing["2"] },
},
...responsiveStyle({ lg: { color: tokens.text.muted } }),
});This file is packages/kit/fixtures/tokens-consumer/consumer.css.ts. pnpm --filter @codeui/solid test:tokens-consumer builds it against the packed dist output, once with the import export condition and once with solid.
Import from @codeui/solid/tokens in every vanilla-extract .css.ts file. Import from @codeui/solid everywhere else.
- Named exports.
tokens,themeTokens,themeVars,breakpoints,layoutVarsandresponsiveStyle. Nothing else. - Parity with the root.
@codeui/solidre-exports the same six objects from the same modules. A value from one entry is identical to the value from the other. - No component code. The entry imports nothing from
solid-jsor@kobalte/*. The fixture check fails the test if any file it reaches does. - Side effects. The token entry is a pure JavaScript object module. It does not load CSS or run vanilla-extract. Load
@codeui/styles/theme.cssfor token values, orall.cssfor the theme and components. Applications that author their own.css.tsfiles still configure a compiler for those files.
Why the root entry fails in a style file
vanilla-extract evaluates every .css.ts file in Node during the build. The root entry imports every component, and with them Solid, Kobalte and JSX. That component code does not evaluate in the style build, so a .css.ts file that imports from @codeui/solid breaks the build. The kit's fixture reproduced this failure before the tokens entry existed. The entry gives style files the token objects without the components.
tokens
import { tokens } from "@codeui/solid"; // in components
import { tokens } from "@codeui/solid/tokens"; // in .css.ts filesimport { Text, tokens } from "@codeui/solid";
export default function InlineStyle() {
return (
<div
style={{
padding: tokens.space["3"],
"border-radius": tokens.radius.card,
background: tokens.surface.input,
}}
>
<Text size="caption" tone="muted">
{tokens.surface.input}
</Text>
</div>
);
}tokens is a nested object with one leaf per --cui-* token, 129 in all. Its top-level groups are surface, text, action, shadow, border, accent, focus, radius, space, control, font and motion. Each leaf is the string var(--cui-<path>).
| Path | Value |
|---|---|
tokens.surface.canvas | "var(--cui-surface-canvas)" |
tokens.action.brandSoft.text | "var(--cui-action-brand-soft-text)" |
tokens.space["1.5"] | "var(--cui-space-1-5)" |
tokens.font.lineHeight.normal | "var(--cui-font-line-height-normal)" |
- A leaf is a reference, not a value. It resolves in the browser against the nearest
data-cui-themescope. To read the resolved value, callgetComputedStyle(element).getPropertyValue("--cui-surface-canvas"). - Numeric keys are strings. Write
tokens.space["2"], nottokens.space[2]. keyof typeof tokens.font.sizeandkeyof typeof tokens.font.weightare the types of thesizeandweightprops onText.
themeTokens
import { themeTokens } from "@codeui/solid";Deprecated. Use tokens. themeTokens keeps the scale names from before the --cui-* contract, so old style files keep compiling.
| Group | Points at |
|---|---|
fontSize | tokens.font.size: xs, sm, md, lg, xl. |
fontWeight | normal, medium and semibold point at tokens.font.weight. hairline, thin, light, bold, extrabold and black keep their old values. |
spacing | tokens.space. |
radii | tokens.radius. radii.default points at tokens.radius.lg. |
boxShadow | default, md and none point at tokens.shadow. lg, xl, 2xl, inner and outline keep their old values. |
colors | The Radix grayDark scale, with the old values. |
zIndex | -1, 0, 10, 20, 30, 40, 50 and auto, with the old values. |
The groups that keep their old values retain separate legacy variables. Their references are available from themeTokens. Prefer the semantic tokens roles for theme overrides.
themeVars
import { themeVars } from "@codeui/solid";Deprecated. Use tokens. themeVars keeps the color names from before the --cui-* contract. Each name points at the closest --cui-* role, so it follows the theme.
| Old name | Points at |
|---|---|
background | tokens.surface.canvas |
foreground | tokens.text.default |
brand | tokens.action.brand.base |
brandLink | tokens.accent.focus |
critical | tokens.action.danger.base |
caution | tokens.action.caution.base |
separator | tokens.border.divider |
dropdownBackground | tokens.surface.menu |
dialogBackground | tokens.surface.dialog |
dialogOverlayBackground | tokens.surface.scrim |
The table shows 10 of the 43 names. packages/kit/src/foundation/contract.css.ts lists all of them. accent8 and accent9 both point at tokens.text.muted.
breakpoints
import { breakpoints } from "@codeui/solid";import { Text, breakpoints } from "@codeui/solid";
import { For } from "solid-js";
export default function Breakpoints() {
return (
<table style={{ "border-collapse": "collapse", color: "var(--cui-text-default)" }}>
<tbody>
<For each={Object.entries(breakpoints)}>
{([name, width]) => (
<tr>
<td style={{ padding: "4px 16px 4px 0" }}>
<Text size="caption" weight="medium">
{name}
</Text>
</td>
<td style={{ padding: "4px 0" }}>
<Text size="caption" tone="muted">
{`min-width: ${width}px`}
</Text>
</td>
</tr>
)}
</For>
</tbody>
</table>
);
}breakpoints is a read-only object of minimum viewport widths in pixels. The values are numbers, so add the unit yourself, as in `(min-width: ${breakpoints.md}px)`.
xs is 0 and has no media query. responsiveStyle uses the other five.
layoutVars
import { layoutVars } from "@codeui/solid";
layoutVars.layoutBackgroundColor; // "var(--…)"layoutVars is a namespace with one member, layoutBackgroundColor. It is a stable CSS custom-property reference, unset by default.
Only one kit rule reads it. A Button with ghost and loading uses it as its background while the spinner shows, and falls back to the button's own background when it is unset. Set it on a container so that loading ghost buttons inside it match the surface they sit on:
vars: { [layoutVars.layoutBackgroundColor]: tokens.surface.canvas }The exported value gives the custom-property name as a var(--…) reference. Set that property in plain CSS or through your style system. It does not require a vanilla-extract runtime.
responsiveStyle
import { responsiveStyle } from "@codeui/solid/tokens";
responsiveStyle(style: {
xs?: CSSProps;
sm?: CSSProps;
md?: CSSProps;
lg?: CSSProps;
xl?: CSSProps;
"2xl"?: CSSProps;
}): StyleRule;responsiveStyle turns per-breakpoint styles into one vanilla-extract StyleRule. CSSProps is a StyleRule without @media and @supports.
xsstyles apply at every width, outside any media query.sm,md,lg,xland2xlgo intoscreen and (min-width: <width>px)queries, from thebreakpointsvalues. Larger widths come later, so they win.- An empty or missing breakpoint adds no query.
- Spread the result into
style(), asconsumer.css.tsabove does. A spread replaces any@mediakey you wrote before it, so put your own@mediaafter the spread, or pass everything throughresponsiveStyle.