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(getLuminance): Add getLuminance function #163

Merged
merged 7 commits into from
Aug 31, 2017

Conversation

jcquinlan
Copy link
Contributor

Closes #148

At least partially, as it allows the user to get the value, but doesn't have an accompanying setter to change the luminance. It seemed like this was already being handled by other methods.

I feel like to really make this useful, another method would need to allow a user to compare the contrast ratio of two colors and return a boolean stating whether or not it adheres to the W3C specs.

@codecov
Copy link

codecov bot commented May 4, 2017

Codecov Report

Merging #163 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #163   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          68     69    +1     
  Lines         386    388    +2     
  Branches      102    102           
=====================================
+ Hits          386    388    +2
Impacted Files Coverage Δ
src/color/readableColor.js 100% <100%> (ø) ⬆️
src/color/getLuminance.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be8b05a...3d19092. Read the comment docs.

@bhough
Copy link
Contributor

bhough commented May 4, 2017

Thanks for the PR @jcquinlan. I definitely think we should at least add some sort of guard type functionality http://lesscss.org/features/#mixin-guards-feature that allows us to check the lightness or darkness of a color. There are also things we can do related to contrast here that would also be useful: https://codepen.io/giana/project/full/ZWbGzD

But I agree, getLuminance isn't necessarily useful on its own.

@souporserious
Copy link
Contributor

souporserious commented May 7, 2017

Awesome to see this in a PR! I was thinking about it, and do you think it should be called getLightness to be in line with the already existing setLightness?

@jcquinlan
Copy link
Contributor Author

@souporserious Hey sorry I ripped off your idea! I was bored at a conference and wanted to do some coding, I hope you don't mind!

As per the suggestion of @bhough it might be a good idea to use this as a stepping stone to creating some of the guards and more full fleshed-out brightness tools that exist elsewhere.

@souporserious
Copy link
Contributor

Oh no, not at all! I'm glad someone found the time to implement it 🙂

@wtgtybhertgeghgtwtg
Copy link
Contributor

Other than the conflicting files, is there anything in particular that is holding this up?

@bhough
Copy link
Contributor

bhough commented Jul 30, 2017

@wtgtybhertgeghgtwtg it needs several things:

  1. Conflicts resolved
  2. Proper eslint comments per: fix(color): Improve the library size for webpack #204
  3. Ideally, I believe it was intended to work in conjunction with: https://github.com/styled-components/polished/pull/217/files
  4. Would also need tests for the other color spaces

Copy link
Contributor

@bhough bhough left a comment

Choose a reason for hiding this comment

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

Couple of other misc. comments:

  1. You will also need to add this to https://github.com/styled-components/polished/blob/master/src/index.js so it can be properly imported using destructured imports. (I always forget to do this).

  2. I would love if we can replace the formula in readableColor with this helper for consistency's sake: https://github.com/styled-components/polished/blob/master/src/color/readableColor.js

Otherwise looking good, and definitely want to get this merged in as soon as it is ready.

// @flow
import getLuminance from '../getLuminance'

describe('getLuminance', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would like to see the tests for all color spaces if possible (rgb, hsl, hsla, and a named CSS color) if we could.

return (0.2126 * r) + (0.7152 * g) + (0.0722 * b)
}

export default curry(getLuminance)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be updated based on #204

- export default curry(getLuminance)
+ // Don’t inline this variable into export because Rollup will remove the /*#__PURE__*/ comment
+ const curriedGetLuminance = /*#__PURE__*/ curry(getLuminance) // eslint-disable-line spaced-comment
+ export default curriedGetLuminance

import curry from '../internalHelpers/_curry'

/**
* Returns a number representing the luminance of a color.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe clarify that this is a percentage (float)?

README.md Outdated
@@ -146,6 +146,7 @@ In the documentation you will see examples using [object spread properties](http
<li><a href="http://polished.js.org/docs/#rgbacolor">RgbaColor</a></li>
<li><a href="http://polished.js.org/docs/#rgbcolor">RgbColor</a></li>
<li><a href="http://polished.js.org/docs/#timingfunction">TimingFunction</a></li>
<li><a href="http://polished.js.org/docs/#getluminance">getLuminance</a></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is getting put in the wrong spot, due to it missing from documentation.json. If you add it, this should get inserted into the proper place in the readme and the documentation.

@bhough
Copy link
Contributor

bhough commented Aug 18, 2017

@jcquinlan I was just starting to look at this myself, so I already merged the rebase with master into your fork 😎

@bhough bhough merged commit a72699a into styled-components:master Aug 31, 2017
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.

None yet

4 participants