ant-design / ant-design-colors

:art: Color Palettes Calculator of Ant Design
https://ant.design/docs/spec/colors
MIT License
652 stars 79 forks source link

Expose isLight and isDark functions #36

Open hpohlmeyer opened 5 years ago

hpohlmeyer commented 5 years ago

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 commented 5 years ago

Coverage Status

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

afc163 commented 5 years ago

I think you can use tinycolor2 directly.

hpohlmeyer commented 5 years ago

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.