styled-components / polished

A lightweight toolset for writing styles in JavaScript ✨
https://polished.js.org/
MIT License
7.64k stars 209 forks source link

feat: eased gradients #523

Closed ricokahler closed 4 years ago

ricokahler commented 4 years ago

This PR is still a work in progress but I wanted to pause here for feedback. For the most part, this PR is as planned from #441 but instead of changing the cubic bezier functions to number array's, I opted to parse them via regex since that's how colors are read anyway.

Currently, this PR just adds a few functions that will eventually power eased gradients. The main one is getScale which will eventually be imported in linearGradient and radialGradient to enable eased gradients via the color stop array (with no breaking API change).

getScale accepts color stops with timing functions in between them. Refer to the tests for usage.

TODO:

Screenshots (for getScale)

image

image

Here's one with an eased gradient 👇

image


Anyway, at this point I think you can see where I'm going with this, and to be honest, I'm not sure I like these changes. It's a lot of code for a relatively niche feature and I'm wondering if you can think of a more simple way to get this done.

Let me know what you think!

cc @bhough

ricokahler commented 4 years ago

I just noticed my branch includes some isValidColor stuff. I don't know how that got in there but ignore it in the diff for now.

codecov[bot] commented 4 years ago

Codecov Report

Merging #523 into version-4-0-release will decrease coverage by 0.94%. The diff coverage is 89.65%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           version-4-0-release     #523      +/-   ##
=======================================================
- Coverage                99.88%   98.94%   -0.95%     
=======================================================
  Files                       87       91       +4     
  Lines                      857      944      +87     
  Branches                   325      344      +19     
=======================================================
+ Hits                       856      934      +78     
- Misses                       1        6       +5     
- Partials                     0        4       +4     
Flag Coverage Δ
#unittests 98.94% <89.65%> (-0.95%) :arrow_down:
Impacted Files Coverage Δ
src/internalHelpers/_parseTimingFunction.js 57.89% <57.89%> (ø)
src/color/getScale.js 94.44% <94.44%> (ø)
src/color/isValidColor.js 100.00% <100.00%> (ø)
src/internalHelpers/_normalizeColorStopArray.js 100.00% <100.00%> (ø)

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 4024710...b578950. Read the comment docs.

ricokahler commented 4 years ago

So I've sat on this for a while and I just don't like this approach. Since there's no easy way to create a timing function, I would advise to not ship eased gradients in v4.