Lightweight Vue 3 Color Picker – color-kit

Description:

A tiny yet configurable color picker component for Vue 3.

Features:

  • Dark & Light Themes
  • Pre-defined color palette

How to use it:

1. Import the color picker.

import { ColorPicker } from 'vue-color-kit'
// stylesheet
import 'vue-color-kit/dist/vue-color-kit.css'

2. Register the component.

export default {
  components: {
    ColorPicker,
  },
}

3. Add a color picker component to your app.

<template>
  <div :style="{background: color}">
    <ColorPicker
      theme="light"
      :color="color"
      :sucker-hide="false"
      :sucker-canvas="suckerCanvas"
      :sucker-area="suckerArea"
      @changeColor="changeColor"
      @openSucker="openSucker"
    />
  </div>
</template>
export default {
  components: {
    ColorPicker,
  },
  data() {
    return {
      color: '#59c7f9',
      suckerCanvas: null,
      suckerArea: [],
      isSucking: false,
    }
  },
  methods: {
    changeColor(color) {
      const { r, g, b, a } = color.rgba
      this.color = `rgba(${r}, ${g}, ${b}, ${a})`
    },
    openSucker(isOpen) {
      if (isOpen) {
        // ... canvas be created
        // this.suckerCanvas = canvas
        // this.suckerArea = [x1, y1, x2, y2]
      } else {
        // this.suckerCanvas && this.suckerCanvas.remove
      }
    },
  },
}

4. All possible component options.

color: {
  type: String,
  default: '#000000',
},
theme: {
  type: String,
  default: 'dark', // or 'light'
},
suckerHide: {
  type: Boolean,
  default: true,
},
suckerCanvas: {
  type: null, // HTMLCanvasElement
  default: null,
},
suckerArea: {
  type: Array,
  default: () => [],
},
colorsDefault: {
  type: Array,
  default: () => [
    '#000000',
    '#FFFFFF',
    '#FF1900',
    '#F47365',
    '#FFB243',
    '#FFE623',
    '#6EFF2A',
    '#1BC7B1',
    '#00BEFF',
    '#2E81FF',
    '#5D61FF',
    '#FF89CF',
    '#FC3CAD',
    '#BF3DCE',
    '#8E00A7',
    'rgba(0,0,0,0)',
  ],
},
colorsHistoryKey: {
  type: String,
  default: 'vue-colorpicker-history',
},

Preview:

Lightweight Vue 3 Color Picker - color-kit

Changelog:

v1.0.5 (06/12/2021)

  • feat: ability to add custom slot

Download Details:

Author: anish2690

Live Demo: https://vue-color-kit.vercel.app/

Download Link: https://github.com/anish2690/vue-color-kit/archive/refs/heads/master.zip

Official Website: https://github.com/anish2690/vue-color-kit

Install & Download:

# Yarn
$ yarn add vue-color-kit

# NPM
$ npm i vue-color-kit

You Might Be Interested In:

Add Comment