Skip to content
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

feat: add color pickers #50

Merged
merged 1 commit into from
Oct 22, 2022

Conversation

SethFalco
Copy link
Contributor

@SethFalco SethFalco commented Oct 22, 2022

Not sure about the UI/UX for this, but I've added color pickers now without removing anything that already existed. We should probably have an icon or something to indicate it's for picking color, but I need to give this more thought or ask a designer or something. 🤔

I use the native color input type of the device, for the most part this should offer the most comfortable experience for the user. This also offers a very practical feature as users can use the eyedropper tool to select a color from somewhere else on the screen, including outside of the browser

It works with 1 caveat!

It seems input[type=color] only supports #RRGGBB without alpha. So if a color is typed in manually which featured the alpha component, the color picker will show the color without alpha applied.

This is visible at the start of the GIF attached which shows the color hsla(200%, 0%, 0%, .7), with the alpha channel stripped off, this is ultimately black so the color picker displays the color black.

color-pickers

Debian 11 (Linux) / Chromium installed via Snap.

image

Debian 11 (Linux) / Firefox Nightly installed via archive from website.

20221022_16h53m32s_grim

postmarketOS (Linux) / Firefox (Looks like they never mobile optimized the modals, so I had to disable my UI scaling to see the whole color picker, but it does "work". I'll just report that issue up to the relevent repo. ^-^')

Relates to

Signed-off-by: Seth Falco <seth@falco.fun>
@LeaVerou
Copy link
Collaborator

LeaVerou commented Oct 22, 2022

Hey, thanks for working on this! My understanding of how people use this site is that they already have a color pair to compute, so they are pasting it in, and often adjusting it to pass (hence the Incrementable). Have you come across use cases where people actually pick the colors in the contrast checker? Have you needed it?

(I'm not opposed to it, but a sanity check is always useful, so that we don't add features just for completeness)

@SethFalco
Copy link
Contributor Author

SethFalco commented Oct 22, 2022

Yeah, I actually wanted to PR this for a while for my own usage!

I don't use the native increment feature/library myself since I mostly play with hex, but I do manually adjust the hex values in increments when under the same use-case you covered. (i.e. I know the 2 colors I want like with links, but just need to get the readability.)

However, I do find myself favoring the color picker in some cases, these are listed in order of occurrence:

  1. Rather than checking my own resource or web development, I'm reviewing someone's else assets. Like game UI/HUD designs, Twitch overlays, or a Qt/Flutter application. So, I want to use the colors from there, where I don't have neatly prepared CSS-like values already.
  2. I'm just not confident in my color choice and want to explore a bit, I'm no designer, so I don't know what works half the time, it's convenient to select the color where I immediately see the contrast ratio as well. ^-^'
  3. I incremented the colors to get a readable result but then find it resulted in an ugly shade. (Especially with yellows/greens.) 😭

To cover 1, I've worked around it by taking a screenshot, pasting it in GIMP, then using the eyedrop tool and pasting the values over to the site which is a bit cumbersome. ^-^'

That's also why I highlighted something I think is great is being able to use the eyedrop tool from the native color picker that pops up, since then, I can just open whatever I'm reviewing and use the eyedropper to select the colors out of it.

It's worth noting I don't only rely on this tool for web development, but within things like graphics design as well. For me, it's less about background color + text, and more about background color + subject. If anything, maybe the example text should even feature some SVG icons and such!

* Make each element with an ID a global variable.
* Many browsers do this anyway (it’s in the HTML5 spec), so it ensures consistency.
*
* https://html.spec.whatwg.org/multipage/window-object.html#named-access-on-the-window-object
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me, at this point is there any current browser that doesn't do this? If not, we could just remove this code.

Copy link
Contributor Author

@SethFalco SethFalco Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment actually taught me that this was a thing at all. I had no idea this was standard behavior. When I looked into it, I mostly found comments to avoid depending on that part of the spec, though. (i.e. if in future there is a global called background, then it'll break the site) ^-^'

I can only confirm that Chromium and Firefox Nightly have this behavior by default, though. Not sure what I'd search on Can I Use to check for this. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should probably keep the loop but assign them to some custom object (e.g. dom).

@LeaVerou
Copy link
Collaborator

LeaVerou commented Oct 22, 2022

Thank you for the extensive feedback on how you use contrast-ratio! I'm fine to merge this, can't hurt and I don't see any issues with it. We'll ditch the toHex() method etc once we migrate to using Color.js instead of an ad hoc Color class (which I will do as soon as I add alpha blending to Color.js and we resolve in the CSS WG how we calculate contrast of semi-transparent colors — since WCAG has resisted adding anything on this).

I incremented the colors to get a readable result but then find it resulted in an ugly shade. (Especially with yellows/greens.) 😭

This is why adjusting in RGB (including hex) is a generally a poor idea for adjusting lightness or luminance. HSL works much better for that, and soon LCh/Oklch will work even better.

@LeaVerou LeaVerou merged commit d6bedf7 into siege-media:gh-pages Oct 22, 2022
@SethFalco SethFalco deleted the add-color-pickers branch May 1, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color Picker to choose color
2 participants