WlColorPicker

Colour selection from a palette or HEX code. Values are normalised to lowercase #rrggbb.
Components / Inputs v0.1.0

Appearance

#3c6cff

Full example
<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>

Example data

#3c6cff

Full example
<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>

States

#3c6cff

Full example
<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>

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

Unavailable color

Model value: #2563eb.

Full 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-subheading">{{ "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-subheading">{{ "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>