Skip to content

Commit 039a875

Browse files
authored
Merge pull request #32 from mrahhal/use-colors-config
Add use-colors theme config
2 parents f5e3145 + 5119d25 commit 039a875

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

samples/basic/src/scss/_variables.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
// Override the system defined themes
22
// Since we're not adding anything beyond the defaults that css-theming already gives us,
33
// we can just completely remove this.
4+
5+
// You can use this to only make css-theming add the colors you want.
6+
// $use-colors: ('purple', 'green', 'blue', 'orange', 'red');
7+
48
$ct-themes: (
59
'default': (
610
'brightness': 'light',
11+
// 'use-colors': $use-colors,
712
),
813
'default-dark': (
914
'brightness': 'dark',
15+
// 'use-colors': $use-colors,
1016
),
1117
);
1218

src/scss/_themes.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $themes: (
1515
'default':
1616
(
1717
// 'colors': overrides $colors-[light|dark]
18+
// 'use-colors': if given, specifies which colors from the default palette to include
1819
// 'colors-text-scale': overrides $colors-text-scale-[light|dark]
1920
// 'semantic-colors': overrides $semantic-colors
2021
// 'font': overrides $font
@@ -74,6 +75,18 @@ $themes-categories-applied-at: (
7475
@return map.merge($default-map, $map);
7576
}
7677

78+
@function strip-colors($colors, $use-colors) {
79+
@if ($use-colors==null) {
80+
@return $colors;
81+
}
82+
83+
$new-colors-map: ();
84+
@each $color in $use-colors {
85+
$new-colors-map: map.merge($new-colors-map, ($color: map.get($colors, $color)));
86+
}
87+
@return $new-colors-map;
88+
}
89+
7790
// Normalize theme data, fill in defaults, and add computed values.
7891
@function normalize-theme($category, $theme-name, $theme) {
7992
$theme: map.merge($theme, ('name': $theme-name, 'css-name': get-theme-css-name($category, $theme-name)));
@@ -83,6 +96,7 @@ $themes-categories-applied-at: (
8396
// colors
8497
$colors-default: if($brightness=='light', colors.$colors-light, colors.$colors-dark);
8598
$colors: combine-with-default-map(map.get($theme, 'colors'), $colors-default);
99+
$colors: strip-colors($colors, map.get($theme, 'use-colors'));
86100
$theme: map.merge($theme, ('colors': $colors));
87101

88102
// colors-text-scale

0 commit comments

Comments
 (0)