ColorInput
A colour picker with an editable hex value and optional swatches.
beta
Try it
<ColorInput label="Project accent" value="#336699" />Examples
Accent colour
<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
<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.
<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 ColorInput from '@tcpsystems/ui/foundation/ColorInput';| Prop | Type | Default |
|---|---|---|
value? | string | $bindable('#000000') |
name? | string | none |
id? | string | none |
label? | string | id ? undefined : d.label ?? 'Colour' |
describedby? | string | none |
invalid? | 'true' | 'false' | boolean | none |
disabled? | boolean | false |
swatches? | string[] | [] |
| Hook | Kind |
|---|---|
.tcp-color | Root class |
data-color-swatch | Data attribute |