Skip to content

Commit

Permalink
feat: added border_color option (anuraghazra#1000)
Browse files Browse the repository at this point in the history
* feat: Allow customization of border color

* docs: Update readme
  • Loading branch information
rishisuresh7 authored Apr 27, 2021
1 parent f9abae8 commit 7a096ac
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GitHub Readme Stats supports custom theming and you can also contribute new them

All you need to do is edit [themes/index.js](./themes/index.js) file and add your theme at the end of the file.

While creating the Pull request to add a new theme **don't forget to add a screenshot of how your theme looks**, you can also test how it looks using custom url parameters like `title_color`, `icon_color`, `bg_color`, `text_color`
While creating the Pull request to add a new theme **don't forget to add a screenshot of how your theme looks**, you can also test how it looks using custom url parameters like `title_color`, `icon_color`, `bg_color`, `text_color`, `border_color`

> NOTE: If you are contributing your theme just because you are using it personally, then you can [customize the looks](./readme.md#customization) of your card with URL params instead.
Expand Down
2 changes: 2 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = async (req, res) => {
locale,
disable_animations,
border_radius,
border_color,
} = req.query;
let stats;

Expand Down Expand Up @@ -76,6 +77,7 @@ module.exports = async (req, res) => {
theme,
custom_title,
border_radius,
border_color,
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
}),
Expand Down
2 changes: 2 additions & 0 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = async (req, res) => {
cache_seconds,
locale,
border_radius,
border_color,
} = req.query;

let repoData;
Expand Down Expand Up @@ -71,6 +72,7 @@ module.exports = async (req, res) => {
bg_color,
theme,
border_radius,
border_color,
show_owner: parseBoolean(show_owner),
locale: locale ? locale.toLowerCase() : null,
}),
Expand Down
4 changes: 3 additions & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = async (req, res) => {
exclude_repo,
custom_title,
locale,
border_radius
border_radius,
border_color,
} = req.query;
let topLangs;

Expand Down Expand Up @@ -71,6 +72,7 @@ module.exports = async (req, res) => {
theme,
layout,
border_radius,
border_color,
locale: locale ? locale.toLowerCase() : null,
}),
);
Expand Down
2 changes: 2 additions & 0 deletions api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async (req, res) => {
api_domain,
range,
border_radius,
border_color,
} = req.query;

res.setHeader("Content-Type", "image/svg+xml");
Expand Down Expand Up @@ -65,6 +66,7 @@ module.exports = async (req, res) => {
theme,
hide_progress,
border_radius,
border_color,
locale: locale ? locale.toLowerCase() : null,
layout,
langs_count,
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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)_
- `border_color` - Card's border color _(hex color)_. (Does not apply when `hide_border` is enabled)
- `bg_color` - Card's background color _(hex color)_ **or** a gradient in the form of _angle,start,end_
- `hide_border` - Hides the card's border _(boolean)_
- `theme` - name of the theme, choose from [all available themes](./themes/README.md)
Expand Down Expand Up @@ -331,6 +332,10 @@ Change the `?username=` value to your [Wakatime](https://wakatime.com) username.

![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=issues&show_icons=true)

- Customize Border Color

![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&border_color=2e4058)

- Include All Commits

![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&include_all_commits=true)
Expand Down
5 changes: 4 additions & 1 deletion src/cards/repo-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const renderRepoCard = (repo, options = {}) => {
show_owner,
theme = "default_repocard",
border_radius,
border_color,
locale,
} = options;

Expand Down Expand Up @@ -60,11 +61,12 @@ const renderRepoCard = (repo, options = {}) => {
});

// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, iconColor, bgColor } = getCardColors({
const { titleColor, textColor, iconColor, bgColor, borderColor } = getCardColors({
title_color,
icon_color,
text_color,
bg_color,
border_color,
theme,
});

Expand Down Expand Up @@ -125,6 +127,7 @@ const renderRepoCard = (repo, options = {}) => {
textColor,
iconColor,
bgColor,
borderColor,
},
});

Expand Down
5 changes: 4 additions & 1 deletion src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
theme = "default",
custom_title,
border_radius,
border_color,
locale,
disable_animations = false,
} = options;

const lheight = parseInt(line_height, 10);

// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, iconColor, bgColor } = getCardColors({
const { titleColor, textColor, iconColor, bgColor, borderColor } = getCardColors({
title_color,
icon_color,
text_color,
bg_color,
border_color,
theme,
});

Expand Down Expand Up @@ -207,6 +209,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
textColor,
iconColor,
bgColor,
borderColor,
},
});

