Color pickers for Angular
Set of color pickers and common components to be used as building blocks for custom colorpickers.
Install
Include Component
Others available
Color
onChange
onChangeComplete
Individual APIs
About
- 13 Different Pickers - Sketch, Photoshop, Chrome and many more
- Make Your Own - Use the building block components to make your own
- This is a fork of (https://github.com/scttcper/ngx-color)
Main enhancements
- each component uses encapsulation strategy as ViewEncapsulation.None
- fix for sketch component for IE 11
- code refactored
- use of @ctrl/tinycolor library (allow any color input of ColorInput interface)
- new material-theming.scss available in bundle with Material theming support for all components
- standard .css available in two modes as light and dark version (light-theme.min.css and dark-theme.min.css)
- ability to use specific component styles mixin in consumer application or whole bundle
Getting Started
Install
```sh npm install @daimoonis/ngx-color --save ```Include styles
sass
```scss @import '~@daimoonis/ngx-color/material-theming'; @import '~@angular/material/theming'; @include mat-core(); $candy-app-primary: mat-palette($mat-indigo); $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); $candy-app-warn: mat-palette($mat-red); $candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn); // @include angular-material-theme($candy-app-theme); // include whole theme @include ngx-color-theme($candy-app-theme); // or // include only specific component theme (whole) .my-sketch-component-wrapper {@include ngx-color-sketch-theme-complete($theme);
}
```
css
```css @import '~@daimoonis/ngx-color/light-theme.min.css'; ``` or ```css @import '~@daimoonis/ngx-color/dark-theme.min.css'; ```Include Component
import
```ts import { ColorSketchModule } from '@daimoonis/ngx-color'; @NgModule({ imports:ColorSketchModule, // added to imports
,
})
class YourModule {}
```
use
```html color="colorInput" (onChangeComplete)="changeComplete($event)"> ```Others available
```ts import { ColorAlphaModule } from '@daimoonis/ngx-color'; // import { ColorBlockModule } from '@daimoonis/ngx-color'; // import { ColorChromeModule } from '@daimoonis/ngx-color'; // import { ColorCircleModule } from '@daimoonis/ngx-color'; // import { ColorCompactModule } from '@daimoonis/ngx-color'; // import { ColorGithubModule } from '@daimoonis/ngx-color'; // import { ColorHueModule } from '@daimoonis/ngx-color'; // import { ColorMaterialModule } from '@daimoonis/ngx-color'; // import { ColorPhotoshopModule } from '@daimoonis/ngx-color'; // import { ColorSketchModule } from '@daimoonis/ngx-color'; // import { ColorSliderModule } from '@daimoonis/ngx-color'; // import { ColorSwatchesModule } from '@daimoonis/ngx-color'; // import { ColorTwitterModule } from '@daimoonis/ngx-color'; // ```Component API
Color
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 ColorInput of these interfaces: ```ts string | RGB | RGBA | HSL | HSLA | HSV | HSVA | TinyColor; // TinyColor is an instance of class from @ctrl/tinycolor library ``` in details: ```ts export interface RGB {r: number | string;
g: number | string;
b: number | string;
}
export interface RGBA extends RGB {
a: number;
}
export interface HSL {
h: number | string;
s: number | string;
l: number | string;
}
export interface HSLA extends HSL {
a: number;
}
export interface HSV {
h: number | string;
s: number | string;
v: number | string;
}
export interface HSVA extends HSV {
a: number;
}
```
For example a string of a hex color '#333'
or a object of rgb or hsl
values { r: 51, g: 51, b: 51 }
or { h: 0, s: 0, l: .10 }
is accepted. Both rgb and hsl
will also take a a: 1
value for alpha. You can also use transparent
, green
etc...
```html
```
In this case, the color picker will initialize with the color #fff
. When the
color is changed, handleChangeComplete
will fire and set the new color to
state.
onChange
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 useonChangeComplete
.
```ts
import { Component } from '@angular/core';
import { ColorEvent } from '@daimoonis/ngx-color';
@Component({
selector: 'selector-name',
template: `
`,
})
export class NameComponent {
constructor() {}
handleChange($event: ColorEvent) {
console.log($event.color);
// color = NgxColor instance which is mostly a @ctrl/tinycolor instance
}
}
```
onChangeComplete
Pass a function to call once a color change is complete.Individual APIs
Some pickers have specific APIs that are unique to themselves:Alpha
- width - String | Number, Pixel value for picker width. Default
316px
- height - String | Number, Pixel value for picker height. Default
16px
- direction - String,
horizontal
orvertical
. Defaulthorizontal
Block
- width - string | number, Pixel value for picker width. Default
170px
- colors - Array of ColorInput, Color squares to display. Default `'#D9E3F0',
- triangle - String, Either
hide
ortop
. Defaulttop
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
Chrome
- disableAlpha - Bool, Remove alpha slider and options from picker. Default
false
Circle
- width - String | number, Pixel value for picker width. Default
252px
- colors - Array of ColorInput, Color squares to display. Default `"#f44336",
- circleSize - Number, Value for circle size. Default
28
- circleSpacing - Number, Value for spacing between circles. Default
14
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
Compact
- colors - Array of ColorInput, Color squares to display. Default `'#4D4D4D',
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
Github
- width - string | number, Pixel value for picker width. Default
212px
- colors - Array of ColorInput, Color squares to display. Default `'#B80000',
- triangle - String, Either
hide
,top-left
ortop-right
. Default
top-left
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
Hue
- width - string | number, Pixel value for picker width. Default
316px
- height - string | number, Pixel value for picker height. Default
16px
- direction - String Enum,
horizontal
orvertical
. Defaulthorizontal
Material
NonePhotoshop
- header - String, Title text. Default
Color Picker
- onAccept - (Output), Callback for when accept is clicked.
- onCancel - (Output), Callback for when cancel is clicked.
Sketch
- disableAlpha - Bool, Remove alpha slider and options from picker. Default
false
- presetColors - Array of ColorInput. Default `'#D0021B', '#F5A623', '#F8E71C', '#8B572A',
color
> and title
properties: [{ color: '#f00', title: 'red' }]
or a combination
> of both
- width - Number, Width of picker. Default
200
- onSwatchHover - An event handler for
onMouseOver
on the<Swatch>
s
(color, event)
Slider
- pointer - React Component, Custom pointer component
Swatches
- width - string | number, Pixel value for picker width. Default
320
- height - string | number, Pixel value for picker height. Default
240
- colors - Array of Arrays of ColorInput, An array of color groups, each with
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
- width - string | number, Pixel value for picker width. Default
276px
- colors - Array of ColorInput, Color squares to display. Default `'#FF6900',
- triangle - String, Either
hide
,top-left
ortop-right
. Default
top-left
- onSwatchHover - (Output) An event handler for
onMouseOver
on the
<Swatch>
s within this component. Gives the args (color, event)
---
GitHub @daimoonis