Skip to content

Build your own look ​

What vue-xr-ui is really for is the behaviour: every control works with the mouse, a controller ray, a pinch and a fingertip poke, captures the pointer while pressed, never selects on a drag, takes keyboard focus and respects open dialogs. The look is yours to change, in three steps from small to total.

1. A theme ​

Colours, radius, spacing and type for everything at once, and through its components styles, the shape of every component and its parts. A theme alone gives four looks as different as Neon and Brutal: see Design systems and Theming.

2. ui and parts ​

ui takes raw uikit properties for a component's outer element, merged last. parts does the same for its inner parts, by name:

vue
<XrSlider
  v-model="volume"
  :parts="{
    track: { height: 4, borderWidth: 0 },
    fill: { backgroundColor: '#f59e0b' },
    thumb: { width: 14, borderRadius: 3 },
  }"
/>

Every component with inner parts lists them in its API table, under parts:

ComponentParts
<XrButton>label, icon
<XrCheckbox>box, mark, label
<XrToggle>track, thumb, label
<XrRadioGroup>option, circle, dot, label, description
<XrSlider>track, fill, thumb
<XrProgress>label, value, track, fill, ring, dot
<XrSelect>trigger, value, chevron, popup, option
<XrTabs>tab, selected, label
<XrListItem>label, description
<XrTextField>input
<XrNumberInput>decrement, increment, field, suffix
<XrTooltip>bubble, label
<XrDialog>header, title, close, actions
<XrWindow>handle, bar
<XrKeyboard>key, accent, label
<XrSessionMenu>hint, stay, exit

Part values win over the component's own, including its states: give hover or active in a part to change those too. The merge is shallow: a part's active replaces the default active entirely, and on most controls that holds the sink on press (transformTranslateZ), the only feedback a fingertip gets. Keep it in yours: active: { backgroundColor: '#333', transformTranslateZ: -4 }. A few values stay the component's own because they carry its state: the slider's fill width and thumb position, the select list's display, and the pointer handlers. The rest (<XrBox>, <XrText>, <XrPanel>, ...) is one element: ui covers it.

3. Headless composables ​

When the shape itself is different, keep the behaviour and draw the rest with <XrBox>. A composable takes a template ref to the box that receives presses and focus, and gives back state and pointer handlers to spread into that box's ui:

vue
<script setup lang="ts">
import { ref, useTemplateRef } from 'vue'
import { XrBox, useXrCheckbox } from 'vue-xr-ui'

const lights = ref(true)
const box = useTemplateRef('box')
const lightsSwitch = useXrCheckbox({
  target: box,
  modelValue: lights,
  onUpdate: (value) => (lights.value = value),
})
</script>

<template>
  <XrBox
    ref="box"
    direction="row"
    :ui="{
      ...lightsSwitch.handlers,
      width: 72,
      height: 40,
      padding: 4,
      justifyContent: lights ? 'flex-end' : 'flex-start',
      backgroundColor: lights ? '#16a34a' : '#3f3f46',
    }"
  >
    <XrBox :ui="{ width: 32, height: 32, backgroundColor: '#fafafa' }" />
  </XrBox>
</template>

Tab reaches it and draws the focus ring around it (pass ring: false and use focused to show focus your own way); Enter and Space flip it.

ComposableGives you
useXrCheckboxchecked, indeterminate, handlers, focused, toggle()
useXrSlidervalue, fraction (0 to 1, for the fill or thumb), dragging, handlers, focused, stepBy()
useXrSelectopen, selected, triggerHandlers, optionHandlers(option), choose(), setOpen(), focused
useXrPresspointer handlers for anything pressable: a press is a down and an up from the same pointer
useXrFocusableTab, the focus ring and Enter/arrow keys for any box

useXrSlider maps values across track (a second template ref) or, by default, across the target. useXrSelect closes on a press outside the trigger and the elements you pass as inside (your list), and on Escape. Its list is yours to place: inline under the trigger, or in an <XrDialog>. The floating layer of <XrSelect>, which is not clipped by a scrolling list around it, is not public yet.

All of them are in the composables reference.

MIT License