Vue Color Kit

1.0.6 · active · verified Tue Apr 21

Vue Color Kit is a dedicated component library providing a highly customizable color picker for Vue 3 applications. Currently stable at version 1.0.6, it offers both dark and light themes, supports various color formats (HEX, RGBA), and includes features like a color history palette and an optional 'sucker' tool for picking colors directly from the screen. While its release cadence appears to be infrequent, with recent updates focusing on minor improvements, it serves as a lightweight and focused solution for integrating color selection capabilities into Vue 3 projects. Its key differentiators include native Vue 3 support, minimal dependencies, and a direct approach to color picking without relying on external UI frameworks, offering a straightforward developer experience for basic to moderately complex color input requirements.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate the ColorPicker component, bind its value, and handle color changes within a Vue 3 Composition API setup, including the necessary CSS import. It also shows the basic event handling for the 'sucker' tool.

<template>
  <div :style="{ background: color, minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }">
    <ColorPicker
      theme="dark"
      :color="color"
      :sucker-hide="false"
      :sucker-canvas="suckerCanvas"
      :sucker-area="suckerArea"
      @changeColor="changeColor"
      @openSucker="openSucker"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { ColorPicker } from 'vue-color-kit';
import 'vue-color-kit/dist/vue-color-kit.css';

interface RGBA { r: number; g: number; b: number; a: number; }
interface ColorResult { rgba: RGBA; hex: string; }

export default defineComponent({
  name: 'ColorPickerExample',
  components: {
    ColorPicker,
  },
  setup() {
    const color = ref<string>('#59c7f9');
    const suckerCanvas = ref<HTMLCanvasElement | null>(null);
    const suckerArea = ref<number[]>([]);

    const changeColor = (newColor: ColorResult) => {
      const { r, g, b, a } = newColor.rgba;
      color.value = `rgba(${r}, ${g}, ${b}, ${a})`;
    };

    const openSucker = (isOpen: boolean) => {
      // In a real application, you would initialize/destroy your canvas here.
      // For simplicity, this example just logs the state.
      if (isOpen) {
        console.log('Sucker tool opened. User needs to set suckerCanvas and suckerArea if actual picking is desired.');
        // Example: suckerCanvas.value = document.createElement('canvas');
        // Example: suckerArea.value = [0, 0, window.innerWidth, window.innerHeight];
      } else {
        console.log('Sucker tool closed.');
        // Example: suckerCanvas.value?.remove();
        // Example: suckerCanvas.value = null;
      }
    };

    return {
      color,
      suckerCanvas,
      suckerArea,
      changeColor,
      openSucker,
    };
  },
});
</script>

view raw JSON →