Skip to content

Color Picker Component ​

The OColorPicker component provides a user-friendly interface for selecting color values.

Usage Examples ​

Basic Usage ​

vue
<template>
  <OColorPicker
    :value="selectedColor"
    placeholder="Select color"
    @onSelectColor="handleColorChange"
  />
</template>

<script setup>
import { ref } from 'vue'

const selectedColor = ref('#4a90e2')

const handleColorChange = (color) => {
  selectedColor.value = color
}
</script>

With Custom Formatting ​

vue
<template>
  <OColorPicker
    :value="selectedColor"
    placeholder="Select color"
    @onSelectColor="handleColorChange"
  >
    <template #formattedColor>
      <div class="custom-color-display">
        <div class="color-box" :style="{ backgroundColor: selectedColor }"></div>
        <span>{{ selectedColor || 'No color selected' }}</span>
      </div>
    </template>
  </OColorPicker>
</template>

<script setup>
import { ref } from 'vue'

const selectedColor = ref('#4a90e2')

const handleColorChange = (color) => {
  selectedColor.value = color
}
</script>

<style scoped>
.custom-color-display {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-box {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #ddd;
}
</style>

Simplified Interface ​

vue
<template>
  <OColorPicker
    :value="selectedColor"
    placeholder="Simple color picker"
    :hideInputs="true"
    :hideSliders="false"
    :hideCanvas="false"
    :showSwatches="true"
    @onSelectColor="handleColorChange"
  />
</template>

<script setup>
import { ref } from 'vue'

const selectedColor = ref('#4a90e2')

const handleColorChange = (color) => {
  selectedColor.value = color
}
</script>

Custom Width and Swatches ​

vue
<template>
  <OColorPicker
    :value="selectedColor"
    placeholder="Custom width and swatches"
    :width="300"
    :swatchesMaxHeight="150"
    :showSwatches="true"
    @onSelectColor="handleColorChange"
  />
</template>

<script setup>
import { ref } from 'vue'

const selectedColor = ref('#4a90e2')

const handleColorChange = (color) => {
  selectedColor.value = color
}
</script>

Props Reference ​

PropTypeDefaultDescription
valueString"#FFFFFF"The selected color value in hex format
placeholderString"Select color"Placeholder text when no color is selected
disabledBooleanfalseWhether the color picker is disabled
hideInputsBooleanfalseWhether to hide the color input fields
hideCanvasBooleanfalseWhether to hide the color canvas
hideSlidersBooleanfalseWhether to hide the color sliders
showSwatchesBooleantrueWhether to show color swatches
swatchesArray[]Custom color swatches to display
elevationNumber1Elevation level for the color picker dropdown
scaleNumber1Scale factor for the color picker dropdown
emitColorOnCloseDropdownBooleanfalseWhether to emit color only when dropdown closes
bgColorString'white'Background color for the color picker
widthNumber/String200Width of the color picker dropdown
swatchesMaxHeightNumber/String100Maximum height of the swatches section