skip section navigation

ColorPicker

ColorPicker edits an sRGB color and exposes a HEX string to your app. the popup combines a visual picker, HEX entry and channel editors, so people can use the input that fits the color they have.

Saved color: #4273FA

usage

svelte
<script>
	import { ColorPicker, Field, FieldLabel } from '@ciabi/loafkit-ui';
	let accent = $state('#4273FA');
</script>

<Field>
	<FieldLabel htmlFor="collection-color">Collection color</FieldLabel>
	<ColorPicker id="collection-color" bind:value={accent} aria-label="Collection color" />
</Field>
<p>Saved color: {accent}</p>

value and form behavior

committed edits update value and call onValueChange(value) with a normalized six-digit HEX string. alpha isn’t part of this API.

the ID identifies the trigger; connect its visible label and any guidance explicitly. name supplies a hidden form value. your form still owns validation rules and error messages.

try the editing modes

the eyedropper appears only where the browser supports it; HEX entry remains available without it.

save a committed color

last committed edit: #566B3A

svelte
<script lang="ts">
import { ColorPicker, Field, FieldLabel } from '@ciabi/loafkit-ui';
let formAccent = $state('#566B3A');
let committedAccent = $state('#566B3A');
let submittedAccent = $state('');
</script>

<form onsubmit={event => {
	event.preventDefault();
	submittedAccent = String(new FormData(event.currentTarget).get('accent'));
}}>
	<Field><FieldLabel htmlFor="color-form-accent">reading room accent</FieldLabel>
		<ColorPicker id="color-form-accent" name="accent" aria-label="reading room accent" bind:value={formAccent} onValueChange={value => committedAccent = value} />
	</Field>
	<p role="status">last committed edit: {committedAccent}</p>
	<button type="submit">save accent</button>
</form>
{#if submittedAccent}<p role="status">submitted accent: {submittedAccent}</p>{/if}

API reference

ColorPicker

Component
value
Default: '#4273FA'

committed normalized six-digit sRGB HEX color.

name

name for the hidden committed-color form value.

id

the trigger ID for an explicit label relationship.

aria-label

an explicit accessible name.

aria-describedby

IDs of supporting descriptions.

disabled
Default: false

makes the control unavailable.

required
Default: false

uses native required-value validation.

invalid
Default: false

marks the visual invalid state; your app supplies validation.

class
Default: ''

extra classes on the component root.

style

inline styles on the component root.

onValueChange

called with a committed normalized HEX color.