Keyboard shortcut: Ctrl + K
Get started

Colour picker

VColorPicker chooses a colour with a saturation and brightness area, a hue track and a text field that accepts hex, rgb(), hsl() and oklch(). Its tracks are native ranges, so assistive technology adjusts each channel on its own.

Usage

vue
#3b82f6
<script setup lang="ts">
import { ref } from 'vue'
import { VColorPicker } from 'vectis-ui'

const color = ref<string | null>('#3b82f6')
</script>

<template>
  <div class="row">
    <VColorPicker v-model="color" />
    <code>{{ color }}</code>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--vectis-space-4);
}
</style>

Examples

Formats

format decides how the value is written: hex, rgb, hsl or oklch. The menu beside the field changes only what the field shows. The picker works in sRGB and clips an oklch() colour outside it.

vue
oklch(62.3% 0.188 259.8)
<script setup lang="ts">
import { ref } from 'vue'
import { VColorPicker } from 'vectis-ui'

const color = ref<string | null>('oklch(62.3% 0.188 259.8)')
</script>

<template>
  <div class="row">
    <VColorPicker v-model="color" format="oklch" />
    <code>{{ color }}</code>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--vectis-space-4);
}
</style>

Opacity

alpha adds an opacity track. The alpha is written into the value only below 1.

vue
rgb(59 130 246 / 0.6)
<script setup lang="ts">
import { ref } from 'vue'
import { VColorPicker } from 'vectis-ui'

const color = ref<string | null>('rgb(59 130 246 / 0.6)')
</script>

<template>
  <div class="row">
    <VColorPicker v-model="color" format="rgb" alpha />
    <code>{{ color }}</code>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--vectis-space-4);
}
</style>

Swatches

swatches offers preset colours as native radios. Give { color, label } to name a swatch for screen readers.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VColorPicker } from 'vectis-ui'
import type { ColorSwatch } from 'vectis-ui'

const color = ref<string | null>('#0ea5e9')
const swatches: ColorSwatch[] = [
  { color: '#0ea5e9', label: 'Ocean' },
  { color: '#16a34a', label: 'Forest' },
  { color: '#f59e0b', label: 'Sun' },
  '#e11d48',
  '#7c3aed',
  '#0f172a',
]
</script>

<template>
  <VColorPicker v-model="color" :swatches="swatches" label="Brand colours" />
</template>

API

Props

PropTypeDefault
formatColorFormat'hex' | 'rgb' | 'hsl' | 'oklch''hex'
How the value is written. The text field accepts all four formats.
alphabooleanfalse
Adds an opacity track and writes the alpha below 1.
swatchesColorSwatch[]none
Preset colours: a colour string or { color, label }.
hideInputbooleanfalse
Hides the text field and its format menu.
hideEyeDropperbooleanfalse
Hides the eyedropper button, otherwise shown where the browser supports the EyeDropper API.
disabledbooleanfalse
Disables every control.
labelstringnone
Accessible name of the picker. Defaults to the library dictionary.
namestringnone
Field name in form submissions, through a hidden input.
v-modelstring | nullnull
Colour written in format, or null before one is chosen.

Types

Types used in the API tables. Import exported types from vectis-ui.

export type ColorSwatch = string | { color: string; label: string }

CSS variables

TokenValue
--vectis-control-size-color-picker-width16rem
--vectis-control-size-color-picker-area10rem
--vectis-control-size-color-picker-track0.75rem
--vectis-control-size-color-picker-thumb1rem
--vectis-control-size-color-picker-preview2rem
--vectis-control-size-color-picker-swatch1.5rem
--vectis-control-size-color-picker-checker0.5rem