ColorPicker
Included in RC.12
Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.
<MColorPicker v-model="color" label="Signature color" alpha />| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue | string | #9C5270 | HEX or RGB(A) input; updates emit uppercase #RRGGBB or #RRGGBBAA. |
alpha / animated | boolean | false / true | Alpha channel and optional Jolt preview transition. |
palette | readonly string[] | six colors | Valid HEX/RGB colors presented as selectable buttons. |
disabled / readonly | boolean | false | Prevent changes through every input and palette action. |
colorLabel / hueLabel / saturationLabel / brightnessLabel / alphaLabel / paletteLabel / invalidLabel | string | English | Labels and validation text can be localized. |
Invalid editor drafts stay visible without changing the model. Sliders operate on HSV and opacity; a remembered hue allows choosing a hue while saturation is zero. The large preview animates an opaque decorative gradient; the canonical color retains its alpha. Colors are not inferred from arbitrary CSS variables.
The preview shows an Aa sample and the color code in near-black or white, whichever reads better over both gradient stops, and the gradient's angle follows the hue as you drag it. Choosing a palette color gives the preview a small bump and pops the chosen swatch's dot. The preview stays hidden from assistive technology; with animated off or reduced motion it simply changes.
Chromium, mouse input. Selecting a palette color changes the button background. The swatch keeps its one-pixel border from the active theme.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const color = ref('#9C5270CC')
const animated = ref(true),
disabled = ref(false)
</script>
<template>
<MColumn gap="lg">
<MText text="CHROMA / PERSONAL STUDIO" variant="overline" tone="primary" />
<MStack direction="column" :responsive="{ at: 800, direction: 'row' }" gap="lg" align="stretch">
<MCard :grow="1" padding="lg"
><MColorPicker
v-model="color"
:label="t('Find your signature.', 'Encontre sua assinatura.')"
alpha
:animated="animated"
:disabled="disabled"
:colorLabel="t('HEX or RGB', 'HEX ou RGB')"
:hueLabel="t('Hue', 'Matiz')"
:saturationLabel="t('Saturation', 'Saturação')"
:brightnessLabel="t('Brightness', 'Brilho')"
:alphaLabel="t('Opacity', 'Opacidade')"
:paletteLabel="t('Palette', 'Paleta')"
:invalidLabel="t('Enter a valid HEX or RGB color.', 'Digite uma cor HEX ou RGB válida.')"
/></MCard>
<MCard :grow="1" padding="lg" gap="lg"
><MText text="YOUR NEXT CHAPTER" variant="overline" /><MBox
:backgroundColor="color"
:height="180"
radius="lg" /><MText
:text="t('Color changes everything.', 'A cor muda tudo.')"
variant="title" /><MText id="color-value" :text="color" /><MText
:text="
t(
'A palette to call your own. Keep the color, change the feeling.',
'Uma paleta para chamar de sua. Guarde a cor, mude a sensação.',
)
"
tone="muted"
/></MCard> </MStack
><MRow gap="md" wrap
><MSwitch v-model="animated" :label="t('Animate preview', 'Animar prévia')" /><MSwitch
v-model="disabled"
:label="t('Disable picker', 'Desabilitar seletor')"
/></MRow>
</MColumn>
</template>Desktop
On the desktop each channel is a track that follows a drag and the arrow keys, with Page Up and Page Down for steps of ten and Home and End for the ends. The preview changes at once, so animated has no effect there; see Desktop components.