Skip to content

Commit

Permalink
fix(palette): don't scope palette variables to * (#68)
Browse files Browse the repository at this point in the history
* fix(palette): don't scope palette variables to *

* refactor(palettes): remove commented out mixins
  • Loading branch information
simeonoff authored Feb 13, 2023
1 parent 4f45619 commit 301c144
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 42 deletions.
70 changes: 31 additions & 39 deletions sass/color/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,35 @@
@use 'sass:string';
@use '../utils/meta' as *;

// Generates CSS variables for the base colors.
// Generates CSS variables for a base color
// @access private
@mixin _base-colors($palette) {
$scope: if(is-root(), ':root', '&');

#{$scope} {
@each $color, $shades in map.remove($palette, '_meta') {
@each $shade, $value in $shades {
$_shade: $shade == 500;
$_valid: meta.type-of($value == 'color');

@if $_shade and $_valid {
--ig-#{$color}-h: #{math.round(color.hue($value))};
--ig-#{$color}-s: #{math.round(color.saturation($value))};
--ig-#{$color}-l: #{math.round(color.lightness($value))};
--ig-#{$color}-a: #{color.alpha($value)};
}
}
}
@mixin _base($color, $shade, $value) {
$_shade: $shade == 500;
$_valid: meta.type-of($value == 'color');

@if $_shade and $_valid {
--ig-#{$color}-h: #{math.round(color.hue($value))};
--ig-#{$color}-s: #{math.round(color.saturation($value))};
--ig-#{$color}-l: #{math.round(color.lightness($value))};
--ig-#{$color}-a: #{color.alpha($value)};
}
}

// Generates shade CSS variables from the base colors.
// Generates CSS variables for a shade color
// @access private
@mixin _shade-colors($palette, $contrast: true) {
$scope: if(is-root(), '*', '&');

#{$scope} {
@each $color, $shades in map.remove($palette, '_meta') {
@each $shade, $value in $shades {
$_shade: meta.type-of($shade) == 'string';
$_hsl: if($_shade, string.index($shade, 'hsl'), false);
$_contrast: if($_shade, string.index($shade, 'contrast'), false);
@mixin _shade($color, $shade, $value, $contrast) {
$_shade: meta.type-of($shade) == 'string';
$_hsl: if($_shade, string.index($shade, 'hsl'), false);
$_contrast: if($_shade, string.index($shade, 'contrast'), false);

@if $_hsl {
$variant: string.slice($shade, 1, string.index($shade, '-hsl') - 1);
@if $_hsl {
$variant: string.slice($shade, 1, string.index($shade, '-hsl') - 1);

--ig-#{$color}-#{$variant}: #{$value};
}
--ig-#{$color}-#{$variant}: #{$value};
}

@if $_contrast and $contrast {
--ig-#{$color}-#{$shade}: #{$value};
}
}
}
@if $_contrast and $contrast {
--ig-#{$color}-#{$shade}: #{$value};
}
}

Expand All @@ -63,6 +47,14 @@
/// @include palette($palette);
/// @require {function} is-root
@mixin palette($palette, $contrast: true) {
@include _base-colors($palette);
@include _shade-colors($palette, $contrast);
$scope: if(is-root(), ':root', '&');

#{$scope} {
@each $color, $shades in map.remove($palette, '_meta') {
@each $shade, $value in $shades {
@include _base($color, $shade, $value);
@include _shade($color, $shade, $value, $contrast);
}
}
}
}
3 changes: 0 additions & 3 deletions test/_color.spec.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ $_palette: palette(
--ig-gray-s: #{math.round(color.saturation($gray-500))};
--ig-gray-l: #{math.round(color.lightness($gray-500))};
--ig-gray-a: #{math.round(color.alpha($gray-500))};
}

* {
--ig-primary-500:
#{var(--ig-primary-h),
calc(var(--ig-primary-s) * 1),
Expand Down

0 comments on commit 301c144

Please sign in to comment.