npm install a-color-picker --save
bower install a-color-picker --save
Define an HTML element to contain the picker and use AColorPicker.from(selector)
to create it.
The default picker is created with HSL, RGB and HEX controls.
The acp-color
attribute is used to set the initial value.
See the Pen WJoQBm by Caldi Gianfranco ( @narsenico) on CodePen.
Show or hide controls through attributes.
acp-show-*
attributes accepts yes/no/true/false
values. Attributes without value are considered true
.
See the Pen a-color-picker demo attr by Caldi Gianfranco ( @narsenico) on CodePen.
Show a palette of colors using the acp-palette
attribute.
Set a list of colors - named color, hex rgb, rgb(), rgba(), hsl(), hsla() - pipe separated or a predefined palette (PALETTE_MATERIAL_500, PALETTE_MATERIAL_CHROME).
The acp-palette-editable
attribute can be set to allow the user to change the palette.
See the Pen a-color-picker demo palette editable by Narsenico ( @narsenico) on CodePen.
To attach an event use on
method and off
to detach it.
AColorPicker.from(selector)
2 | .on(eventName, callback)
3 | .off(eventName, callback)
Event name | Callback parameters | |
---|---|---|
change | picker | target |
color | selected color | |
coloradd | picker | target |
color | color added | |
colorremove | picker | target |
color | color removed or null if all colors are removed |
AColorPicker.createPicker(element, options)
AColorPicker.createPicker(options)
Create a color picker.
Parameter | |
---|---|
element | HTMLElement, jQuery object or css selector string. Optional: if not defined, options.attachTo is used. |
options | See options Optional only if element is defined. |
Return | |
A ACPController instance |
AColorPicker.from(selector, options)
Create one or more color pickers.
Parameter | |
---|---|
selector | HTMLElement, NodeList, jQuery object or css selector string. |
options | Optional, see options |
Return | |
An array of ACPController. This array has helper methods on and off to attach/detach events to all items. |
AColorPicker.parseColor(color, outFormat)
Parse color in input and return formatted value.
Parameter | |
---|---|
color | Value to be parsed Accepts color name, rgb array, hex rgb, rgb(), rgba(), hsl(), hsla() |
outFormat | Output format, one of: rgb, rgbcss, rgbcss4, rgba, rgbacss, hsl, hslcss, hslcss4, hsla, hslacss, hex, hexcss4. If outFormat is a plain object, will be filled with all formats as properties. |
Return | |
Formatted color or undefined if not recognized. |
ACPController
Can access picker properties and handle events.
Property | Type | ||
---|---|---|---|
color | Get or set the current color | String|Array | Accept: named color, hex rgb, rgb(), rgba(), hsl(), hsla() |
Return: hex rgb or rgba() if alpha != 1 | |||
| |||
palette | Get or set the current palette | Array | Array of colors |
| |||
Function | Parameters | ||
on | Attach an event to the controller. | eventName | See events for detail |
callback | |||
| |||
off | Detach an event from the controller. | eventName | See events for detail |
| |||
show | Show the picker. | ||
| |||
hide | Hide the picker. | ||
| |||
toggle | Show or hide the picker. | ||
| |||
setColor | Set current color | color | Same of 'color' property |
silent | If true the change event will not be triggered | ||
|
options
Property | Type | Default | |
---|---|---|---|
attachTo | Where to attach the picker top element, can be HTMLElement, jQuery object or css selector | String|Object | body |
showHSL | If falsy hide the HSL inputs | Boolean | true |
showRGB | If falsy hide the RGB inputs | Boolean | true |
showHEX | If falsy hide the RGB HEX inputs | Boolean | true |
showAlpha | If truly show control to change opacity | Boolean | false |
color | Initial color | Boolean | #ff0000 |
palette | Array of predefined colors. Each element can be color name, rgb array, hex rgb, rgb(), rgba(), hsl(), hsla() | Array | null |
paletteEditable | If truly make the palette editable | Boolean | false |
useAlphaInPalette | If truly enable alpha channel in palette colors, if 'auto' depends on the value of 'showAlpha' | String|Boolean | auto |
hueBarSize | Size of hue bar in pixel (width, height) | Array | [150,11] |
slBarSize | Size of saturation/luminance canvas in pixel (width, height) | Array | [232,150] |
npm install a-color-picker --save
89 | bower install a-color-picker --save
92 | Define an HTML element to contain the picker and use
102 | AColorPicker.from(selector)
to create it.
103 |
The default picker is created with HSL, RGB and HEX controls.
104 |
The
105 | acp-color
attribute is used to set the initial value.
See the Pen 108 | WJoQBm by Caldi Gianfranco ( 109 | @narsenico) on 110 | CodePen.
111 |Show or hide controls through attributes.
116 |
117 | acp-show-*
attributes accepts
118 | yes/no/true/false
values. Attributes without value are considered
119 | true
.
120 |
See the Pen 123 | a-color-picker demo attr by Caldi Gianfranco ( 124 | @narsenico) on 125 | CodePen.
126 |Show a palette of colors using the
131 | acp-palette
attribute.
132 |
Set a list of colors - named color, hex rgb, rgb(), rgba(), hsl(), hsla() - pipe separated or a predefined palette (PALETTE_MATERIAL_500,
133 | PALETTE_MATERIAL_CHROME).
134 |
The
135 | acp-palette-editable
attribute can be set to allow the user to change the palette.
See the Pen 138 | a-color-picker demo palette editable by Narsenico ( 139 | @narsenico) on 140 | CodePen.
141 |
146 | To attach an event use
147 | on
method and
148 | off
to detach it.
149 |
AColorPicker.from(selector)
150 | .on(eventName, callback)
151 | .off(eventName, callback)
152 | Event name | 156 |Callback parameters | 157 |158 | |
---|---|---|
change | 163 |
164 | picker
165 | |
166 | target | 167 |
170 | color
171 | |
172 | selected color | 173 ||
coloradd | 178 |
179 | picker
180 | |
181 | target | 182 |
185 | color
186 | |
187 | color added | 188 ||
colorremove | 193 |
194 | picker
195 | |
196 | target | 197 |
200 | color
201 | |
202 | color removed or null if all colors are removed | 203 |
212 |
AColorPicker.createPicker(element, options)
225 | AColorPicker.createPicker(options)
227 | Create a color picker.
228 |Parameter | 232 |233 | |
---|---|
element | 238 |HTMLElement, jQuery object or css selector string.
239 | Optional: if not defined, 240 | options.attachTo is used. |
241 |
options | 244 |See
245 | options
246 | Optional only if element is defined. 247 | |
248 |
Return | 253 |254 | |
A 259 | ACPController instance 260 | | 261 |
AColorPicker.from(selector, options)
268 | Create one or more color pickers.
269 |Parameter | 273 |274 | |
---|---|
selector | 279 |HTMLElement, NodeList, jQuery object or css selector string. | 280 |
options | 283 |Optional, see 284 | options 285 | | 286 |
Return | 291 |292 | |
An array of
297 | ACPController. This array has helper methods
298 | on and
299 | off to attach/detach
300 | events to all items.
301 | |
302 |
AColorPicker.parseColor(color, outFormat)
309 | Parse color in input and return formatted value.
310 |Parameter | 314 |315 | |
---|---|
color | 320 |Value to be parsed
321 | Accepts color name, rgb array, hex rgb, rgb(), rgba(), hsl(), hsla() |
322 |
outFormat | 325 |Output format, one of: rgb, rgbcss, rgbcss4, rgba, rgbacss, hsl, hslcss, hslcss4, hsla, hslacss, hex, hexcss4.
326 | If outFormat is a plain object, will be filled with all formats as properties. 327 | |
328 |
Return | 333 |334 | |
Formatted color or
339 | undefined if not recognized.
340 |
355 | |
356 |
ACPController
363 | Can access picker properties and handle events.
364 |Property | 368 |Type | 369 |||
---|---|---|---|
color | 442 |Get or set the current color | 443 |String|Array | 444 |Accept: named color, hex rgb, rgb(), rgba(), hsl(), hsla() | 445 |
Return: hex rgb or rgba() if alpha != 1 | 448 ||||
451 |
471 | |
472 | |||
palette | 477 |Get or set the current palette 478 | | 479 |Array | 480 |Array of colors | 481 |
484 |
488 | |
489 | |||
Function | 494 |Parameters | 495 |||
on | 500 |Attach an event to the controller. | 501 |eventName | 502 |See 503 | events for detail | 504 |
callback | 507 ||||
510 |
511 | |
512 | |||
off | 517 |Detach an event from the controller. | 518 |eventName | 519 |See 520 | events for detail | 521 |
524 |
525 | |
526 | |||
show | 531 |Show the picker. | 532 |||
535 |
536 | |
537 | |||
hide | 542 |Hide the picker. | 543 |||
546 |
547 | |
548 | |||
toggle | 553 |Show or hide the picker. | 554 |||
557 |
558 | |
559 | |||
setColor | 564 |Set current color | 565 |color | 566 |Same of 'color' property | 567 |
silent | 570 |If true the change event will not be triggered | 571 |||
574 | 578 | |
579 |
options
586 |
587 | Property | 591 |592 | | Type | 593 |Default | 594 |
---|---|---|---|
attachTo | 599 |Where to attach the picker top element, can be HTMLElement, jQuery object or css selector | 600 |String|Object | 601 |body | 602 |
showHSL | 605 |If falsy hide the HSL inputs | 606 |Boolean | 607 |true | 608 |
showRGB | 611 |If falsy hide the RGB inputs | 612 |Boolean | 613 |true | 614 |
showHEX | 617 |If falsy hide the RGB HEX inputs | 618 |Boolean | 619 |true | 620 |
showAlpha | 623 |If truly show control to change opacity | 624 |Boolean | 625 |false | 626 |
color | 629 |Initial color | 630 |Boolean | 631 |#ff0000 | 632 |
palette | 635 |Array of predefined colors.
636 | Each element can be color name, rgb array, hex rgb, rgb(), rgba(), hsl(), hsla() |
637 | Array | 638 |null | 639 |
paletteEditable | 642 |If truly make the palette editable | 643 |Boolean | 644 |false | 645 |
useAlphaInPalette | 648 |If truly enable alpha channel in palette colors, if 'auto' depends on the value of 'showAlpha' |
649 | String|Boolean | 650 |auto | 651 |
hueBarSize | 654 |Size of hue bar in pixel (width, height) | 655 |Array | 656 |[150,11] | 657 |
slBarSize | 660 |Size of saturation/luminance canvas in pixel (width, height) | 661 |Array | 662 |[232,150] | 663 |