-
-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switching between Picker options #248
Comments
For anyone that stumbles upon a similar requirement, I found the solution to this with css.
I'm going to leave this issue open in case it helps anyone else or if anyone comes up with a better solution. |
I just stumbled across this issue and I tested it in a different way since I am doing this just with colors. I don't know how you do this, but if you work with JavaScript you can set the background-image or background-color of the button where the pickr is attached to quite easily. Since the pickr is event-driven you can change css-elements with JavaScript when an event happens. Let's assume we've got the default pickr: // Simple example, see optional options for more configuration.
const pickr = Pickr.create({
el: htmlElement,
theme: 'classic', // or 'monolith', or 'nano'
swatches: [
'rgba(244, 67, 54, 1)',
'rgba(233, 30, 99, 0.95)',
'rgba(156, 39, 176, 0.9)',
'rgba(103, 58, 183, 0.85)',
'rgba(63, 81, 181, 0.8)',
'rgba(33, 150, 243, 0.75)',
'rgba(3, 169, 244, 0.7)',
'rgba(0, 188, 212, 0.7)',
'rgba(0, 150, 136, 0.75)',
'rgba(76, 175, 80, 0.8)',
'rgba(139, 195, 74, 0.85)',
'rgba(205, 220, 57, 0.9)',
'rgba(255, 235, 59, 0.95)',
'rgba(255, 193, 7, 1)'
],
components: {
// Main components
preview: true,
opacity: true,
hue: true,
// Input / output Options
interaction: {
hex: true,
rgba: true,
hsla: true,
hsva: true,
cmyk: true,
input: true,
clear: true,
save: true
}
}
}); Now let's assume we have a png, jpeg, svg or whatever image-format in a folder named pickr.on('init', pickr => {
htmlElement.style.backgroundImage = "url('img/test.png')"
}) If we want to set it after a clear we can do this: pickr.on('clear', pickr => {
htmlElement.style.backgroundImage = "url('img/test.png')"
}) Instead of using a background-image we can also set the selected color of the pickr: pickr.on('init', pickr => {
htmlElement.style.backgroundColor = pickr.getColor().toRGBA().toString(0)
}) I hope this is what you were looking for. If not then I am sorry to had a wrong assuming. |
I have a design requirement that states if a user has not selected a color there is an eyedropper svg button and when a color has been selected the selected color is shown. I've tried updating the value of
useAsButton
through thesave
event handler when the selected color object is null or has a color accordingly but that does not update the picker button. The only other idea I have would be to re-render the picker instance but that would remove the already selected color. Would this be possible?The text was updated successfully, but these errors were encountered: