Skip to content

KColorPicker ​

Components providing color selection.

Install ​

bash
pnpm add @ikun-ui/color-picker
bash
yarn add @ikun-ui/color-picker
bash
npm install @ikun-ui/color-picker

Basic usage ​

Basic Usage.

Sizes ​

Add size attribute to change the size of ColorPicker. It supports sm, md and lg.

External Control ​

Control opening and closing through handleOpen and handleOpen

Rendering Trigger Text ​

Renders the default text of the trigger, effective when showText is true. When customizing text, you can use showText as a function to return custom text.

Disabled ​

Disabled ColorPicker

Disabled Alpha ​

Disabled color alpha.

Clear ​

Clear Color

Custom Trigger ​

Triggers for customizing color panels.

Color Format ​

Encoding formats, support HEX, HSV, RGB.

Preset Colors ​

Set the presets color of the color picker.

Customizing Preset Panel ​

Set the presets color of the color picker by preset slot.

ColorPicker Props ​

NameTypeDefaultDescription
valuestring | RgbaColor | HsvaColor-color value.
defaultValuestring | RgbaColor | HsvaColor-The default color panel value, which determines the initial linear color.
format'rgb' | 'hsv' | 'hex''hex'Format of color.
allowClearbooleanfalseAllow clearing color selected.
disabledbooleanfalseDisable ColorPicker.
disabledAlphabooleanfalseDisable Alpha.
showTextbooleantrueWhether to display color values.
placement'top' | 'left' | 'right' | 'bottom''top'Placement of popup.
titlestring''Title of ColorPicker.
trigger'manual' | 'click' | 'hover'clickHow ColorPicker are triggered
size'sm' | 'md' | 'lg'mdSize of ColorPicker.
presetsKColorPickerPreset-Preset colors.
clsstring''Additional class for component
attrsany{}Additional attributes
typescript
export interface KColorPickerPreset {
	defaultOpen?: boolean;
	label: string;
	colors: string[] | RgbaColor[] | HsvaColor[];
}
typescript
export interface RgbaColor {
	r: number;
	g: number;
	b: number;
	a?: number;
}
typescript
export interface HsvaColor {
	h: number;
	s: number;
	v: number;
	a?: number;
}

ColorPicker Api ​

NameDescriptionType
handleOpenOpen the dropdown.()=> void
handleCloseClose the dropdown.()=> void

ColorPicker Events ​

NameDescriptionType
changeCallback when value is changed.(color: string)=> void
changeCompleteCalled when color pick ends.(color: string)=> void
openChangeCallback when format is changed.(format: 'rgb' | 'hsv' | 'hex')=> void
openChangeCallback when open is changed.(open: boolean) => void
clearCalled when clear.()=> void

ColorPicker Slots ​

NameDescription
defaultCustom trigger element.
titlecontent of the title.
textcontent of the color text.
presetcontent of the preset.

Color Api ​

TIP

It is based on tinycolor2 , the ColorInput type comes from tinycolor2

NameDescriptiontype
toHexConvert to hex format characters, the return type like: 1677ff .toHex(value: Color): string
toHexStringonvert to hex format color string, the return type like: #1677ff.toHexString(value: Color): string
toHsvConvert to hsv object.toHsv(value: Color): tinycolor.ColorFormats.HSVA
toHsvStringConvert to hsb format color string, the return type like: hvb(215, 91%, 100%).toHsvString(value: Color): string
toRgbConvert to rgb object.toRgb(value: Color): tinycolor.ColorFormats.RGBA
toRgbStringConvert to rgb format color string, the return type like: rgb(22, 119, 255).toRgbString(value: Color): string

MIT Licensed