Skip to Content
CodeUI

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.

ExportStatusWhat it holds
tokensCurrentEvery --cui-* token, by role.
themeTokensDeprecatedThe old scale names.
themeVarsDeprecatedThe old color names.
breakpointsCurrentViewport widths in pixels.
layoutVarsCurrentOne layout variable, layoutBackgroundColor.
responsiveStyleCurrentA helper that writes min-width media queries.

The @codeui/solid/tokens entry

consumer.css.ts
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, layoutVars and responsiveStyle. Nothing else.
  • Parity with the root. @codeui/solid re-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-js or @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.css for token values, or all.css for the theme and components. Applications that author their own .css.ts files 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 files
var(--cui-surface-input)
token-exports/inline-style.tsx
import { 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>).

PathValue
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-theme scope. To read the resolved value, call getComputedStyle(element).getPropertyValue("--cui-surface-canvas").
  • Numeric keys are strings. Write tokens.space["2"], not tokens.space[2].
  • keyof typeof tokens.font.size and keyof typeof tokens.font.weight are the types of the size and weight props on Text.

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.

GroupPoints at
fontSizetokens.font.size: xs, sm, md, lg, xl.
fontWeightnormal, medium and semibold point at tokens.font.weight. hairline, thin, light, bold, extrabold and black keep their old values.
spacingtokens.space.
radiitokens.radius. radii.default points at tokens.radius.lg.
boxShadowdefault, md and none point at tokens.shadow. lg, xl, 2xl, inner and outline keep their old values.
colorsThe 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 namePoints at
backgroundtokens.surface.canvas
foregroundtokens.text.default
brandtokens.action.brand.base
brandLinktokens.accent.focus
criticaltokens.action.danger.base
cautiontokens.action.caution.base
separatortokens.border.divider
dropdownBackgroundtokens.surface.menu
dialogBackgroundtokens.surface.dialog
dialogOverlayBackgroundtokens.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";
xsmin-width: 0px
smmin-width: 640px
mdmin-width: 768px
lgmin-width: 1024px
xlmin-width: 1280px
2xlmin-width: 1536px
token-exports/breakpoints.tsx
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.

  • xs styles apply at every width, outside any media query.
  • sm, md, lg, xl and 2xl go into screen and (min-width: <width>px) queries, from the breakpoints values. Larger widths come later, so they win.
  • An empty or missing breakpoint adds no query.
  • Spread the result into style(), as consumer.css.ts above does. A spread replaces any @media key you wrote before it, so put your own @media after the spread, or pass everything through responsiveStyle.

On this page