Skip to content

Commit

Permalink
refactor(css-variable-color): add define-color-based-on() function …
Browse files Browse the repository at this point in the history
…to define a new color based on another css variable by changing its lightness, use multiply in parameter $alpha in the `color()` function.
  • Loading branch information
sciborrudnicki committed May 22, 2022
1 parent 7156d13 commit 214c17e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/mixins/_css-variable-color.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
--s-#{$name}-a: #{alpha($color)};
}

// Defines a color based on the specified CSS variable and its lightness.
@mixin define-color-based-on($name, $color, $lightness: 0%) {
--s-#{$name}-h: var(--s-#{$color}-h);
--s-#{$name}-l: calc(var(--s-#{$color}-l) + #{$lightness});
--s-#{$name}-s: var(--s-#{$color}-s);
--s-#{$name}-a: var(--s-#{$color}-a);
}

// Color variable.
@function color($name, $hue: 0deg, $lightness: 0%, $saturation: 0%, $alpha: 0) {
@function color($name, $hue: 0deg, $lightness: 0%, $saturation: 0%, $alpha: 1) {
@return hsla(
calc(var(--s-#{$name}-h) + #{$hue}),
calc(var(--s-#{$name}-s) + #{$saturation}),
calc(var(--s-#{$name}-l) + #{$lightness}),
calc(var(--s-#{$name}-a) + #{$alpha})
calc(var(--s-#{$name}-a) * #{$alpha})
);
}

0 comments on commit 214c17e

Please sign in to comment.