Expand Down
7 changes: 5 additions & 2 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
layout,
custom_title,
locale,
border_radius
border_radius,
border_color,
} = options;

const i18n = new I18n({
Expand Down Expand Up @@ -104,10 +105,11 @@ const renderTopLanguages = (topLangs, options = {}) => {
}, 0);

// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, bgColor } = getCardColors({
const { titleColor, textColor, bgColor, borderColor } = getCardColors({
title_color,
text_color,
bg_color,
border_color,
theme,
});

Expand Down Expand Up @@ -189,6 +191,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
titleColor,
textColor,
bgColor,
borderColor,
},
});

Expand Down
13 changes: 11 additions & 2 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
locale,
layout,
langs_count = languages ? languages.length : 0,
border_radius
border_radius,
border_color,
} = options;

const i18n = new I18n({
Expand All @@ -113,11 +114,18 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
langsCount = clampValue(parseInt(langs_count), 1, langs_count);

// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, iconColor, bgColor } = getCardColors({
const {
titleColor,
textColor,
iconColor,
bgColor,
borderColor,
} = getCardColors({
title_color,
icon_color,
text_color,
bg_color,
border_color,
theme,
});

Expand Down Expand Up @@ -221,6 +229,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
textColor,
iconColor,
bgColor,
borderColor,
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/common/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Card {
y="0.5"
rx="${this.border_radius}"
height="99%"
stroke="#E4E2E2"
stroke="${this.colors.borderColor}"
width="${this.width - 1}"
fill="${
typeof this.colors.bgColor === "object"
Expand Down
9 changes: 8 additions & 1 deletion src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ function getCardColors({
icon_color,
bg_color,
theme,
border_color,
fallbackTheme = "default",
}) {
const defaultTheme = themes[fallbackTheme];
const selectedTheme = themes[theme] || defaultTheme;
const defaultBorderColor = selectedTheme.border_color || defaultTheme.border_color;

// get the color provided by the user else the theme color
// finally if both colors are invalid fallback to default theme
Expand All @@ -139,7 +141,12 @@ function getCardColors({
"#" + defaultTheme.bg_color,
);

return { titleColor, iconColor, textColor, bgColor };
const borderColor = fallbackColor(
border_color || defaultBorderColor,
"#" + defaultBorderColor,
);

return { titleColor, iconColor, textColor, bgColor, borderColor };
}

function wrapTextMultiline(text, width = 60, maxLines = 3) {
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/renderWakatimeCard.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports[`Test Render Wakatime Card should render correctly 1`] = `
y=\\"0.5\\"
rx=\\"4.5\\"
height=\\"99%\\"
stroke=\\"#E4E2E2\\"
stroke=\\"#e4e2e2\\"
width=\\"494\\"
fill=\\"#fffefe\\"
stroke-opacity=\\"1\\"
Expand Down Expand Up @@ -220,7 +220,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
y=\\"0.5\\"
rx=\\"4.5\\"
height=\\"99%\\"
stroke=\\"#E4E2E2\\"
stroke=\\"#e4e2e2\\"
width=\\"494\\"
fill=\\"#fffefe\\"
stroke-opacity=\\"1\\"
Expand Down
5 changes: 5 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ describe("Test utils.js", () => {
text_color: "0f0",
icon_color: "00f",
bg_color: "fff",
border_color: "fff",
theme: "dark",
});
expect(colors).toStrictEqual({
titleColor: "#f00",
textColor: "#0f0",
iconColor: "#00f",
bgColor: "#fff",
borderColor: "#fff",
});
});

Expand All @@ -87,13 +89,15 @@ describe("Test utils.js", () => {
text_color: "0f0",
icon_color: "00f",
bg_color: "fff",
border_color: "invalidColor",
theme: "dark",
});
expect(colors).toStrictEqual({
titleColor: "#2f80ed",
textColor: "#0f0",
iconColor: "#00f",
bgColor: "#fff",
borderColor: "#e4e2e2",
});
});

Expand All @@ -106,6 +110,7 @@ describe("Test utils.js", () => {
textColor: "#9f9f9f",
iconColor: "#79ff97",
bgColor: "#151515",
borderColor: "#e4e2e2",
});
});
});
Expand Down
1 change: 1 addition & 0 deletions themes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const themes = {
icon_color: "4c71f2",
text_color: "333",
bg_color: "fffefe",
border_color: "e4e2e2",
},
default_repocard: {
title_color: "2f80ed",
Expand Down

0 comments on commit 7a096ac

Please sign in to comment.