Skip to content
tcpsystemsui

Theme

Colour scheme
Accent
Density
Radius
Esc

ColorInput

A colour picker with an editable hex value and optional swatches.

beta

Try it

Svelte
<ColorInput label="Project accent" value="#336699" />

Examples

Accent colour

Accent colour.svelte
<script lang="ts">
	import '@tcpsystems/ui/foundation/elements/color';
	import ColorInput from '@tcpsystems/ui/foundation/ColorInput';
	let value = $state('#336699');
</script>

<ColorInput label="Project accent" bind:value />

Brand swatches

Brand swatches.svelte
<script lang="ts">
	import ColorInput from '@tcpsystems/ui/foundation/ColorInput';
	import '@tcpsystems/ui/foundation/elements/color';
	let value = $state('#336699');
</script>

<ColorInput label="Workspace colour" bind:value swatches={['#336699', '#cc8800', '#228855']} />

Disabled and error

Use a six-digit hex colour, such as #336699.

Disabled and error.svelte
<script lang="ts">
	import '@tcpsystems/ui/foundation/elements/color';
	import ColorInput from '@tcpsystems/ui/foundation/ColorInput';
	import Stack from '@tcpsystems/ui/foundation/Stack';
	const uid = $props.id();
	let value = $state('blue');
</script>

<Stack>
	<ColorInput label="Managed brand colour" value="#336699" disabled />
	<ColorInput label="Custom accent" bind:value invalid={!/^#[\da-f]{6}$/i.test(value)} describedby={uid} />
	<p id={uid}>Use a six-digit hex colour, such as #336699.</p>
</Stack>

API

Import
import ColorInput from '@tcpsystems/ui/foundation/ColorInput';
PropTypeDefault
value?string$bindable('#000000')
name?stringnone
id?stringnone
label?stringid ? undefined : d.label ?? 'Colour'
describedby?stringnone
invalid?'true' | 'false' | booleannone
disabled?booleanfalse
swatches?string[][]
HookKind
.tcp-colorRoot class
data-color-swatchData attribute