Skip to content

ColorPicker Component

ColorPicker Component

ColorPicker component allows users to select colors through a visual interface, supporting multiple color formats, transparency adjustment, and predefined colors.

Basic Usage

The most basic color picker usage.

Currently selected color value: #409EFF
Show CodeArrow
CopyGitHub

Alpha Selection

Enable transparency selection by setting the show-alpha attribute.

Currently selected color value: rgba(64, 158, 255, 0.68)
Alpha effect preview
Show CodeArrow
CopyGitHub

Predefined Colors

Set predefined colors through the predefine attribute to provide quick selection of commonly used colors.

Currently selected color value: #1e90ff
Predefined color list:
Show CodeArrow
CopyGitHub

Different Sizes

ColorPicker supports different sizes, set through the size attribute, supporting small, default, and large sizes.

Small
Default
Large
Show CodeArrow
CopyGitHub

Different Color Formats

ColorPicker supports different color format outputs, which can be set through the color-format attribute.

HEX Format
#409EFF
RGB Format
rgb(64, 158, 255)
RGBA Format
rgba(64, 158, 255, 0.68)
Show CodeArrow
CopyGitHub

Disabled State

Disable the color picker by setting the disabled attribute.

Disabled State
Current color value: #409EFF
Show CodeArrow
CopyGitHub

Event Handling

ColorPicker provides various events for handling operations during the color selection process.

rgba(64, 158, 255, 0.8)
Event Log:
No events
Show CodeArrow
CopyGitHub

ColorPicker Component API

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
v-modelBinding valuestring
disabledWhether disabledbooleanfalse
sizeSizestringsmall / default / largedefault
show-alphaWhether to support alpha selectionbooleanfalse
color-formatColor format written to v-modelstringhsl / hsv / hex / rgbhex
popper-classClass name for ColorPicker dropdownstring
predefinePredefined colorsstring[]
validate-eventWhether to trigger form validation on inputbooleantrue
tabindexColorPicker tabindexstring / number0
teleportedWhether to render dropdown under bodybooleantrue

Events

Event NameDescriptionParameters
changeTriggered when binding value changes(value: string)
active-changeTriggered when currently displayed color changes(value: string)
focusTriggered when focused(event: FocusEvent)
blurTriggered when blurred(event: FocusEvent)

Methods

ColorPicker component exposes the following methods, which can be called through template refs.

Method NameDescriptionParameters
handleTriggerClickToggle color picker panel display/hide

Style Variables

ColorPicker component uses the following style variables, which can be customized through SCSS variables:

Variable NameDescription
$theme-color-primaryPrimary theme color
$text-color-defaultDefault text color
$border-color-defaultDefault border color
$bg-color-defaultDefault background color
$color-whiteWhite color
$color-blackBlack color
$font-size-defaultDefault font size
$font-size-smallSmall font size
$opacity-disabledDisabled state opacity

Released under the MIT License