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.
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:
| Group | Type | Description |
|---|---|---|
name | string | |
colors | ColorTokens | The colours below. |
radius | { sm, md, lg, full } | Corner radii, dmm. Dark and light: 8, 16, 24, 999. |
space | readonly 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). |
viewingDistance | number | Metres at which panels are designed to be read (1). |
components | ComponentStyles (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
| Token | Used for |
|---|---|
surface, surfaceRaised, surfaceSunken | Panel background; cards and inputs on it; wells and tracks. |
border | Outlines and dividers. |
text, textMuted | Body text; secondary text and placeholders. |
primary, primaryHover, primaryActive, onPrimary | The accent: primary buttons, selected states, slider fill; text on it. |
secondary, secondaryHover, secondaryActive, onSecondary | Secondary buttons. |
ghostHover, ghostActive | Ghost buttons, list rows. |
danger | Destructive actions and errors. |
focusRing | The focus ring. |
disabled, onDisabled | Disabled controls and their text. |
scrim | What dims the scene behind a modal <XrDialog>. |
Helpers
withAccent(theme, accent)
function withAccent(theme: ThemeTokens, accent: string): ThemeTokensThe 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.
const green = withAccent(darkTheme, '#22c55e')defineTheme(base, overrides)
function defineTheme(
base: ThemeTokens,
overrides: DeepPartial<Omit<ThemeTokens, 'components'>> & { name: string; components?: ComponentStyles },
): ThemeTokensA 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.
const brand = defineTheme(lightTheme, {
name: 'brand',
colors: { primary: '#e11d48', surface: '#fff7ed' },
radius: { md: 8 },
})contrastRatio(a, b)
function contrastRatio(a: string, b: string): numberThe 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)
function pixelSizeAt(distance: number): numberWorld 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.