vue-color

repository·main·Indexed 25 days ago

https://github.com/linx4200/vue-color

A collection of efficient, customizable, and tree-shakable color picker components for Vue 2.7 and Vue 3. It is TypeScript-ready, SSR-friendly, and supports various picker styles including ChromePicker, CompactPicker, PhotoshopPicker, and SketchPicker. The library uses tinycolor2 internally for parsing and supports two-way data binding via v-model and v-model:tinyColor.

Tokens
3.8K
Snippets
7
Records
42
Agent score
82%

What's inside vue-color

  1. Ensure SSR Compatibility (Nuxt/SSR)

    main

    Because vue-color components rely on DOM interaction, they must be rendered on the client side. If using Nuxt, wrap the picker in a <ClientOnly> component.

    <template>
      <ClientOnly>
        <ChromePicker />
      </ClientOnly>
    </template>
    
    <script setup lang="ts">
    import { ClientOnly } from '#components';
    import { ChromePicker } from 'vue-color';
    </script>
  2. Quick Start with vue-color in Vue 3

    main

    To use vue-color in a Vue 3 project, follow these two steps:

    1. Import styles: Import the global stylesheet in your main entry file (e.g., main.ts).
    2. Use a component: Import a specific picker component (like ChromePicker) and use it in your template with v-model.
    // main.ts
    import { createApp } from 'vue'
    import App from './App.vue'
    
    // Import styles
    import 'vue-color/style.css';
    
    createApp(App).mount('#app')
    <template>
      <ChromePicker v-model="color" />
    </template>
    
    <script setup lang="ts">
    import { ChromePicker } from 'vue-color'
    
    const color = defineModel({
      default: '#68CCCA'
    });
    </script>
  3. Use the HueSlider component

    main

    The HueSlider component provides a slider to select a hue value within the range of [0, 360]. It supports both horizontal and vertical orientations.

    <script setup>
    import { HueSlider } from 'vue-color';
    
    const hue = defineModel();
    </script>
    
    <template>
      <HueSlider v-model="hue" />
    </template>