Getting started with nxt-color-picker

Installing

npm install --save nxt-color-picker

Import color picker module

import { ColorPickerModule } from 'nxt-color-picker'

@NgModule({
    ...
    imports: [
        ...
        ColorPickerModule
    ]
})

Include it in HTML template

<input [(nxtColor)]="color" 
    [style.background]="color"/>

Configuration options

InputTypeDefault valueDescription
[nxtColor]stringundefined

The color to show in the color picker dialog

[width]string'230px'

Use this option to set color picker dialog width

[height]string'auto'

Use this option to force color picker dialog height

[toggle]booleanfalse

Sets the default open / close state of the color picker

[disabled]booleanfalse

Disables opening of the color picker dialog via toggle

[mode]ColorMode'color'

Dialog color mode

[cmykEnabled]booleanfalse

Enables CMYK input format and color change event

[outputFormat]OutputFormatOutputFormatEnum.auto

Output color format

[alphaChannel]AlphaChannelAlphaChannelEnum.enabled

Alpha channel mode

[fallbackColor]stringundefined

Used when the color is not well-formed or is undefined

[position]DialogPosition | DialogPosition[]DialogPositionEnum.auto

Dialog position

[positionOffset]number0

Dialog offset percentage relative to the directive element

[presetLabel]boolean | stringtrue

Show label for preset colors

If string is given, it overrides the default label.

[presetColors]string[]undefined

Array of preset colors to show in the color picker dialog

[disableInput]booleanfalse

Disables / hides the color input field from the dialog

[dialogDisplay]DialogDisplayDialogDisplayEnum.popup

Dialog positioning mode

[ignoredElements]any[]undefined

Array of HTML elements that will be ignored when clicked

[saveClickOutside]booleantrue

Save currently selected color when user clicks outside

[closeClickOutside]booleantrue

Close the color picker dialog when user clicks outside

[okButton]booleanfalse

Show an OK / Apply button which saves the color

[cancelButton]booleanfalse

Show a Cancel / Reset button which resets the color

[presetColorsEditable]booleanfalse

Show buttons to add / remove preset colors

[maxPresetColors]numberundefined

Use this option to set the max colors allowed in presets

[useRootViewContainer]booleanfalse

Create dialog component in the root view container

Note: The root component needs to have public viewContainerRef.

OutputTypeDescription
(open)string

Current color value, emit when dialog is isOpen

(close)string

Current color value, emit when dialog is closed

(inputChange)InputChangeEvent

Input name and its value, emit when user changes color through inputs

(toggleChange)boolean

Status of the dialog, emit when dialog is isOpen / closed

(sliderDragStart)SliderChangeEvent

Slider name and current color, emit when slider dragging starts

(sliderChange)SliderChangeEvent

Slider name and its value, emit when user changes color through slider

(sliderDragEnd)SliderChangeEvent

Slider name and current color, emit when slider dragging ends

(colorSelect)string

Color select canceled, emit when Cancel button is pressed

(colorSelectCancel)void

Selected color value, emit when OK button pressed or user clicks outside (if saveClickOutside is true)

(nxtColorChange)string

Changed color value, emit when color changes

(cmykColorChange)string

Outputs the color as CMYK string if CMYK is enabled

(presetColorsChange)string[]

Preset colors, emit when preset color is added / removed