ngx-color-picker
Version:
Color picker widget for Angular
146 lines (99 loc) • 6.74 kB
Markdown
"https://badge.fury.io/js/ngx-color-picker"><img src="https://badge.fury.io/js/ngx-color-picker.svg" align="right" alt="npm version" height="18"></a>
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 <a href="https://github.com/zefoy/ngx-color-picker/tree/4.x.x/">here</a>.
[ ](https://zefoy.github.io/ngx-color-picker/)
|
[ ](https://stackblitz.com/github/zefoy/ngx-color-picker/tree/master)
```bash
npm install
npm run build
```
```bash
npm install
npm run start
```
```bash
npm install ngx-color-picker --save
```
```javascript
import { ColorPickerModule } from 'ngx-color-picker';
@NgModule({
...
imports: [
...
ColorPickerModule
]
})
```
```html
<input [(colorPicker)]="color" [style.background]="color"/>
```
```javascript
[ ] // The color to show in the color picker dialog.
[ ] // Use this option to set color picker dialog width ('230px').
[ ] // Use this option to force color picker dialog height ('auto').
[ ] // Sets the default open / close state of the color picker (false).
[ ] // Disables opening of the color picker dialog via toggle / events.
[ ] // Dialog color mode: 'color', 'grayscale', 'presets' ('color').
[ ] // Enables CMYK input format and color change event (false).
[ ] // Output color format: 'auto', 'hex', 'rgba', 'hsla' ('auto').
[ ] // Alpha mode: 'enabled', 'disabled', 'always', 'forced' ('enabled').
[ ] // Used when the color is not well-formed or is undefined ('#000').
[ ] // Dialog position: 'auto', 'top', 'bottom', 'left', 'right',
// 'top-left', 'top-right', 'bottom-left', 'bottom-right' ('auto').
[ ] // Dialog offset percentage relative to the directive element (0%).
[ ] // Dialog position is calculated relative to dialog arrow (false).
[ ] // Label text for the preset colors if any provided ('Preset colors').
[ ] // Array of preset colors to show in the color picker dialog ([]).
[ ] // Disables / hides the color input field from the dialog (false).
[ ] // Dialog positioning mode: 'popup', 'inline' ('popup').
// popup: dialog is shown as popup (fixed positioning).
// inline: dialog is shown permanently (static positioning).
[ ] // Array of HTML elements that will be ignored when clicked ([]).
[ ] // Save currently selected color when user clicks outside (true).
[ ] // Close the color picker dialog when user clicks outside (true).
[ ] // Show an OK / Apply button which saves the color (false).
[ ] // Button label text shown inside the OK / Apply button ('OK').
[ ] // Additional class for customizing the OK / Apply button ('').
[ ] // Show a Cancel / Reset button which resets the color (false).
[ ] // Button label text shown inside the Cancel / Reset button ('Cancel').
[ ] // Additional class for customizing the Cancel / Reset button ('').
[ ] // Show an Add Color button which add the color into preset (false).
[ ] // Button label text shown inside the Add Color button ('Add color').
[ ] // Additional class for customizing the Add Color button ('').
[ ] // Additional class for customizing the Remove Color button ('').
[ ] // Additional class for customizing the Preset Colors container ('').
[ ] // Use this option to set the max colors allowed in presets (null).
[ ] // Message for empty colors if any provided used ('No colors added').
[ ] // Additional class for customizing the empty colors message ('').
[ ] // Create dialog component in the root view container (false).
// Note: The root component needs to have public viewContainerRef.
(colorPickerOpen) // Current color value, send when dialog is opened (value: string).
(colorPickerClose) // Current color value, send when dialog is closed (value: string).
(colorPickerChange) // Changed color value, send when color is changed (value: string).
(colorPickerCancel) // Color select canceled, send when Cancel button is pressed (void).
(colorPickerSelect) // Selected color value, send when OK button is pressed (value: string).
(cpToggleChange) // Status of the dialog, send when dialog is opened / closed (open: boolean).
(cpInputChange) // Input name and its value, send when user changes color through inputs
// ({input: string, value: number | string, color: string})
(cpSliderChange) // Slider name and its value, send when user changes color through slider
// ({slider: string, value: number | string, color: string})
(cpSliderDragStart) // Slider name and current color, send when slider dragging starts (mousedown,touchstart)
// ({slider: string, color: string})
(cpSliderDragEnd) // Slider name and current color, send when slider dragging ends (mouseup,touchend)
// ({slider: string, color: string})
(cpCmykColorChange) // Outputs the color as CMYK string if CMYK is enabled (value: string).
(cpPresetColorsChange) // Preset colors, send when 'Add Color' button is pressed (value: array).
```
```javascript
openDialog() // Opens the color picker dialog if not already open.
closeDialog() // Closes the color picker dialog if not already closed.
```
<a href=