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

[WIP] feat(color): Named color support for color mixins. #155

Merged
merged 1 commit into from
Apr 30, 2017

Conversation

bhough
Copy link
Contributor

@bhough bhough commented Apr 23, 2017

Adds support for CSS named colors in all color mixins. Also fixes shade and tint docs.

Addresses request in #153

@codecov
Copy link

codecov bot commented Apr 23, 2017

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #155   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          63     64    +1     
  Lines         336    343    +7     
  Branches       92     96    +4     
=====================================
+ Hits          336    343    +7
Impacted Files Coverage Δ
src/color/invert.js 100% <ø> (ø) ⬆️
src/internalHelpers/_nameToHex.js 100% <100%> (ø)
src/color/tint.js 100% <100%> (ø) ⬆️
src/color/shade.js 100% <100%> (ø) ⬆️
src/color/parseToRgb.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 ddc6f9e...693d76d. Read the comment docs.

@bhough
Copy link
Contributor Author

bhough commented Apr 23, 2017

@mxstbr @nikgraf @suchipi I'm of two minds on this one:

It is really nice to just be able to use named colors in all our color methods without any extra effort.

But will they be used frequently enough to warrant the ~4kb (1.5 gzipped) overhead on every color mixin? Would it be better to just expose nameToHex as a helper for the times someone wants to pass a named color into a mixin?

@suchipi
Copy link

suchipi commented Apr 23, 2017

You could save some size and duplication by changing parseToRgb, parseToHsl, etc to all call nameToHex internally. Then you wouldn't need to repeat the call in each helper (though it's a little more coupled organizationally).

I personally prefer the helpers handling named colors out of the box because that behavior matches what sass and stylus helpers do. When I ran into this, it was surprising to me to find this wasn't supported by polished out of the box, because someone had described polished to me as "common sass helpers for js". Exporting nameToHex (instead of calling it internally) would provide the tools necessary to handle named colors, but handling it internally provides a smoother developer experience for those who need it, since they don't have to go through the roundabout of realizing they need to handle this case and adding the helper (if they do). So to me it seems like a question of smoother DX ("pit of success") or smaller bundle size.

Copy link
Member

@nikgraf nikgraf left a comment

Choose a reason for hiding this comment

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

I initially didn't add a color map as I was concerned about the total output. I'm still a bit, but definitely can see the benefit for development. (I personally use them a lot for prototyping)

Let's remove the duplicated nameToHex parsings and make it happen 😄

@@ -32,7 +33,8 @@ import curry from '../internalHelpers/_curry'
* }
*/
function opacify(amount: number, color: string) {
const parsedColor = parseToRgb(color)
const normalizedColor = nameToHex(color)
Copy link
Member

Choose a reason for hiding this comment

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

@bhough I think we can drop nameToHex here since it's already done by default in parseToRgb. Same goes for all the other functions including the ones using parseToHsl

@bhough
Copy link
Contributor Author

bhough commented Apr 27, 2017

Good catch @nikgraf. I'll get that taken care of at some point before the weekend.

@bhough bhough force-pushed the named-colors branch 2 times, most recently from f2f0610 to 99f53e7 Compare April 28, 2017 14:29
@bhough
Copy link
Contributor Author

bhough commented Apr 28, 2017

@nikgraf this is ready to re-review.

return toColorString({
...parseToHsl(color),
Copy link
Member

Choose a reason for hiding this comment

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

@bhough one nitpick … can you revert that change? No need to assign the hslColor here

// Note: At a later stage we can optimize this function as right now a hsl
// color would be parsed converted to rgb values and converted back to hsl.
return rgbToHsl(parseToRgb(color))
return rgbToHsl(parseToRgb(normalizedColor))
Copy link
Member

Choose a reason for hiding this comment

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

no need for an assignment here, best to just inline it

return toColorString({
...parseToHsl(color),
...hslColor,
Copy link
Member

Choose a reason for hiding this comment

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

same here, inlining it should save us a couple bites again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I originally did this because we were doing it two different ways across color modules, I'll have to change this back as well as the update the ones where we were doing an assignment.

@bhough bhough force-pushed the named-colors branch 2 times, most recently from ca4d5d3 to e319cae Compare April 28, 2017 16:09
Adds support for CSS named colors in all color mixins. Also fixes some outdated tests for

mix/shade/tint and updates associated docs.
@bhough
Copy link
Contributor Author

bhough commented Apr 28, 2017

@nikgraf ok third time is a charm. I actually cleaned it up some more, found a few more things that eventually call parseToRGB so was able to re move a few more redundant nameToHex calls.

@nikgraf nikgraf merged commit 16ecf5b into master Apr 30, 2017
@nikgraf nikgraf deleted the named-colors branch April 30, 2017 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants