ColorPicker Color Picker
LhColorPicker color picker: saturation pad, hue / alpha sliders, hex / rgb formats and predefined swatches.
Basic Usage
Basic Usage
#2b4c7c
rgb(58, 125, 90)
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'
const color = ref('#2B4C7C')
const color2 = ref('#3A7D5A')
</script>
<template>
<div class="demo-row">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color2" format="rgb" />
</div>
</template>vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'
export default {
components: { LhColorPicker },
data() {
return {
color: '#2B4C7C',
color2: '#3A7D5A',
}
},
}
</script>
<template>
<div class="demo-row">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color2" format="rgb" />
</div>
</template>Alpha & Predefine
#a63d40
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'
const color3 = ref('#A63D40')
const predefine = ['#2B4C7C', '#3A7D5A', '#B8860B', '#A63D40', '#666B70']
</script>
<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'
export default {
components: { LhColorPicker },
data() {
return {
color3: '#A63D40',
}
},
}
</script>
<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>ColorPicker API
Props
| Name | Description | Type | Default |
|---|---|---|---|
| modelValue | Color value (v-model, hex or rgb(), emitted per format) | string | '' |
| format | Output format: hex / rgb | "hex" | "rgb" | 'hex' |
| showAlpha | Alpha channel (8-digit hex / rgba() output) | boolean | false |
| predefine | Predefined swatches | string[] | () => [] |
| size | Size | "small" | "medium" | "large" | "mini" | "x-large" | 'medium' |
| disabled | Disabled | boolean | false |
| clearable | Clear button | boolean | false |
| placeholder | Placeholder when empty | string | '' |
| ariaLabel | Accessibility name of the trigger | string | — |
| sx | Quick layout props | LhSxProps | — |
Events
| Name | Description | Type |
|---|---|---|
| update:modelValue | Fired when the color changes | (value: string) |
| change | Fired when the color changes | (value: string) |
| clear | Fired when the clear button is clicked | () |
Accessibility
- Hue / alpha sliders are
role="slider"with arrow-key adjustment (Shift for larger steps) - The trigger is keyboard-activatable (Enter / Space); clicking outside or Esc closes the panel
Type Definitions
The TypeScript type structures exported by this component (auto-extracted from packages/components/color-picker/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):
LhColorPickerProps
ts
export interface LhColorPickerProps {
modelValue?: string
format?: LhColorFormat
showAlpha?: boolean
predefine?: string[]
size?: LhComponentSize
disabled?: boolean
clearable?: boolean
placeholder?: string
ariaLabel?: string
sx?: LhSxProps
}LhColorPickerSize
ts
export type LhColorPickerSize = LhComponentSize
