diff --git a/readme.md b/readme.md
index ccea98b..96617e5 100644
--- a/readme.md
+++ b/readme.md
@@ -125,7 +125,7 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
- `title_color` - Card's title color _(hex color)_
- `text_color` - Body text color _(hex color)_
- `icon_color` - Icons color if available _(hex color)_
-- `bg_color` - Card's background color _(hex color)_
+- `bg_color` - Card's background color _(hex color)_ **or** a gradient in the form of _angle,start,end_
- `theme` - name of the theme, choose from [all available themes](./themes/README.md)
- `cache_seconds` - set the cache header manually _(min: 1800, max: 86400)_
diff --git a/src/common/Card.js b/src/common/Card.js
index aa96ad0..d1ec723 100644
--- a/src/common/Card.js
+++ b/src/common/Card.js
@@ -109,6 +109,13 @@ class Card {
}
+ ${typeof this.colors.bgColor == 'object' ? `
+
+
+
+
+ ` : ""}
+
diff --git a/src/common/utils.js b/src/common/utils.js
index 968006f..0c8ccc6 100644
--- a/src/common/utils.js
+++ b/src/common/utils.js
@@ -61,7 +61,7 @@ function clampValue(number, min, max) {
}
function fallbackColor(color, fallbackColor) {
- return (isValidHexColor(color) && `#${color}`) || fallbackColor;
+ return (isValidHexColor(color) && `#${color}`) || (color.includes(',') && isValidHexColor(color.split(',')[1]) && isValidHexColor(color.split(',')[2]) && color.split(',')) || fallbackColor;
}
function request(data, headers) {
diff --git a/tests/card.test.js b/tests/card.test.js
index 15d1d7b..4e8b2df 100644
--- a/tests/card.test.js
+++ b/tests/card.test.js
@@ -133,4 +133,39 @@ describe("Card", () => {
"#fff"
);
});
+ it("should render gradient backgrounds", () => {
+ const { titleColor, textColor, iconColor, bgColor } = getCardColors({
+ title_color: "f00",
+ icon_color: "0f0",
+ text_color: "00f",
+ bg_color: "90,fff,000",
+ theme: "default",
+ });
+ const card = new Card({
+ height: 200,
+ colors: {
+ titleColor,
+ textColor,
+ iconColor,
+ bgColor,
+ },
+ });
+ document.body.innerHTML = card.render(``);
+ expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
+ "fill",
+ "url(#gradient)"
+ );
+ expect(document.querySelector('defs linearGradient')).toHaveAttribute(
+ "gradientTransform",
+ "rotate(90)"
+ );
+ expect(document.querySelector('defs linearGradient stop:nth-child(1)')).toHaveAttribute(
+ "stop-color",
+ "#fff"
+ );
+ expect(document.querySelector('defs linearGradient stop:nth-child(2)')).toHaveAttribute(
+ "stop-color",
+ "#000"
+ );
+ });
});