Skip to content

Tokens ​

@vue-xr-ui/tokens holds the themes and the helpers to make your own. It has no Vue or three.js dependency, so a design tool or a server can use it too. vue-xr-ui re-exports all of it.

ts
import { darkTheme, lightTheme, withAccent, defineTheme } from 'vue-xr-ui'

Units ​

Lengths are in dmm: 1 dmm is 1 mm seen from 1 m away. A panel twice as far is drawn twice as large, so it keeps the same angular size and the same readability. See Core concepts.

Themes ​

darkTheme (the default) and lightTheme are ThemeTokens:

GroupTypeDescription
namestring
colorsColorTokensThe colours below.
radius{ sm, md, lg, full }Corner radii, dmm. Dark and light: 8, 16, 24, 999.
spacereadonly number[]Spacing scale, dmm, by step: 0, 4, 8, 12, 16, 24, 32, 48, 64.
typography{ caption, body, label, title, headline }Each a TypeStyle: fontSize (dmm), lineHeight, fontWeight. 14, 18, 18, 24, 32 dmm.
interaction{ minTarget, pressDepth, hoverScale }minTarget (48 dmm) is the smallest control that is easy to hit with a ray or poke with a finger; pressDepth (4 dmm) is how far a pressed control sinks; hoverScale (1.03).
viewingDistancenumberMetres at which panels are designed to be read (1).
componentsComponentStyles (optional)Per component: ui and parts (raw uikit properties), or a function of the instance's props returning them. Merged under each instance's own. See Design systems.

Presets ​

neonTheme, glassTheme, brutalTheme and clayTheme (also as themePresets.neon, .glass, .brutal, .clay) are complete themes, components included. See them live in Design systems.

Colours ​

TokenUsed for
surface, surfaceRaised, surfaceSunkenPanel background; cards and inputs on it; wells and tracks.
borderOutlines and dividers.
text, textMutedBody text; secondary text and placeholders.
primary, primaryHover, primaryActive, onPrimaryThe accent: primary buttons, selected states, slider fill; text on it.
secondary, secondaryHover, secondaryActive, onSecondarySecondary buttons.
ghostHover, ghostActiveGhost buttons, list rows.
dangerDestructive actions and errors.
focusRingThe focus ring.
disabled, onDisabledDisabled controls and their text.
scrimWhat dims the scene behind a modal <XrDialog>.

Helpers ​

withAccent(theme, accent) ​

ts
function withAccent(theme: ThemeTokens, accent: string): ThemeTokens

The theme with its accent replaced, from one hex colour: hover a little lighter, pressed a little darker, white or near-black text on it (whichever keeps a 3:1 contrast), and a focus ring that reads on the theme.

ts
const green = withAccent(darkTheme, '#22c55e')

defineTheme(base, overrides) ​

ts
function defineTheme(
  base: ThemeTokens,
  overrides: DeepPartial<Omit<ThemeTokens, 'components'>> & { name: string; components?: ComponentStyles },
): ThemeTokens

A new theme from base with overrides merged one level deep per group (colors, radius, typography, interaction, components, by component name); space is replaced as a whole.

ts
const brand = defineTheme(lightTheme, {
  name: 'brand',
  colors: { primary: '#e11d48', surface: '#fff7ed' },
  radius: { md: 8 },
})

contrastRatio(a, b) ​

ts
function contrastRatio(a: string, b: string): number

The WCAG contrast ratio of two hex colours, from 1 to 21. Text wants 4.5 or more; large text and controls 3 or more.

pixelSizeAt(distance) ​

ts
function pixelSizeAt(distance: number): number

World units (metres) per dmm for a panel distance metres away: 0.001 * distance. Components do this for you; use it to size your own meshes in dmm.

MIT License