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

Expose isLight and isDark functions #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hpohlmeyer
Copy link

It is very common to overlay generated colors with text, as you do in the demo screenshot. It would be nice to determine if a generated color is light or dark to decide what color should be used for the overlaying text.

This PR exposes the isLight and isDark functions from 'tinycolor2' to make it easy to determine the lightness of a color.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 99.27% when pulling 541b61a on hpohlmeyer:add-lightness-functions into 62a1833 on ant-design:master.

@afc163
Copy link
Member

afc163 commented Aug 30, 2019

I think you can use tinycolor2 directly.

@hpohlmeyer
Copy link
Author

hpohlmeyer commented Aug 30, 2019

Yes, that’s what I was doing intially, but it could bring maintainance overhead.
I don’t really care for the tinycolor2 version that is used to determine the lightness of the color, but since I would need to use tinycolor2 directly, there are a few ways to approach this:

  1. Use tinycolor2 without having it in the package.json since I know it is there and typescript will notify me if @ant-design/color does not use it anymore.

  2. npm install the latest version of tinycolor2. If @ant-design/color does not use the latest version that would leave me with two versions of tinycolor2.

  3. npm install a specific version of tinycolor2 and manually keep it in sync with the @ant-design/color version, which has to be noted somewhere and could easily be forgotten if someone else is updating the project dependencies.

Having the functions exposed by the @ant-design/color package would just let me use the provided functions without having to manually deal with an additional package.

I was thinking that determining the lightness of a color is a very common practice and thus would be a nice addition to this package.

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.

4 participants