Skip to content

Commit

Permalink
refactor(color): remove duplicated output of CSS variables
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonoff committed Aug 30, 2024
1 parent 6d3145b commit 380c6a2
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 123 deletions.
3 changes: 1 addition & 2 deletions sass/color/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
$_shade: meta.type-of($shade) == 'string';
$_hsl: if($_shade, string.index($shade, 'hsl'), false);
$_contrast: if($_shade, string.index($shade, 'contrast'), false);
$_variant: if($_shade, string.index($shade, 'variant'), false);
$_color: '' + $color;

@if $_hsl {
Expand All @@ -49,7 +48,7 @@
--ig-#{$_color}-#{$variant}: #{$value};
}

@if not($_hsl) and not($_contrast) and not($_variant) {
@if not($_hsl) and not($_contrast) and not($variant) {
--ig-#{$_color}-#{$shade}: #{$value};
}

Expand Down
11 changes: 3 additions & 8 deletions test/_color.spec.scss
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ $_palette: palette(
--ig-primary-500:
#{hsl(var(--ig-primary-h), var(--ig-primary-s), var(--ig-primary-l))};
--ig-primary-500-contrast: #{contrast-color($_palette, primary, 500)};
--ig-primary-600:
--ig-primary-600:
#{hsl(from var(--ig-primary-500) h calc(s * 1.26) calc(l * 0.89))};
--ig-gray-500:
#{hsl(var(--ig-gray-h)
var(--ig-gray-s)
#{math.round(color.lightness($gray-500))})};
--ig-gray-500-contrast: #{contrast-color($_palette, gray, 500)};
--ig-gray-600:
--ig-gray-600:
#{hsl(from var(--ig-gray-500) h s 54%)};
}
}
Expand Down Expand Up @@ -294,9 +294,6 @@ $_palette: palette(
$value: map.get($_palette, $color, $shade);

@if $shade == 500 {
--ig-#{$color}-h: #{list.nth($value, 1)};
--ig-#{$color}-s: #{list.nth($value, 2)};
--ig-#{$color}-l: #{list.nth($value, 3)};
--ig-#{$color}-a: 1;
}

Expand All @@ -308,12 +305,10 @@ $_palette: palette(
}
}

@include it('should properly get the hex value from handmade palettes') {
@include it('should properly get the value from handmade palettes') {
$_palette: mocks.$handmade-palette;
$_hex: color($_palette, primary, 800);
$_ref: color(null, primary, 800);

@include assert-equal($_hex, #316ec9);
@include assert-equal($_ref, hsl(from var(--ig-primary-800) h s l / var(--ig-primary-a)));
}

Expand Down
Loading

0 comments on commit 380c6a2

Please sign in to comment.