Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
vue-accessible-color-picker
Advanced tools
An accessible Vue.js color picker component.
Links:
npm install vue-accessible-color-picker
In a Vue single file component (SFC), import the ColorPicker
plugin and register the component via the components
property on the Vue instance. You can then use it in the file’s template
section.
<template>
<ColorPicker />
</template>
<script>
import { ColorPicker } from 'vue-accessible-color-picker';
export default {
components: {
ColorPicker,
},
}
</script>
Unstyled component:
If you want to use the unstyled variant of the component, you need to adjust the import statement slightly:
import { ColorPicker } from 'vue-accessible-color-picker/dist/vue-accessible-color-picker-unstyled';
Registering a component globally allows you to use it in all Vue templates without the need to register it via an SFC’s components
property first.
In your Vue project’s main.js
file (i.e. where you call app.mount
), import the ColorPicker
plugin and register the component using app.component
.
import { ColorPicker } from 'vue-accessible-color-picker';
app.component('ColorPicker', ColorPicker)
Unstyled component:
import { ColorPicker } from 'vue-accessible-color-picker/dist/vue-accessible-color-picker-unstyled';
app.component('ColorPicker', ColorPicker)
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
, ColorHsv
, ColorHwb
, or ColorRgb
Required: false
Default: null
Usage:
<ColorPicker color="hsl(270 100% 50% / 0.8)" />
<ColorPicker color="#f80b" />
<ColorPicker :color="{ h: 0.75, s: 1, l: 0.5, a: 0.8 }" />
<template>
<ColorPicker :color="color" @color-change="updateColor" />
</template>
<script>
export default {
data() {
return {
color: 'hsl(270 100% 50% / 0.8)',
}
},
methods: {
updateColor (eventData) {
this.color = eventData.cssColor
}
},
}
</script>
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: false
Default: ['hex', 'hsl', 'hwb', 'rgb']
Usage:
<ColorPicker :visible-formats="['hsl', 'hwb']" />
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: false
Default: 'rgb'
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: false
Default: 'color-picker'
Usage:
<ColorPicker id="color-picker-1" />
color-change
Description: An input
event 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.
{
colors: {
hex: string
hsl: ColorHsl
hsv: ColorHsv
hwb: ColorHwb
rgb: ColorRgb
}
cssColor: string
}
Usage:
<template>
<ColorPicker color="hsl(270 100% 50% / 0.8)" @color-change="updateColor" />
</template>
<script>
export default {
methods: {
updateColor (eventData) {
console.log(eventData)
}
},
}
</script>
Description: Overrides the content of the hue range input’s label
element. The slot content is placed inside a span
element.
Default content:
Hue
Description: Overrides the content of the alpha range input’s label
element. The slot content is placed inside a span
element.
Default content:
Alpha
Description: Overrides the content of the copy button element.
Default content:
Copy color
Description: Overrides the content of the format switch button element.
Default content:
Switch format
IE | Edge | Edge (Chromium) | Firefox | Chrome | Safari |
---|---|---|---|---|---|
no | 79 | 79 | 63 | 73 | 12.2 |
The component’s browser support is due to the use of Object.fromEntries(), CSS custom properties, and spread syntax in object literals.
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 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 the this colors at the halfway point of the Y axis (i.e. at 50% lightness) which isn’t easy to hit.
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).
3.0.0 (2021-03-21)
VueAccessibleColorPicker
namespace from types.'rgb'
to 'hsl'
. To upgrade without changing this in your application, you can pass 'rgb'
to the defaultFormat
prop.Object.fromEntries
. Most notably, Edge using the EdgeHTML engine and Safari versions before 12.2 are no longer supported. Please refer to the README.md file for the complete list.FAQs
Color picker component for Vue.js
The npm package vue-accessible-color-picker receives a total of 4,877 weekly downloads. As such, vue-accessible-color-picker popularity was classified as popular.
We found that vue-accessible-color-picker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.