Design systems
The components carry the behaviour (input, focus, states, layout). The look is data: a theme. The scene below is the same set of components, untouched, under five themes. Pick one at the top.
Neon, Glass, Brutal and Clay ship with the library as themePresets. They are not special: each is a plain ThemeTokens object, written with defineTheme, that you can copy and change. The playground has the same switcher for every component it shows: open it.
What a theme can change
| Layer | Changes | Example |
|---|---|---|
colors | Every surface, text, accent and state colour | Ink on paper, neon on black |
radius | Corner radii, from square to pill | { sm: 0, md: 0, lg: 0, full: 0 } |
typography | Sizes, line heights and weights per text style | Bold labels |
interaction | Target size, how far a press sinks, hover scale | pressDepth: 12 for a deep press |
components | Raw uikit properties per component and per part | Thick borders, a diamond slider thumb, raised buttons |
components is what turns a palette into a design system. For each component it takes ui (its outer element) and parts (its named inner parts, the same names as the parts prop), merged under what an instance passes:
import { darkTheme, defineTheme } from 'vue-xr-ui'
export const neon = defineTheme(darkTheme, {
name: 'neon',
colors: { surface: '#0a0518', border: '#ff2bd6', primary: '#22e8ff', onPrimary: '#06030f' },
radius: { sm: 2, md: 3, lg: 4, full: 4 },
components: {
XrPanel: { ui: { borderWidth: 2 } },
XrSlider: {
parts: {
track: { height: 4, borderWidth: 0 },
thumb: { width: 18, height: 18, backgroundColor: '#ff2bd6', transformRotateZ: 45 },
},
},
},
})When a style depends on the instance, give a function of its props:
components: {
// A hard offset shadow, drawn as thicker right and bottom borders.
XrButton: (props) => ({
ui: props.variant === 'ghost' ? {} : { borderWidth: 3, borderRightWidth: 6, borderBottomWidth: 6, borderColor: '#111' },
}),
XrText: (props) => (props.variant === 'title' ? { ui: { letterSpacing: 3 } } : {}),
}Order of merging, last wins: the component's own defaults, then the theme's components entry, then the instance's ui and parts. One level deep, as with parts: a hover or active you give replaces the component's for that element, so keep transformTranslateZ in an active you write (it is the only feedback a fingertip gets).
Two things to keep in mind when writing one:
- A colour you set wins over the colour the component picks for its state: a fixed
borderColoron a text field or a select trigger hides their focused and open outline. Set widths there and letcolorsgive the colour, and checkprops.disabledin a function style. - Components are built from other components: a checkbox's box is an
<XrBox>, every label an<XrText>, a number input's steppers are<XrButton>s, a select's list and a dialog's body are<XrPanel>s. A theme entry forXrBoxorXrTextreaches those too, so keep layout (padding, sizes) out of those two and style the parts instead.
Using one
For the whole app:
import { createXrUi, themePresets } from 'vue-xr-ui'
app.use(createXrUi({ theme: themePresets.brutal }))Switch at runtime, as the demo above does:
const theme = useXrTheme()
theme.value = themePresets.glassOr for one part of the scene, with <XrThemeProvider :theme="themePresets.clay">.
The four presets
| Preset | Look | Built with |
|---|---|---|
neonTheme | Near-black, cyan and magenta outlines, sharp corners, spaced headings | Colours, small radii, borders on panels and controls, a diamond slider thumb, letterSpacing on titles |
glassTheme | Translucent smoked panels, bright bent edges, pills, white selection | Translucent colours, large radii, borderBend on edges |
brutalTheme | Cream paper, black ink, square corners, hard offset shadows | Square radii, bold type, thick right and bottom borders as shadows |
clayTheme | Soft pastels, very round, controls raised off the panel that sink deep | transformTranslateZ on buttons and tabs, pressDepth: 12, a soft bottom edge |
Further than a theme
A theme restyles every instance. For one instance, use its ui and parts props; for a control whose shape is different altogether, build it with <XrBox> and the headless composables. All three: Build your own look.