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

color.channel can not auto convert between spaces and wrong docs about it #2353

Closed
Mister-Hope opened this issue Sep 18, 2024 · 1 comment · Fixed by #2354
Closed

color.channel can not auto convert between spaces and wrong docs about it #2353

Mister-Hope opened this issue Sep 18, 2024 · 1 comment · Fixed by #2354
Assignees
Labels
cosmetic Doesn't affects CSS semantics enhancement

Comments

@Mister-Hope
Copy link

Mister-Hope commented Sep 18, 2024

Reproduction: https://sass-lang.com/playground/#eJwzNHAoLU5VUCpOLC62Ss7PyS9SsubiUgGzrBSU00zTzNPSgCIOKalJpekKYHG95IzEvLzUHA2IMh0F9fKMzJLUvNTiYnVNawAzfhqY

@use "sass:color";

$color: #f5f7ff;

@debug color.channel($color, 'whiteness');

$channel: Color #f5f7ff has no channel named whiteness.
  ╷
5 │ @debug color.channel($color, 'whiteness');
  │        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  - 5:8  root stylesheet

I don't think this is the expected behavior.

The docs says:

⚠️ Heads up!

Because color.whiteness() is redundant with color.channel(), it’s no longer recommended. Instead of color.whiteness($color), you can write color.channel($color, "whiteness").

However, the correct name should be lightness or blackness on the color space docs. Something worth noting is that the deprecation also requires users to convert color space manually, as color.channel won't do that. An exmaple here:

@use "sass:color";

$color: #f5f7ff;

// $channel: Color #f5f7ff has no channel named lightness.
@debug color.channel($color, 'lightness');
// works and return 98.0392156863%
@debug color.channel(color.to-space($color, hsl), 'lightness');

So I believe at least the docs needs an update.

If the current behavior of color.channel is a bug, and sass team believes a channel name could be returned with any legacy color space by automatically converted to a correct space behind the sence, then only whiteness and blackness should be corrected in docs.

Otherwise, every deprecation about color.channel should be corrected, like color.red($color) must be replaced by color.channel(color.to-space($color, rgb), 'red'), unless the developer is sure that $color MUST be in rgb space

@Mister-Hope Mister-Hope changed the title color.channel can not auto convert between spaces color.channel can not auto convert between spaces and wrong docs about it Sep 18, 2024
@nex3
Copy link
Contributor

nex3 commented Sep 19, 2024

color.channel($color, "whiteness") is valid, but only if the color is in the HWB color space (example). From the color.channel() documentation:

Returns the value of $channel in $space, which defaults to $color’s space.

When you call color.channel(#f5f7ff, "whiteness"), the $space argument defaults to rgb because that's the color space of hex colors. If you explicitly pass $space: hwb, it will work regardless of the space of the input color (example).

It is probably worth adding the explicit $space parameter to the deprecation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cosmetic Doesn't affects CSS semantics enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants