Skip to content

Commit 9629092

Browse files
committed
feat (theme): add colors as array in theme-json.scss : https://github.com/BeAPI/beapi-blocks-theme/pull/173/files
1 parent f335813 commit 9629092

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

config/webpack-theme-json-plugin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ class WebpackThemeJsonPlugin {
8686
const tasks = {
8787
'settings-color-palette'(key, value) {
8888
let result = ''
89+
const palette = []
8990

9091
for (const color of value) {
91-
result += `${getVariableName('settings-color-' + color.slug)}: ${color.color};\n`
92+
const colorVar = getVariableName('settings-color-' + color.slug)
93+
result += `${colorVar}: ${color.color};\n`
94+
palette.push(`${color.slug}: ${colorVar}`)
9295
}
9396

94-
return result
97+
return result + `$settings-palette: (${palette.join(', ')});\n`
9598
},
9699
'settings-custom': 'default',
97100
'settings-spacing-spacingSizes'(key, value) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@use "../01-abstract/theme-json.scss" as *;
2+
3+
/*
4+
* Palette : Usefully to get the color or background color of a parent element
5+
* Usage Example:
6+
* Use these classes to store a color value in a CSS variable.
7+
* This allows any child element to reuse the parent's background color.
8+
*
9+
* HTML:
10+
* <div class="has-primary-background-color">
11+
* <span class="child-element">
12+
* I will use the parent's background as my text color
13+
* </span>
14+
* </div>
15+
*
16+
* CSS:
17+
* .child-element {
18+
* color: var(--background-color);
19+
* }
20+
*/
21+
22+
@each $color-name, $color-value in $settings-palette {
23+
.has-#{$color-name}-color {
24+
--color: #{$color-value};
25+
}
26+
27+
.has-#{$color-name}-background-color {
28+
--background-color: #{$color-value};
29+
}
30+
}

src/scss/editor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ variables.$entry-file-name: "editor";
3434
@use "04-utilities/sr-only";
3535
@use "04-utilities/js-animation";
3636
@use "04-utilities/aria";
37+
@use "04-utilities/palette";
3738

3839
/**
3940
* Blocks

src/scss/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ variables.$entry-file-name: "style";
3838
@use "04-utilities/sr-only";
3939
@use "04-utilities/js-animation";
4040
@use "04-utilities/aria";
41+
@use "04-utilities/palette";
4142

4243
/**
4344
* Components

0 commit comments

Comments
 (0)