-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: use colord
instead of tinycolor2
in ColorPicker
#34286
Comments
colord
instead of tinycolor2
colord
instead of tinycolor2
in ColorPicker
It seems like colord combined with the names and a11y plugins provides the functionality we need. The readability from tinyColor that is widely used is the same number as contrast in colors. There is a function in tinycolor2 to return the most readable color from an array of colors that we also use in some cases including for providing a public API abstraction on top of (getMostReadableColor), that has nothing equivalent in colord but it is just a simple loop checking the contrast of all the colors in an array and returning the highest so we can easily implement it. I think as long as we add the two plugins we don't need to introduce any breaking change. |
I see this call in #34605: import { colord, extend } from 'colord';
import namesPlugin from 'colord/plugins/names';
import a11yPlugin from 'colord/plugins/a11y';
extend( [ namesPlugin, a11yPlugin ] ); How is it going to scale? Can you extend with the same plugin multiple times? I would also argue if the bundle size is going to be the deciding factor with the plugin architecture, the core library is smaller than but there is additional overhead when using plugins: Anyway, I don't care what you end up using eventually. I just wanted to raise some concerns I had. The call is on your side if it's worth an effort. |
From our initial investigation, I remember finding a potential (small) breaking change: #34014 (comment) @jorgefilipecosta, would you mind looking into it as well and confirming if our initial findings were correct?
Edit: I misread your question. That's actually a great question and something that we should look into — we may need to initialise the plugin in a separate function and maybe implement something similar to the singleton pattern to use the library
Your concerns are definitely relevant! Size is only one potential improvement that we'd enjoy when switching to |
Hi @ciampo, |
Hi @gziolo,
Yes one can extend with the same plugin multiple times If the plugin is already registered as an extension the call to extend does nothing. So I guess the current approach scales and may work, but it is not ideal from the developer experience point of view it would be better to not have to call extend all the time. But I'm not sure how to do that I would appreciate any insights here. |
Let's add those |
I quickly looked into On the other hand, I couldn't find any usage of the The current legacy adapter already takes care of marking those two properties as deprecated. Probably, to avoid introducing more breaking changes than necessary, the better option is to leave the code for the
Regarding the removal of the After that's done, we can remove the |
Good point, I guess we may need to have an oldHue in the state to avoid the issue but we should not pass it on to the onChange it may be relevant internally for the component but is not relevant for users of the component. |
These should be taken care of when we remove tinycolor for the gradient-related components. |
Absolutely — sorry if I didn't explain myself clearly! Nonetheless, something to keep in mind — I assume that the refactor from |
Part of #34284
Why
The
colord
library may be a better replacement fortinycolor2
, which is currently used by theColorPicker
component:What
The maintainer of
colord
reached out to us in a previous PR and suggested we take a look at thecolord
library.We should first assess the feasibility of this refactor (partially started in #34014 (comment))
A/C
colord
provides all needed functionalityThe text was updated successfully, but these errors were encountered: