npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-accessible-color-picker

v5.1.0

Published

Color picker component for Vue.js

Downloads

30,269

Readme

vue-accessible-color-picker

Tests passing

A color picker component for Vue.js.

This package’s files are distributed in the ES module format and have not been transpiled.

Links:

Contents

Installation

npm install vue-accessible-color-picker

Usage

In a Vue single file component, import the ColorPicker component and its styles (if you want to use them).

<template>
	<ColorPicker />
</template>

<script setup>
import { ColorPicker } from 'vue-accessible-color-picker'
</script>

<style>
@import url('vue-accessible-color-picker/styles');
</style>

When using Vue’s composition API, you can directly use the component in the file’s template section once you import it.

You can also register the component and import the styles globally.

Documentation

Props

alphaChannel

  • Description: Whether to show input controls for a color’s alpha channel. If set to 'hide', the alpha range input and the alpha channel input are hidden, the “Copy color” button will copy a CSS color value without alpha channel, and the object emitted in a color-change event will have a cssColor property value without alpha channel.

  • Type: 'show' or 'hide'

  • Required: No

  • Default: 'show'

  • Usage:

    <ColorPicker alpha-channel="hide" />

color

  • Description: Sets the color of the color picker. You can pass any valid CSS color string or an object matching the internal color representation for an HSL, HSV, HWB, or RGB color.

  • Type: string, ColorHsl, ColorHwb, or ColorRgb

  • Required: No

  • Default: '#ffffffff'

  • Usage:

    <ColorPicker color="hsl(270 100% 50% / 0.8)" />
    <ColorPicker color="#f80b" />
    <ColorPicker :color="{ h: 270, s: 100, l: 50, a: 0.8 }" />
    <template>
    	<ColorPicker
    		:color="color"
    		@color-change="updateColor"
    	/>
    </template>
    
    <script setup>
    import { ref } from 'vue'
    import { ColorPicker } from 'vue-accessible-color-picker'
    
    const color = ref('hsl(270 100% 50% / 0.8)')
    
    function updateColor (eventData) {
    	color.value = eventData.cssColor
    }
    </script>

defaultFormat

  • Description: The color format to show by default when rendering the color picker. Must be one of the formats specified in visibleFormats.

  • Type: VisibleColorFormat

  • Required: No

  • Default: 'hsl'

  • Usage:

    <ColorPicker default-format="hwb" />

id

  • Description: The ID value will be used to prefix all input elements’ id and label elements’ for attribute values. Set this prop if you use multiple instances of the color-picker component on one page.

  • Type: string

  • Required: No

  • Default: 'color-picker'

  • Usage:

    <ColorPicker id="color-picker-1" />

visibleFormats

  • Description: A list of visible color formats. Controls for which formats the color input elements are shown and in which order the formats will be cycled through when activating the format switch button.

  • Type: VisibleColorFormat[]

  • Required: No

  • Default: ['hex', 'hsl', 'hwb', 'rgb']

  • Usage:

    <ColorPicker :visible-formats="['hsl', 'hwb']" />

Events

color-change

  • Description: The event that is emitted each time the internal colors object is updated.

  • Data: The event emits an object containing both the internal colors object and a CSS color value as a string based on the currently active format. The cssColor property will respect alphaChannel.

    {
    	colors: {
    		hex: string
    		hsl: { h: number, s: number, l: number, a: number }
    		hsv: { h: number, s: number, v: number, a: number }
    		hwb: { h: number, w: number, b: number, a: number }
    		rgb: { r: number, g: number, b: number, a: number }
    	}
    	cssColor: string
    }
  • Usage:

    <template>
    	<ColorPicker
    		color="hsl(270 100% 50% / 0.8)"
    		@color-change="colorChanged"
    	/>
    </template>
    
    <script setup>
    import { ColorPicker } from 'vue-accessible-color-picker'
    
    function colorChanged (eventData) {
    	console.log(eventData)
    }
    </script>

color-copy

  • Description: The color-copy event is fired once a copy operation succeeded.

  • Data: Emits the same event data as the color-change event.

  • Usage:

    <template>
    	<ColorPicker
    		color="hsl(270 100% 50% / 0.8)"
    		@color-copy="colorCopied"
    	/>
    </template>
    
    <script setup>
    import { ColorPicker } from 'vue-accessible-color-picker'
    
    function colorCopied (eventData) {
    	console.log(eventData)
    }
    </script>

Slots

alpha-range-input-label

  • Description: Overrides the content of the alpha range input’s label element.
  • Default content: Alpha

copy-button

  • Description: Overrides the content of the copy button element.
  • Default content: Copy color (and SVG icon)

format-switch-button

  • Description: Overrides the content of the format switch button element.
  • Default content: Switch format (and SVG icon)

hue-range-input-label

  • Description: Overrides the content of the hue range input’s label element.
  • Default content: Hue

Theming

You can customize the GUI of the color picker using CSS custom properties:

:root {
	--vacp-color-focus: tomato;
	--vacp-width-border: 2px;
}

Available custom properties and their default values:

| Custom property | Default value | | ------------------------------- | ------------- | | --vacp-color-background-input | #fff | --vacp-color-background | #fff | --vacp-color-border | #000 | --vacp-color-focus | #19f | --vacp-color-text-input | currentColor | --vacp-color-text | currentColor | --vacp-font-family | -apple-system, BlinkMacSystemFont, Segoe UI, Arial, sans-serif | --vacp-font-size | 0.8em | --vacp-spacing | 6px | --vacp-width-border | 1px | --vacp-width-color-space | 300px

Versioning

This package uses semantic versioning.

Design

The color picker consists of the following main elements:

  • Color space:

    For fine-tuning the saturation and lightness/value, a slice of the HSV cylinder for the currently selected hue is shown.

    The HSV cylinder is more convenient for this task than the HSL cylinder as it shows a color at 100% saturation and 100% value in the top right corner (i.e. one can drag the color space thumb into the corner as a quasi shortcut). The HSL cylinder’s slice has this color at the halfway point of the Y axis (i.e. at 50% lightness) which isn’t easy to select.

  • Hue slider:

    A slider for selecting the current hue. This rotates the HSV cylinder; thus, it changes the slice of the HSV cylinder that’s shown in the color space.

  • Alpha slider:

    A slider for selecting the current alpha value.

  • Copy button:

    Copies the color formatted as a CSS color string in the active format.

  • Color inputs:

    A set of text fields which allow you to enter the individual components of each color. The text fields are shown based on the active format.

  • Switch format button:

    Cycles through the available color formats (currently HEX, HSL, HWB, and RGB).