Skip to content

Commit 0c255f8

Browse files
committed
feat(Theme): add support for gradient settings in theme JSON and SCSS
1 parent 61ea8fe commit 0c255f8

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎config/webpack-theme-json-plugin.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ class WebpackThemeJsonPlugin {
9696

9797
return result + `$settings-palette: (\n\t${palette.join(',\n\t')}\n);\n`
9898
},
99+
'settings-color-gradients'(key, value) {
100+
let result = ''
101+
const gradients = []
102+
103+
for (const gradient of value) {
104+
const gradientVar = getVariableName('settings-gradient-' + gradient.slug)
105+
result += `${gradientVar}: ${gradient.gradient};\n`
106+
gradients.push(`${gradient.slug}: ${gradientVar}`)
107+
}
108+
109+
return result + `$settings-gradients: (\n\t${gradients.join(',\n\t')}\n);\n`
110+
},
99111
'settings-custom': 'default',
100112
'settings-spacing-spacingSizes'(key, value) {
101113
let result = ''

‎src/scss/04-utilities/_palette.scss‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/*
44
* Palette : Usefully to get the color or background color of a parent element
55
* 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.
6+
* Use these classes to store a color / gradient value in a CSS variable.
7+
* This allows any child element to reuse the parent's background color or image.
88
*
99
* HTML:
1010
* <div class="has-primary-background-color">
@@ -17,6 +17,8 @@
1717
* .child-element {
1818
* color: var(--background-color);
1919
* }
20+
*
21+
* Gradients expose --gradient on .has-{slug}-gradient-background.
2022
*/
2123

2224
@each $color-name, $color-value in $settings-palette {
@@ -28,3 +30,9 @@
2830
--background-color: #{$color-value};
2931
}
3032
}
33+
34+
@each $gradient-name, $gradient-value in $settings-gradients {
35+
.has-#{$gradient-name}-gradient-background {
36+
--gradient: #{$gradient-value};
37+
}
38+
}

0 commit comments

Comments
 (0)