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

SCSS Functions for Black/White (with Alpha) #28

Open
ReneDrie opened this issue Oct 17, 2023 · 6 comments
Open

SCSS Functions for Black/White (with Alpha) #28

ReneDrie opened this issue Oct 17, 2023 · 6 comments

Comments

@ReneDrie
Copy link
Contributor

ReneDrie commented Oct 17, 2023

For a lot of projects we use white and black with an Alpha channel for colors/backgrounds/lines etc. Would it be convenient if we create 2 functions for this? So you can do something like:

color: white(0.5)
background: black(0.5)

Implementation is probably quite simple, but something in the lines of:

@function white($alpha: 1) {
  @return rgba(255, 255, 255, $alpha);
}
@function black($alpha: 1) {
  @return rgba(0, 0, 0, $alpha);
}
@tworrisb
Copy link
Contributor

tworrisb commented Oct 18, 2023

Can we maybe also do something like:

@function color($color, $alpha: 1) {
  @return rgba(#{$color}, $alpha);
}

@tworrisb tworrisb assigned tworrisb and unassigned tworrisb Oct 18, 2023
@ThaNarie
Copy link
Member

ThaNarie commented Oct 18, 2023

@tworrisb What would your function add?

black; // normal
color(black); // yours

rgb(white / 0.8); // normal
color(white, 0.8); // yours

I only see more typing, with no saved benefit?

@ReneDrie
Copy link
Contributor Author

I also agree that I don't see the benefit of that.

@nswaldman
Copy link

nswaldman commented Oct 19, 2023

I don't like either proposal over just writing rgba(black, 0.5) and rgba(white, 0.5).

On the one had we have two functions that do the same to one hard-coded colour each. So any deviation of how a design treats these two colours (a previous project had $black: #1d1d1d;) renders these functions useless. On the other hand we have a function that is rgba() with extra steps.

There's less moving parts to just writing rgba(black, 0.5), rgba(white, 0.5) or rgba($black, 0.5).

@ThaNarie
Copy link
Member

I was slightly mistaken, rgb(black / 0.5) is not possible, you would always need to do 0 0 0 or 255 255 255.

So it would be:

// normally
color: black;
color: rgb(0 0 0 / 0);
color: rgb(0 0 0 / 0.5);

// with this util
color: black();
color: black(0);
color: black(0.5);

@jesse-mm
Copy link
Collaborator

In sass you can do rgba(#000, 0.5) for me it has the same verbosity as for rgba(black, 0.5)

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

No branches or pull requests

5 participants