Color format used by the color picker. The format affects which value is shown in the input field.
hex
outputs #RRGGBB
or #RRGGBBAA
.rgb
outputs rgb(R, G, B)
or rgba(R, G, B, A)
.hsl
outputs hsl(H, S, L)
or hsla(H, S, L, A)
.auto
guesses the format from the active input field. Defaults to hex
if
it fails.mixed
outputs #RRGGBB
when alpha is 1; otherwise rgba(R, G, B, A)
.A function that is called whenever a new color is picked.
The newly selected color, as a CSS color string.
All color themes supported by the color picker. More themes might be added in the future.
All theme modes.
The color picker dialog can be closed by clicking anywhere on the page or by pressing the ESC on the keyboard. The later will also revert the color to its original value.
If you would like to close the dialog programmatically, you can do so by calling this method.
When true
, resets the color to its original
value. Defaults to false
.
Converts an input field to a color picker input.
Initializes the Coloris color picker and binds the color picker to all
input fields with the data-coloris
attribute.
When the script file is loaded directly in a browser, this method is called automatically. When called in a module environment (e.g. browserify, rollup, or webpack), you need to call this method once before any other calls to any {@link Coloris} methods. This method checks for when the document is ready, so you do not have to call this method inside some document ready block.
Removes a virtual instance that was added by setInstance. Note that
to remove an instance, the selector must be exactly equal to what was passed
to setInstance
, it cannot merely be a different selector that happens to
match the same elements.
CSS selector to remove from the set of virtual instances.
Adds a virtual instance with separate options.
Although there is only one physical instance of the color picker in the document, it is possible to simulate multiple instances, each with its own appearance and behavior, by updating the configuration at runtime, when the color picker is opened.
Here is an example of how to do it by manually setting configuration options in response to click events:
// Regular color fields use the default light theme
document.querySelectorAll('.color-fields').forEach(input => {
input.addEventListener('click', e => {
Coloris({
theme: 'default',
themeMode: 'light',
});
});
});
// But the special color fields use the polaroid dark theme
document.querySelectorAll('.special-color-fields').forEach(input => {
input.addEventListener('click', e => {
Coloris({
theme: 'polaroid',
themeMode: 'dark',
});
});
});
This works well and is quite versatile, but it can get a little hard to keep track of each change every "instance" makes and revert them to the default values.
So as of version 0.15.0, there is a new way to automatically manage virtual instances. This works by assigning configuration overrides to a CSS selector representing one or more color fields.
CSS selector for the input fields to which the options should apply.
Options to apply to all color picker input fields matching the given selector.
Update the color picker's position and the color gradient's offset.
Generated using TypeDoc
The main entry point or namespace for Coloris. This object is callable and can be used to initialize Coloris. It also contains several utility methods.