-
Notifications
You must be signed in to change notification settings - Fork 34
Home
- setColorPicker
- getValue
- getSafeValue
- getColorValue
- getPrefixedValues
- change
- setDirection
- getDirection
- setType
- getType
- addHandler
- getHandler
- getHandlers
- clear
- getSelected
- updatePreview
- render
Set custom color picker
Parameters
-
cp
Object Color picker interface
Examples
const gp = new Grapick({
el: '#gp',
colorEl: '<input id="colorpicker"/>'
});
gp.setColorPicker(handler => {
const colorEl = handler.getEl().querySelector('#colorpicker');
// Or you might face something like this
colorPicker({
el: colorEl,
startColoer: handler.getColor(),
change(color) {
handler.setColor(color);
}
});
// jQuery style color picker
$(colorEl).colorPicker2({...}).on('change', () => {
handler.setColor(this.value);
})
})
Get the complete style value
Parameters
type
angle
Examples
const ga = new Grapick({...});
ga.addHandler(0, '#000');
ga.addHandler(55, 'white');
console.log(ga.getValue());
// -> `linear-gradient(left, #000 0%, white 55%)`
Returns string
Get the gradient value with the browser prefix if necessary
Parameters
type
angle
Returns string
Get only colors value
Examples
const ga = new Grapick({...});
ga.addHandler(0, '#000');
ga.addHandler(55, 'white');
console.log(ga.getColorValue());
// -> `#000 0%, white 55%`
Returns string
Get an array with browser specific values
Parameters
type
angle
Examples
const ga = new Grapick({...});
ga.addHandler(0, '#000');
ga.addHandler(55, 'white');
console.log(ga.getPrefixedValues());
// -> [
"-moz-linear-gradient(left, #000 0%, white 55%)",
"-webkit-linear-gradient(left, #000 0%, white 55%)"
"-o-linear-gradient(left, #000 0%, white 55%)"
]
Returns Array
Trigger change
Parameters
-
complete
Boolean Indicates if the change is complete (eg. while dragging is not complete) (optional, default1
)
Set gradient direction, eg. 'top', 'left', 'bottom', 'right', '90deg', etc.
Parameters
-
direction
string Any supported direction
Set gradient direction, eg. 'top', 'left', 'bottom', 'right', '90deg', etc.
Parameters
-
direction
string Any supported direction
Set gradient type, available options: 'linear' or 'radial'
Parameters
type
-
direction
string Any supported direction
Get gradient type
Returns string
Add gradient handler
Parameters
-
position
integer Position integer in percentage -
color
string Color string, eg. red, #123, 'rgba(30,87,153,1)', etc.. -
select
Boolean Select the handler once it's added (optional, default1
)
Returns Object Handler object
Get handler by index
Parameters
-
index
integer
Returns Object
Get all handlers
Returns Array
Remove all handlers
Return selected handler if one exists
Returns (Handler | null)
Update preview element
Render the gradient picker
Set color
Parameters
-
color
string Color string, eg. red, #123, 'rgba(30,87,153,1)', etc.. -
complete
Boolean Indicates if the action is complete (optional, default1
)
Examples
handler.setColor('red');
Set color
Parameters
-
position
integer Position integer in percentage, eg. 20, 50, 100 -
complete
Boolean Indicates if the action is complete (optional, default1
)
Examples
handler.setPosition(55);
Get color of the handler
Returns string Color string
Get position of the handler
Returns integer Position integer
Indicates if the handler is the selected one
Returns Boolean
Get value of the handler
Examples
handler.getValue(); // -> `black 0%`
Returns string
Select the current handler and deselect others
Deselect the current handler
Remove the current handler
Returns Handler Removed handler (itself)
Get handler element
Returns HTMLElement
Render the handler
Returns HTMLElement Rendered element