Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createTokens

Design token registry with hierarchical collections, alias resolution, and namespace support.

Usage

The createTokens composable allows you to define a collection of design tokens, which can be primitive values or aliases that reference other tokens. It provides a context for resolving these tokens, making it easy to access design values throughout your application.

ts
import { createTokens } from '@vuetify/v0'

// Default behavior (depth = Infinity): fully flatten nested objects
const tokens = createTokens({
  color: {
    primary: '#3b82f6',
    secondary: '#64748b',
    info: '{primary}'
  },
  radius: {
    sm: '4px',
    md: '8px',
  },
})

tokens.resolve('color.primary') // '#3b82f6'
tokens.resolve('color.info') // '#3b82f6' (alias resolved)
tokens.resolve('radius.md') // '8px'

const features = createTokens({
  dark: true,
  rtl: { value: true, variation: 'toggle' },
}, { flat: true })

// With flat: true, nested objects are kept as-is at their base id
features.resolve('rtl') // { value: true, variation: 'toggle' }

Context / DI

Use createTokensContext to share a token registry across a component tree:

ts
import { createTokensContext } from '@vuetify/v0'

export const [useTokens, provideTokens, tokens] =
  createTokensContext({
    namespace: 'my:tokens',
    tokens: {
      colors: {
        primary: '#3b82f6',
        secondary: '{colors.primary}',  // alias
      },
    },
  })

// In parent component
provideTokens()

// In child component
const tokens = useTokens()
tokens.resolve('colors.primary')  // '#3b82f6'

Options

createTokens

OptionTypeDefaultNotes
flatbooleanfalseKeep nested objects as-is at their base key instead of flattening
prefixstringPrepend a string to every token ID on registration (e.g. 'color.')

createTokensContext

Accepts all createTokens options plus:

OptionTypeDefaultNotes
namespacestringDI namespace string (e.g. 'my:tokens')
tokensTokenCollectionInitial token collection registered when the context is created

Architecture

createTokens extends createRegistry and powers token-based systems:

Reactivity

createTokens uses minimal reactivity like its parent createRegistry. Token resolution is cached but not reactive.

Tip

For reactive theming Use useTheme which builds on createTokens with proper reactivity for theme switching.

Examples

FAQ

API Reference

The following API details are for the createTokens composable.

Benchmarks

Every operation is profiled across multiple dataset sizes to measure real-world throughput. Each benchmark is assigned a performance tier—good, fast, blazing, or slow—and groups are scored by averaging their individual results so you can spot bottlenecks at a glance. This transparency helps you make informed decisions about which patterns scale for your use case. Learn more in the benchmarks guide.

View benchmark source↗

Was this page helpful?

Ctrl+/