jaames / iro.js

šŸŽØ Modular color picker widget for JavaScript, with support for a bunch of color formats
https://iro.js.org
Mozilla Public License 2.0
1.32k stars 83 forks source link

iro.js 5.0 discussion #83

Closed jaames closed 4 years ago

jaames commented 5 years ago

What a wild year! iro.js hit 500 stars on Github, over 1000 NPM installs per week, and was featured on a number of web publications such as Creative Bloq, Codrops and JS Weekly!

I've been thinking a lot about what the next steps for this project might look like now that it's finally stable and fitting most people's requirements pretty well. I figured it would be worth sharing my ideas for discussion:

I think this would take iro.js to the next level and make it one of the best damn color picker libraries out there. I welcome everybody's opinions though!

jaames commented 4 years ago

@rwwagner90 Things are going alright! I'm still working away on updating the documentation website, progress has been a little slow since I've also been busy with freelance work and applying to a job, but it is very nearly done now. I just need to give it a bit more polish and write some examples to demonstrate new features.

At the moment the handle for the currently active color should always be drawn on top of the others. SVG doesn't really support anything like CSS' z-index, so the 'top' handle is always last. As such, it's possible to target the 'active' color's handle with a CSS selector like .IroColorPicker .IroHandle:last-of-type, but it's not possible to target any handle by its associated color.

I'll look into making it a bit easier to target specific handles after the docs are done :)

RobbieTheWagner commented 4 years ago

@jaames sounds good! Docs in general are definitely more important.

At the moment the handle for the currently active color should always be drawn on top of the others. SVG doesn't really support anything like CSS' z-index, so the 'top' handle is always last. As such, it's possible to target the 'active' color's handle with a CSS selector like .IroColorPicker .IroHandle:last-of-type, but it's not possible to target any handle by its associated color.

Sounds like we may need a function like makeActiveColor where we could set which color / handle are active and move that svg to last in the list, so it is on top.

jaames commented 4 years ago

@rwwagner90 There's a setActiveColor method that should do the trick!

Obviously the multicolor stuff isn't publicly documented yet (...heh), but here's the relevant part of the source if you want to see what's available: https://github.com/jaames/iro.js/blob/e66e0ee560bc0be31fe2fb8d8e0af203057380ac/src/ColorPicker.tsx#L79-L113

RobbieTheWagner commented 4 years ago

@jaames setActiveColor doesn't seem to change the color selected. Are you sure it is working as intended?

jaames commented 4 years ago

@rwwagner90 It's the same method called internally when you interact with one of the UI handles, so as long as the last handle you interacted with is shown on top of all the others, it should definitely be working correctly. setActiveColor expects to be passed the color index rather than the color value though, maybe that's catching you out?

In lieu of documentation I put together a quick Codepen demo, hopefully that will help make things a bit clearer :) https://codepen.io/rakujira/pen/bGddRyq?editors=0010

RobbieTheWagner commented 4 years ago

@jaames I was passing the index. It still doesn't seem to work for me. However, I do not have a reference to the actual color index, I was just setting to the index it was from the order of colors I had. If I set all the colors a few times, does the index keep growing? I wonder if with several palettes, my indices are like 15, even though I only have 4-5 colors.

I suppose I should find a way to store the index somehow to be sure.

jaames commented 4 years ago

@rwwagner90 Ah, my bad. The color index shouldn't keep growing, assuming that you're using the setColors() method I posted whenever you switch the color palette? Are you setting the palette as a series of color values (like hex strings or whatever) or are you using the iro.Color objects that iro.js provides?

I'll take a deeper look tomorrow since it's getting late here, but sounds like there might be a bug on my end somewhere if that doesn't work as expected.

RobbieTheWagner commented 4 years ago

@jaames I'm doing this this.colorPicker.setColors(this.selectedPalette.colors.mapBy('hex')); so I am setting colors as hex. Should I be doing something else?

jaames commented 4 years ago

@rwwagner90 That looks correct to me.

I made a basic multi-palette demo on Codepen to test, and everything seems to be working okay as far as I can tell. Not sure if there was something I missed? The only change I made was having setColors fire its own event so I could re-render the color swatch HTML whenever the selected palette is switched.

https://codepen.io/rakujira/pen/poJJYVP?editors=0010

I should maybe mention that only the active color handle is guaranteed to be drawn on top of the other ones. The other handles will be drawn in the same order that they're provided to the color picker with.

RobbieTheWagner commented 4 years ago

@jaames when I call setActiveColor nothing happens at all for me. The handle does not move, and the slider does not switch to the new color. I'll try to debug more later today. Should I be creating iro color objects instead of using hex values?

jaames commented 4 years ago

@rwwagner90 That's really strange. Just to rule out any potential browser differences, does that last Codepen work for you? It shouldn't matter whether you use color objects or hex values, etc -- setColors() will work with either.

I'm not extremely familiar with Ember, but is there a chance that it's doing something that affects the color picker in some way? If you don't manage to get to the bottom of it, I think a reproduction repo would be helpful.

RobbieTheWagner commented 4 years ago

@jaames yeah, the codepen works for me. I will debug more later and report back. To confirm, this should work in 5.0.0-5 right?

jaames commented 4 years ago

@rwwagner90 Yeah, 5.0.0-5 is the right version.

RobbieTheWagner commented 4 years ago

@jaames I got it to work. I was doing something dumb. Sorry about that!

I was just looking at the image above of the new stuff like the square picker, additional slider types, etc and I was curious if that stuff had also been implemented? I would love to try some of it out šŸ˜ƒ

jaames commented 4 years ago

@rwwagner90 Hah, no worries!

Yep, those are implemented now! The documentation can be found here: https://iro.js.org/advanced.html#custom-ui-layouts

jaames commented 4 years ago

Also, I finally published iro.js v5 and the new documentation site! I'm going to continue working on things over the course of the next week or two, so there's still some pending changes on the docsite and little bits like the readme that I need to finish. :)

But without further ado, here's the full v5 changelog! šŸŽ‰

Additionally, there's some smaller features that I'm hoping to add next week:

I'm sorry that it's taken me so long to finish all of this - it's been a pretty big undertaking! I also owe a huge thanks to @rwwagner90 from Ship Shape for sponsoring the project, it's really helped out a lot :)


I'm going to close this thread now, but please feel free to continue the conversation! You can also reach me via email, Twitter or Discord (jaames#9860)

RobbieTheWagner commented 4 years ago

Thanks so much for all the hard work @jaames! We'll hopefully be announcing our product using your library soon šŸ˜ƒ