A Collection of Color Pickers from Sketch, Photoshop, Chrome & more
npm install ngx-colorDEMO: https://ngx-color.vercel.app
- Component API
- Color
- onChange
- onChangeComplete
- Individual APIs
- Alpha
- Block
- Chrome
- Circle
- Compact
- Github
- Hue
- Material
- Photoshop
- Sketch
- Slider
- Swatches
- Twitter
- Shade
- 13 Different Pickers - Sketch, Photoshop, Chrome, Twitter and many more
- Make Your Own - Use the building block components to make your own
- This is a port of react-color
by casesandberg
Latest version available for each version of Angular
| ngx-color | Angular |
| --------- | --------- |
| 4.1.1 | 8.x |
| 5.1.4 | 9.x |
| 6.2.0 | 10.x 11.x |
| 7.3.3 | 12.x 13.x |
| 8.0.3 | 14.x 15.x |
| current | >= 16.x |
``sh`
npm install ngx-color --save
##### import
`ts
import { ColorSketchModule } from 'ngx-color/sketch';
@NgModule({
imports: [
ColorSketchModule, // added to imports
],
})
class YourModule {}
`
##### use
`html`
`ts`
import { ColorAlphaModule } from 'ngx-color/alpha'; //
import { ColorBlockModule } from 'ngx-color/block'; //
import { ColorChromeModule } from 'ngx-color/chrome'; //
import { ColorCircleModule } from 'ngx-color/circle'; //
import { ColorCompactModule } from 'ngx-color/compact'; //
import { ColorGithubModule } from 'ngx-color/github'; //
import { ColorHueModule } from 'ngx-color/hue'; //
import { ColorMaterialModule } from 'ngx-color/material'; //
import { ColorPhotoshopModule } from 'ngx-color/photoshop'; //
import { ColorSketchModule } from 'ngx-color/sketch'; //
import { ColorSliderModule } from 'ngx-color/slider'; //
import { ColorSwatchesModule } from 'ngx-color/swatches'; //
import { ColorTwitterModule } from 'ngx-color/twitter'; //
import { ColorShadeModule } from 'ngx-color/shade'; //
Color controls what color is active on the color picker. You can use this to
initialize the color picker with a particular color, or to keep it in sync with
the state of a parent component.
Color accepts either a string of a hex color '#333' or a object of rgb or hsl{ r: 51, g: 51, b: 51 }
values or { h: 0, s: 0, l: .10 }. Both rgb and hsla: 1
will also take a value for alpha. You can also use transparent.
`html`
In this case, the color picker will initialize with the color #fff. When thehandleChangeComplete
color is changed, will fire and set the new color to
state.
Pass a function to call every time the color is changed. Use this to store the
color in the state of a parent component or to make other transformations.
Keep in mind this is called on drag events that can happen quite frequently. If
you just need to get the color once use onChangeComplete.
`ts
import { Component } from '@angular/core';
import { ColorEvent } from 'ngx-color';
@Component({
selector: 'selector-name',
template: ,
})
export class NameComponent {
constructor() {}
handleChange($event: ColorEvent) {
console.log($event.color);
// color = {
// hex: '#333',
// rgb: {
// r: 51,
// g: 51,
// b: 51,
// a: 1,
// },
// hsl: {
// h: 0,
// s: 0,
// l: .20,
// a: 1,
// },
// }
}
}
`
Pass a function to call once a color change is complete.
Some pickers have specific APIs that are unique to themselves:
- width - String | Number, Pixel value for picker width. Default 316px16px
- height - String | Number, Pixel value for picker height. Default horizontal
- direction - String, or vertical. Default horizontal
- width - string | number, Pixel value for picker width. Default 170px['#D9E3F0', '#F47373', '#697689', '#37D67A', '#2CCCE4', '#555555', '#dce775', '#ff8a65', '#ba68c8']
- colors - Array of Strings, Color squares to display. Default hide
- triangle - String, Either or top. Default toponMouseOver
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- disableAlpha - Bool, Remove alpha slider and options from picker. Default
false
- width - String | number, Pixel value for picker width. Default 252px["#f44336", "#e91e63", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4caf50", "#8bc34a", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#795548", "#607d8b"]
- colors - Array of Strings, Color squares to display. Default 28
- circleSize - Number, Value for circle size. Default 14
- circleSpacing - Number, Value for spacing between circles. Default onMouseOver
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- colors - Array of Strings, Color squares to display. Default ['#4D4D4D', '#999999', '#FFFFFF', '#F44E3B', '#FE9200', '#FCDC00', '#DBDF00', '#A4DD00', '#68CCCA', '#73D8FF', '#AEA1FF', '#FDA1FF', '#333333', '#808080', '#cccccc', '#D33115', '#E27300', '#FCC400', '#B0BC00', '#68BC00', '#16A5A5', '#009CE0', '#7B64FF', '#FA28FF', '#000000', '#666666', '#B3B3B3', '#9F0500', '#C45100', '#FB9E00', '#808900', '#194D33', '#0C797D', '#0062B1', '#653294', '#AB149E']onMouseOver
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- width - string | number, Pixel value for picker width. Default 212px['#B80000', '#DB3E00', '#FCCB00', '#008B02', '#006B76', '#1273DE', '#004DCF', '#5300EB', '#EB9694', '#FAD0C3', '#FEF3BD', '#C1E1C5', '#BEDADC', '#C4DEF6', '#BED3F3', '#D4C4FB']
- colors - Array of Strings, Color squares to display. Default hide
- triangle - String, Either , top-left or top-right. Defaulttop-left
onMouseOver
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- width - string | number, Pixel value for picker width. Default 316px16px
- height - string | number, Pixel value for picker height. Default horizontal
- direction - String Enum, or vertical. Default horizontal
None
- header - String, Title text. Default Color Picker
- onAccept - (Output), Callback for when accept is clicked.
- onCancel - (Output), Callback for when cancel is clicked.
- disableAlpha - Bool, Remove alpha slider and options from picker. Default
false['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']
- presetColors - Array of Strings or Objects, Hex strings for default colors
at bottom of picker. Default color
> presetColors may also be described as an array of objects with title
> and properties: [{ color: '#f00', title: 'red' }] or a combination200
> of both
- width - Number, Width of picker. Default onMouseOver
- onSwatchHover - An event handler for on the s(color, event)
within this component. Gives the args
- pointer - React Component, Custom pointer component
- width - string | number, Pixel value for picker width. Default 320240
- height - string | number, Pixel value for picker height. Default onMouseOver
- colors - Array of Arrays of Strings, An array of color groups, each with
an array of colors
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- width - string | number, Pixel value for picker width. Default 276px['#FF6900', '#FCB900', '#7BDCB5', '#00D084', '#8ED1FC', '#0693E3', '#ABB8C3', '#EB144C', '#F78DA7', '#9900EF']
- colors - Array of Strings, Color squares to display. Default hide
- triangle - String, Either , top-left or top-right. Defaulttop-left
onMouseOver
- onSwatchHover - (Output) An event handler for on the
s within this component. Gives the args (color, event)
- width - String | Number, Pixel value for picker width. Default 316px16px`
- height - String | Number, Pixel value for picker height. Default
---