-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add support of HSL functional notation for output colors #43128
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
[Console] Add support of HSL functional notation for output colors #43128
Conversation
Also add a missing test for RGB functional notation
16048c9
to
0cbd988
Compare
technically, CSS does not restrict you to integer percentages. |
That's right! My comment is a bit misleading on this point. Do you mean we should support these values as well? I think it doesn't worth the additional complexity it would bring to code in my opinion. |
I was on the verge of closing the other PR, and I maybe should have done that. Anything can be converted to |
[$hue, $saturation, $lightness] = \array_slice($matches, 1); | ||
|
||
if ($hue > 359) { | ||
throw new InvalidArgumentException(sprintf('Invalid hue; value should be between 0 and 359, got %d.', $hue)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this exception ? In CSS, hsl(4236, 50%, 50%)
is valid. 4236deg
is equivalent to 276deg
as hue as far as the color is concerned (but it may make a difference regarding transitions, I'm not sure)
I tend to agree with @fabpot here. Given that this PR only deals with hsl to convert it back to hex RGB, which is already supported as input, the Console component does not really need to support HSL strings. You could use a separate PHP package providing such conversion (and maybe even providing a PHP function named |
I can totally understand your point of view. Maybe this one's a bit too far given the console context. The last comment by @stof is also relevant. I'm closing it, thanks for the review anyways! |
Also add a missing test for RGB functional notation
Yes. But wait. That's not just "another way to set colors". Of course RGB notation suits most cases and is some kind of a "must" when it comes to colors. But HSL notation has some undeniable pros over RGB notation. There's a great (french) article speaking about it (https://iamvdo.me/blog/les-avantages-de-hsl-par-rapport-a-rgb). To make it simple, HSL is way more effective when it comes to manipulating color gradients in particular. By adding this feature, we're giving this possibility to developers using Console components to make even more gorgeous CLI applications.
I don't think we need to add (yet, at least) other variations like CMYK or HSV. I rarely came across them, and it seems they’re clearly not as popular as RGB and HSL.
About having to put
%
in the notation, I think it's a good choice for two reasons.[0, 1]
means, if we want to be exhaustive, we need to check these values can be in multiple format:0.5
,.5
, maybe1.
. Having the mandatory percent sign clearly tells the developer to use an integer in the interval[0, 100]
.hsl
method in CSS.