Use it for
Use BbColorPalette when the palette is the interface: a theme editor, a brand settings panel, or a wizard step.
Use something else when
BbColorPicker— the palette opens from a dot, chip or row you own and closes after the pickBbColorPickerInput— the colour is a labelled form field, with hex text people can type
BbColorPalette is the colour square, hue slider, swatches and eyedropper that BbColorPicker opens in its popover, rendered in the page. It has no label, hint or error chrome: name it with aria-label.
Coming from v2#activator → BbColorPicker
In v2, BbColorPalette was the popover with an #activator slot. That component is BbColorPicker now. npx bitboss-ui check reports activator or #activator on BbColorPalette: rename the tag.
Passthrough
Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.
A theme editor
Bind a seeded string | null model and repaint the preview from it. Save on value-commit, which fires once per finished drag, key step or swatch pick.
Workspace accent
Saved #4f46e5
<template>
<div
class="grid w-fit gap-4 rounded-[var(--bb-radius)] border border-[color:var(--bb-border)] p-4"
>
<div>
<p class="m-0 text-sm font-medium">Workspace accent</p>
<p class="m-0 text-xs text-[color:var(--bb-text-muted)]" role="status">
{{ status }}
</p>
</div>
<!--
The preview shows the customer portal, which is light whatever the
docs theme, so it has a fixed surface of its own. It repaints from
the model on every drag frame.
-->
<div
class="flex items-center gap-4 rounded-[var(--bb-radius)] border border-[color:var(--bb-border)] bg-white p-3 text-sm text-zinc-900"
>
<span
class="rounded-[var(--bb-radius)] px-3 py-1.5 font-medium"
:style="{ backgroundColor: accent ?? '#e4e4e7', color: textOn(accent) }"
>
Book a demo
</span>
<span class="underline" :style="{ color: accent ?? undefined }">View pricing</span>
</div>
<!-- The palette IS the control: nothing to open or close. -->
<BbColorPalette
v-model="accent"
aria-label="Workspace accent"
swatches
@value-commit="onSave"
/>
</div>
</template>
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue';
import { BbColorPalette } from 'bitboss-ui';
const accent = ref<string | null>('#4f46e5');
const status = ref('Saved #4f46e5');
let timer: ReturnType<typeof setTimeout> | undefined;
/*
* `v-model` moves on every drag frame; `value-commit` fires once per finished
* drag, key step or swatch pick, so it is the one place that saves (simulated).
*/
const onSave = (value: string) => {
status.value = 'Saving…';
clearTimeout(timer);
timer = setTimeout(() => (status.value = `Saved ${value}`), 600);
};
onBeforeUnmount(() => clearTimeout(timer));
const textOn = (hex: string | null) => {
if (hex === null) return '#111827';
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
return 0.299 * r! + 0.587 * g! + 0.114 * b! > 150 ? '#111827' : '#ffffff';
};
</script>
The model is lowercase #RRGGBB. null shows an empty palette, but every pick is a concrete colour, so clearing back to null is your own action.
Presets, transparency and the eyedropper
Offer your colours as swatches, turn on alpha when the value can carry opacity, and add eye-dropper to sample a colour from the screen.
#fde04799
<template>
<div class="grid w-fit gap-3">
<!-- Checkerboard behind the fill, so the alpha channel is visible. -->
<div class="preview">
<div class="preview__fill" :style="{ backgroundColor: tint ?? 'transparent' }">
Highlighted passage
</div>
</div>
<!--
The eyedropper button renders only where the browser has the native
EyeDropper API: on Firefox and Safari the swatches and the square are
the whole palette.
-->
<BbColorPalette
v-model="tint"
alpha
aria-label="Highlight tint"
eye-dropper
:swatches="SWATCH_COLUMNS"
/>
<p class="m-0 text-xs tabular-nums text-[color:var(--bb-text-muted)]">{{ tint }}</p>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { BbColorPalette } from 'bitboss-ui';
// Each inner array is a COLUMN of shades: ramps are designed vertically.
const SWATCH_COLUMNS: string[][] = [
['#fef9c3', '#fde047', '#eab308'],
['#dcfce7', '#86efac', '#22c55e'],
['#e0f2fe', '#7dd3fc', '#0ea5e9'],
];
// With `alpha` the model carries an 8-digit #RRGGBBAA value.
const tint = ref<string | null>('#fde04799');
</script>
<style scoped>
.preview {
height: 3.5rem;
border: 1px solid var(--bb-border);
border-radius: var(--bb-radius);
overflow: hidden;
background-image:
linear-gradient(45deg, var(--bb-muted) 25%, transparent 25%),
linear-gradient(-45deg, var(--bb-muted) 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, var(--bb-muted) 75%),
linear-gradient(-45deg, transparent 75%, var(--bb-muted) 75%);
background-position:
0 0,
0 6px,
6px -6px,
-6px 0;
background-size: 12px 12px;
}
.preview__fill {
display: grid;
height: 100%;
width: 100%;
place-items: center;
color: var(--bb-text);
font-weight: 500;
}
</style>
Each inner array of swatches is a column, and the whole grid is one Tab stop that the arrow keys move through. With alpha the model is #RRGGBBAA; without it, an eight-digit value loses its opacity. The eyedropper button exists only where the browser has the native API, and a sampled colour is always opaque.
Locked and disabled
readonly keeps the square, sliders and swatches focusable while nothing changes the value. Use it for a colour people may read but not edit.
<template>
<div class="grid w-fit gap-3">
<BbSwitch id="brand-locked" v-model="locked" compact label="Brand locked" name="brand-locked" />
<!-- Read-only: the square and sliders stay focusable, nothing changes the value. -->
<BbColorPalette
v-model="brand"
aria-label="Brand colour"
:readonly="locked"
:swatches="BRAND_COLUMNS"
/>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { BbColorPalette, BbSwitch } from 'bitboss-ui';
const BRAND_COLUMNS: string[][] = [
['#0f172a', '#334155', '#64748b'],
['#1d4ed8', '#2563eb', '#60a5fa'],
['#b91c1c', '#dc2626', '#f87171'],
];
const locked = ref(true);
const brand = ref<string | null>('#2563eb');
</script>
disabled takes every control out of the tab order, and so does a <fieldset disabled> around the palette.
Styling
The root paints nothing: add the border and padding on pt:root, and shape the swatches on pt:swatch. --mark is the ring on the chosen swatch (default --bb-accent).
<template>
<!--
The palette's root paints nothing, so the border and padding are added
on `pt:root`, along with `--mark`, the ring on the chosen swatch.
-->
<BbColorPalette
v-model="color"
aria-label="Tag colour"
pt:root="rounded-[var(--bb-radius)] border border-[color:var(--bb-border)] p-3 [--mark:var(--bb-success)]"
pt:swatch="rounded-full"
:swatches="TAG_COLUMNS"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { BbColorPalette } from 'bitboss-ui';
const TAG_COLUMNS: string[][] = [
['#f97316', '#ea580c'],
['#14b8a6', '#0d9488'],
['#8b5cf6', '#7c3aed'],
['#ec4899', '#db2777'],
];
const color = ref<string | null>('#14b8a6');
</script>
pt:swatch:selected styles the swatch that matches the value, and pt:root:disabled the whole palette while it is disabled.