Skip to content

Commit

Permalink
refactor(chart-themes): replace repeating brushes styles with a CSS v…
Browse files Browse the repository at this point in the history
…ariable

This reduces the amount of generated CSS by quite a few lines.
  • Loading branch information
simeonoff committed Nov 20, 2024
1 parent 53dea5f commit 3c540e0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sass/themes/_functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

// Special case for chart brushes
@if $value == 'series' {
$result: map.merge($result, (#{$key}: #{color.chart-brushes()}));
$result: map.merge($result, (#{$key}: var(--chart-brushes)));
}
}

Expand Down
10 changes: 10 additions & 0 deletions sass/themes/charts/_theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../mixins' as *;
@use '../../color/functions' as color;
@use './category-chart-theme' as *;
@use './data-chart-theme' as *;
@use './doughnut-chart-theme' as *;
Expand All @@ -12,6 +13,15 @@
@use './sparkline-theme' as *;

@mixin chart-themes($schema, $target: 'angular') {
:root {
@include css-vars-from-theme(
(
chart-brushes: color.chart-brushes(),
),
'ig'
);
}

@include css-vars(category-chart-theme($schema: $schema, $target: $target));
@include css-vars(data-chart-theme($schema: $schema, $target: $target));
@include css-vars(doughnut-chart-theme($schema: $schema, $target: $target));
Expand Down
2 changes: 1 addition & 1 deletion test/_themes.spec.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ $schema: (
hover-foreground: color-mix(in oklch, var(--ig-secondary-700-contrast) 100%, transparent),
border-style: solid,
border-radius: .125rem,
brushes: #{chart-brushes()},
brushes: var(--chart-brushes),
resting-elevation: var(--ig-elevation-2),
_meta: (
version: 1
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
$handmade-palette: mocks.$handmade-palette;

@include palette($handmade-palette);

color: color($handmade-palette, 'primary', 300);
}

0 comments on commit 3c540e0

Please sign in to comment.