Skip to content

@mfe-forge/design ​

Shared design tokens for MFE Forge, plus a helper that writes them to the DOM as CSS custom properties. The package has no runtime dependencies and no React dependency.

For guidance on theming and sharing tokens between micro frontends, see the Design system guide.

Install ​

bash
bun add @mfe-forge/design
# or: npm install @mfe-forge/design
RequirementValue
Module formatESM only ("type": "module")
Node.js>=20.0.0
Peer dependenciesNone
Side effectsNone ("sideEffects": false)

Entry points ​

Import pathExports
@mfe-forge/designtokens, applyTokens, type TokenPath
@mfe-forge/design/tokenstokens, type TokenPath

Use the /tokens subpath when you only need the values (for example in a build script or a Tailwind/CSS generator) and want to avoid importing anything that touches document.

API ​

tokens ​

ts
const tokens: {
  readonly colors: { readonly [name: string]: string }
  readonly radius: {
    readonly sm: string
    readonly md: string
    readonly lg: string
    readonly xl: string
  }
  readonly font: { readonly sans: string; readonly mono: string }
  readonly spacing: {
    readonly xs: string
    readonly sm: string
    readonly md: string
    readonly lg: string
    readonly xl: string
    readonly '2xl': string
  }
}

A plain object declared as const, so every value is typed as its literal string. It is the single source of truth for the default MFE Forge theme.

ts
import { tokens } from '@mfe-forge/design'

tokens.colors.primary // 'oklch(0.82 0.2 128)'
tokens.spacing.lg // '1.5rem'
tokens.colors['muted-foreground'] // hyphenated keys need bracket access

applyTokens(element?) ​

ts
function applyTokens(element?: HTMLElement): void
ParameterTypeDefaultDescription
elementHTMLElementdocument.documentElementElement whose inline style receives the custom properties.

Calls element.style.setProperty() for:

  • every entry in tokens.colors as --color-<name>
  • every entry in tokens.radius as --radius-<name>
  • --font-sans and --font-mono

Behavior notes:

  • Spacing is not applied. tokens.spacing has no CSS variables; read it from the tokens object.
  • The properties are set as inline styles, so they override stylesheet declarations of the same custom property on that element.
  • The default parameter reads document, so calling applyTokens() with no argument outside a browser or DOM test environment throws a ReferenceError. Passing an element avoids that.
  • It is idempotent; calling it again rewrites the same values.
ts
import { applyTokens } from '@mfe-forge/design'

// Globally, once, in the host bootstrap
applyTokens()

// Or scoped to a remote's root element
applyTokens(document.getElementById('checkout-root')!)
css
.card {
  background: var(--color-card);
  color: var(--color-card-foreground);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
}

TokenPath ​

ts
type TokenPath = keyof typeof tokens // 'colors' | 'radius' | 'font' | 'spacing'

Despite the name, this is the set of top-level token groups, not a dotted path such as 'colors.primary'.

Token reference ​

The default palette is a single dark theme. There is no light variant in the package.

Colors ​

Token keyCSS variableValue
background--color-backgroundoklch(0.145 0 0)
foreground--color-foregroundoklch(0.985 0 0)
card--color-cardoklch(0.205 0 0)
card-foreground--color-card-foregroundoklch(0.985 0 0)
border--color-borderoklch(0.295 0 0)
input--color-inputoklch(0.295 0 0)
primary--color-primaryoklch(0.82 0.2 128)
primary-foreground--color-primary-foregroundoklch(0.145 0 0)
muted--color-mutedoklch(0.205 0 0)
muted-foreground--color-muted-foregroundoklch(0.556 0 0)
destructive--color-destructiveoklch(0.577 0.245 27.33)
ring--color-ringoklch(0.556 0 0)

Radius ​

Token keyCSS variableValue
sm--radius-sm0.25rem
md--radius-md0.5rem
lg--radius-lg0.75rem
xl--radius-xl1rem

Font ​

Token keyCSS variableValue
sans--font-sans"Inter", system-ui, sans-serif
mono--font-mono"JetBrains Mono", monospace

The package does not load Inter or JetBrains Mono; include the font files yourself or rely on the fallbacks.

Spacing ​

Not emitted by applyTokens.

Token keyValue
xs0.25rem
sm0.5rem
md1rem
lg1.5rem
xl2rem
2xl3rem

Released under the MIT License.