What is ngx-color-picker?
ngx-color-picker is an Angular component library that provides a color picker widget. It allows users to select colors through a user-friendly interface, supporting various color formats such as HEX, RGB, and HSL. The package is highly customizable and can be integrated easily into Angular applications.
What are ngx-color-picker's main functionalities?
Basic Color Picker
This feature allows you to add a basic color picker to your Angular application. The selected color is bound to the 'color' variable in your component.
<color-picker [(color)]="color"></color-picker>
Preset Colors
This feature allows you to provide a set of preset colors that users can choose from. The 'presetColors' variable should be an array of color strings.
<color-picker [(color)]="color" [presetColors]="presetColors"></color-picker>
Output Events
This feature allows you to handle color change events. The 'onColorChange' method will be called whenever the user selects a new color.
<color-picker [(color)]="color" (colorChange)="onColorChange($event)"></color-picker>
Custom Styles
This feature allows you to customize the dimensions of the color picker. The 'cpWidth' and 'cpHeight' properties set the width and height of the color picker, respectively.
<color-picker [(color)]="color" [cpWidth]="200" [cpHeight]="200"></color-picker>
Other packages similar to ngx-color-picker
ngx-color
ngx-color is another Angular color picker library that offers a variety of color picker components inspired by popular color pickers like Photoshop and Sketch. It provides a more diverse set of color picker styles compared to ngx-color-picker.
angular2-color-picker
angular2-color-picker is a simple and lightweight color picker for Angular applications. It offers basic color picking functionalities and is easy to integrate, but it lacks some of the advanced customization options available in ngx-color-picker.
ng2-color-picker
ng2-color-picker is an Angular 2+ color picker component that provides a straightforward and easy-to-use interface for color selection. It is similar to ngx-color-picker in terms of basic functionality but may not offer as many customization options.
Angular Color Picker
This is a simple color picker based on the cool angular2-color-picker by Alberplz.
This documentation is for the latest 5/6.x.x version which requires Angular 5 or newer. For Angular 4 you need to use the latest 4.x.x version. Documentation for the 4.x.x can be found from here.
Quick links
Example application
|
StackBlitz example
Building the library
npm install
npm start
Running the example
cd example
npm install
npm start
Library development
npm link
cd example
npm link ngx-color-picker
Installing and usage
npm install ngx-color-picker --save
Load the module for your app:
import { ColorPickerModule } from 'ngx-color-picker';
@NgModule({
...
imports: [
...
ColorPickerModule
]
})
Use it in your HTML template:
<input [(colorPicker)]="color" [style.background]="color"/>
[colorPicker]
[cpWidth]
[cpHeight]
[cpToggle]
[cpDisabled]
[cpColorMode]
[cpOutputFormat]
[cpAlphaChannel]
[cpFallbackColor]
[cpPosition]
[cpPositionOffset]
[cpPositionRelativeToArrow]
[cpPresetLabel]
[cpPresetColors]
[cpDisableInput]
[cpDialogDisplay]
[cpIgnoredElements]
[cpSaveClickOutside]
[cpCloseClickOutside]
[cpOKButton]
[cpOKButtonText]
[cpOKButtonClass]
[cpCancelButton]
[cpCancelButtonText]
[cpCancelButtonClass]
[cpAddColorButton]
[cpAddColorButtonText]
[cpAddColorButtonClass]
[cpRemoveColorButtonClass]
[cpMaxPresetColorsLength]
[cpPresetEmptyMessage]
[cpPresetEmptyMessageClass]
[cpUseRootViewContainer]
(colorPickerOpen)
(colorPickerClose)
(colorPickerChange)
(colorPickerCancel)
(colorPickerSelect)
(cpToggleChange)
(cpInputChange)
(cpSliderChange)
(cpSliderDragEnd)
(cpSliderDragStart)
(cpPresetColorsChange)
Available control / helper functions (provided by the directive):
openDialog()
closeDialog()