Vitral 0.2.18
Form

InputColor

A text box for a colour: the swatch opens the picker, the hex is typed, and empty is null.

Import

main.ts
import { InputColor } from '@vitral/vue';

Basic

Six digits take as they are typed; a short #rgb when the box is left. ArrowDown opens the picker, Escape comes back to the box.

Value: #2f5597
<script setup lang="ts">import { InputColor } from '@vitral/vue';import { ref } from 'vue'; const color = ref<string | null>('#2f5597');</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.5rem; max-width: 18rem">        <label for="ci-basic">Class colour</label>        <InputColor id="ci-basic" v-model="color" clearable placeholder="Uses the course's colour" />        <small style="color: var(--vt-text-muted-color)">Value: {{ color === null ? 'null' : color }}</small>    </div></template>

Swatches

A palette under the picker, for the colours a value usually comes from.

<script setup lang="ts">import { InputColor } from '@vitral/vue';import { ref } from 'vue'; const color = ref<string | null>(null);const palette = ['#e53935', '#fb8c00', '#fdd835', '#43a047', '#00897b', '#1e88e5', '#3949ab', '#8e24aa', '#6d4c41', '#546e7a'];</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.5rem; max-width: 18rem">        <label for="ci-swatches">Subject colour</label>        <InputColor id="ci-swatches" v-model="color" :swatches="palette" clearable placeholder="Uses the area's colour" />    </div></template>

Sizes and states

<script setup lang="ts">import { InputColor } from '@vitral/vue';</script> <template>    <div style="display: grid; gap: 0.75rem; max-width: 18rem">        <InputColor model-value="#43a047" size="small" aria-label="Small" />        <InputColor model-value="#43a047" aria-label="Normal" />        <InputColor model-value="#43a047" size="large" aria-label="Large" />        <InputColor model-value="#43a047" variant="filled" aria-label="Filled" />        <InputColor model-value="#zzzzzz" invalid placeholder="Invalid" aria-label="Invalid" />        <InputColor model-value="#43a047" readonly aria-label="Read only" />        <InputColor model-value="#43a047" disabled aria-label="Disabled" />    </div></template>

API

Read from packages/vue/src/components/InputColor/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
alpha booleanOffer an opacity slider; the value then carries it as eight hex digits (`'#33669980'`). Off by default: the value is `'#rrggbb'`.
defaultColor stringThe colour the panel starts on while the value is empty. Defaults to `'#ff0000'`.
swatches string[]Colours offered under the picker, one press each: the palette the value usually comes from.
clearable booleanShows a button that empties the field while it holds a colour.
placeholder string—
size Size—
variant InputVariantDefaults to the plugin's `inputVariant`.
invalid boolean—
disabled boolean—
readonly boolean—
fluid boolean—
placement OverlayPlacement—
appendTo string`'body'` (the default), `'self'` to render in place, or a selector.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
focus event: FocusEvent—
blur event: FocusEvent—
clear ——
show ——
hide ——