new Picker(options)
Create a color picker.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object | @see |
Examples
var picker = new Picker(myParentElement);
picker.onDone = function(color) {
myParentElement.style.backgroundColor = color.rgbaString;
};
var picker = new Picker({
parent: myParentElement,
color: 'gold',
onChange: function(color) {
myParentElement.style.backgroundColor = color.rgbaString;
},
});
Members
-
onChange :Picker~colorCallback
-
Callback whenever the color changes.
Type:
-
onDone :Picker~colorCallback
-
Callback when the user clicks "Ok".
Type:
-
onOpen :Picker~colorCallback
-
Callback when the popup opens.
Type:
-
onClose :Picker~colorCallback
-
Callback when the popup closes.
Type:
-
<static> StyleElement
-
The
<style>element for picker CSS which is added to the document.
Methods
-
setOptions(options)
-
Set the picker options.
Parameters:
Name Type Description optionsObject Properties
Name Type Argument Default Description parentHTMLElement Which element the picker should be attached to.
popup'top' | 'bottom' | 'left' | 'right' | false <optional>
right If the picker is used as a popup, where to place it relative to the parent.
falseto add the picker as a normal child element of the parent.templatestring <optional>
Custom HTML string from which to build the picker. See /src/picker.pug for required elements and class names.
layoutstring <optional>
default Suffix of a custom "layout_..." CSS class to handle the overall arrangement of the picker elements.
alphaboolean <optional>
true Whether to enable adjusting the alpha channel.
editorboolean <optional>
true Whether to show a text field for color value editing.
editorFormat'hex' | 'hsl' | 'rgb' <optional>
hex How to display the selected color in the text field (the text field still supports input in any format).
cancelButtonboolean <optional>
false Whether to have a "Cancel" button which closes the popup.
colorstring <optional>
Initial color for the picker.
onChangefunction <optional>
@see
onChangeonDonefunction <optional>
@see
onDoneonOpenfunction <optional>
@see
onOpenonClosefunction <optional>
@see
onClose -
openHandler()
-
Default behavior for opening the popup
-
closeHandler()
-
Default behavior for closing the popup
-
movePopup(options, open)
-
Move the popup to a different parent, optionally opening it at the same time.
Parameters:
Name Type Description optionsObject @see
setOptions()(Usually a new.parentand.color).openboolean Whether to open the popup immediately.
-
setColor(color, silent)
-
Set/initialize the picker's color.
Parameters:
Name Type Description colorstring Color name, RGBA/HSLA/HEX string, or RGBA array.
silentboolean If true, won't trigger onChange.
-
setColour()
-
- See:
-
show()
-
Show/open the picker.
-
hide()
-
Hide the picker.
-
destroy()
-
Release all resources used by this picker instance.
Type Definitions
-
colorCallback(color)
-
A callback that gets the picker's current color value.
Parameters:
Name Type Description colorObject Properties
Name Type Description rgbaArray.<number> RGBA color components.
hslaArray.<number> HSLA color components (all values between 0 and 1, inclusive).
rgbStringstring RGB CSS value (e.g.
rgb(255,215,0)).rgbaStringstring RGBA CSS value (e.g.
rgba(255,215,0, .5)).hslStringstring HSL CSS value (e.g.
hsl(50.6,100%,50%)).hslaStringstring HSLA CSS value (e.g.
hsla(50.6,100%,50%, .5)).hexstring 8 digit #RRGGBBAA (not supported in all browsers).