WlColorPicker
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Colour swatch size.
Accessible color list name; falls back to WlConfig.locale.colorPalette (Palette in English).
Accessible HEX field name; falls back to WlConfig.locale.colorHex (Color HEX code in English).
Disables the palette and input.
External error state.
Enable an alpha channel in the selected color.
Allow entering a custom color beyond the swatch palette.
Choose a dataset or edit the array in the SFC below.
Props modelValue, swatches, pt, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
#3c6cff
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlColorPicker } from "legato-ui";
import { ref } from "vue";
const value = ref("#3c6cff");
</script>
<template>
<div class="wl-stack" data-space="md">
<WlColorPicker
v-model="value"
alpha
custom
palette-label="Material color"
input-label="Material color HEX code"
/>
<p class="wl-text-small" role="status">{{ value }}</p>
</div>
</template>Palette and HEX input
Custom swatches, sm/md, a normalised model, external invalid, disabled and the colour's text value.
Custom palette, sizes and HEX
Palette sm
Palette md
#rgb and #rrggbb input is normalized to lowercase #rrggbb. Invalid text marks the field and preserves the last valid model value.
External error and disabled
Approve the selected color before saving.
Unavailable color
Model value: #2563eb.
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlColorPicker } from "legato-ui";
import { ref } from "vue";
const color = ref("#2563eb");
const swatches = ["#2563eb", "#2e9e68", "#bf8615", "#d2494f", "#22252b", "#f7f7f8"];
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlColorPicker">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Custom palette, sizes and HEX" }}</h3>
<div class="wl-grid" data-space="lg">
<div
v-for="size in ['sm', 'md'] as const"
:key="size"
class="wl-stack"
data-space="sm"
><p class="wl-text-small">{{ "Palette" }} {{ size }}</p><WlColorPicker
v-model="color"
:size="size"
:swatches="swatches"
:palette-label="`${'Material color, '}${size}`"
:input-label="`${'Material color HEX, '}${size}`"
/></div>
</div>
<p class="wl-text-small wl-text-muted">{{ "#rgb and #rrggbb input is normalized to lowercase #rrggbb. Invalid text marks the field and preserves the last valid model value." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "External error and disabled" }}</h3>
<div class="wl-grid" data-space="lg">
<div
class="wl-stack"
data-space="sm"
role="group"
aria-label="Color with an external error"
aria-describedby="docs-color-error"
>
<WlColorPicker
v-model="color"
:swatches="swatches"
invalid
palette-label="Palette with an error"
input-label="HEX with an error"
/>
<p id="docs-color-error" class="wl-text-small" role="alert">{{ "Approve the selected color before saving." }}</p>
</div>
<div class="wl-stack" data-space="sm"><p class="wl-text-small">{{ "Unavailable color" }}</p><WlColorPicker
model-value="#2e9e68"
:swatches="swatches"
disabled
palette-label="Unavailable palette"
input-label="Unavailable HEX"
/></div>
</div>
<div class="wl-inline" data-space="sm">
<span class="docs-color-preview" :style="{ backgroundColor: color }" aria-hidden="true"></span>
<WlButton size="sm" @click="color = '#2563eb'">{{ "Reset color" }}</WlButton>
</div>
<p class="wl-text-small" role="status">{{ "Model value:" }} {{ color }}.</p>
</section>
</div>
</template>
<style scoped>
.docs-color-preview {
width: var(--wl-space-xl);
height: var(--wl-space-xl);
border: 1px solid var(--wl-border);
border-radius: var(--wl-radius-sm);
}
</style>