Skip to content

Commit 46a6790

Browse files
committed
add sponsor button
1 parent c17a1f8 commit 46a6790

11 files changed

+80
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to the "react-github-buttons" project will be documented in
44

55
## [Unreleased]
66

7+
## [0.4.0] 2019-6-15
8+
### Added
9+
10+
- Sponsor button
11+
712
## [0.3.0] 2019-6-15
813
### Added
914

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function App() {
3535

3636
## Release Notes
3737

38-
### 0.3.0
39-
#### Added
38+
## 0.4.0
39+
### Added
4040

41-
- Used by button
41+
- Sponsor button
4242

4343
## Issues
4444

example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-github-buttons-example",
33
"homepage": "https://vaibhavhrt.github.io/react-github-buttons",
4-
"version": "0.3.0",
4+
"version": "0.4.0",
55
"license": "MIT",
66
"private": true,
77
"dependencies": {

example/src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22

3-
import { Fork, Star, Watch, UsedBy } from 'react-github-buttons';
3+
import { Fork, Sponsor, Star, Watch, UsedBy } from 'react-github-buttons';
44

55
export default class App extends Component {
66
render () {
@@ -10,6 +10,7 @@ export default class App extends Component {
1010
<Fork owner='vaibhavhrt' repo='react-github-buttons' />
1111
<Watch owner='vaibhavhrt' repo='react-github-buttons' />
1212
<UsedBy owner='vaibhavhrt' repo='react-github-buttons' count={0} />
13+
<Sponsor owner='vaibhavhrt' repo='react-github-buttons' />
1314
</div>
1415
)
1516
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-github-buttons",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "React Components for dynamic buttons for github repo's star, fork etc.",
55
"keywords": ["react", "github", "component", "utility"],
66
"author": {

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import Star from "./star";
22
import Fork from "./fork";
33
import Watch from "./watch";
44
import UsedBy from './usedBy';
5+
import Sponsor from './sponsor';
56

6-
export { Fork, Star, UsedBy, Watch };
7+
export { Fork, Sponsor, Star, UsedBy, Watch };

src/lib/githubButton.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ForkIcon from "./icons/forkIcon";
1010
import StarIcon from "./icons/starIcon";
1111
import WatchIcon from "./icons/watchIcon";
1212
import UsedByIcon from './icons/usedByIcon';
13+
import SponsorIcon from './icons/sponsorIcon';
1314

1415
function getDataForVariant(
1516
variant: string,
@@ -51,43 +52,58 @@ function getDataForVariant(
5152
label = `${count} repositories depend on this package`;
5253
countUrl = `https://github.com/${owner}/${repo}/network/dependents`;
5354
return { title, btnTitle, label, countUrl, Icon: UsedByIcon };
55+
} else if (variant === "sponsor") {
56+
title = "Sponsor";
57+
btnTitle = `Sponsor ${owner}/${repo}`;
58+
label = "";
59+
countUrl = "";
60+
return { title, btnTitle, label, countUrl, Icon: SponsorIcon };
5461
}
55-
throw new Error("Invalid Variant, supply one of [star, fork, watch, usedby]");
62+
throw new Error("Invalid Variant, supply one of [star, fork, watch, usedby, sponsor]");
5663
}
5764

5865
export interface IPropTypes {
5966
owner: string;
6067
repo: string;
6168
variant: string;
6269
count: number;
70+
showCount: boolean;
6371
}
6472

6573
export default function GithubButton(props: IPropTypes) {
66-
const { owner, repo, variant, count } = props;
74+
const { owner, repo, variant, count, showCount } = props;
6775
const { title, btnTitle, label, countUrl, Icon } = getDataForVariant(variant, count, owner, repo);
6876

77+
const inlineStyle = showCount ? {} : { borderRadius: ".25em" };
78+
6979
return (
7080
<div className={classes.root}>
71-
<button title={btnTitle} className={classes.button}>
81+
<button title={btnTitle} className={classes.button} style={inlineStyle}>
7282
<Icon />
7383
{` ${title}`}
7484
</button>
75-
<a
85+
{showCount && <a
7686
className={classes.count}
7787
href={countUrl}
7888
aria-label={label}
7989
target="_blank"
8090
rel="noreferrer noopener"
8191
>
8292
{count}
83-
</a>
93+
</a>}
8494
</div>
8595
);
8696
}
8797

8898
GithubButton.propTypes = {
89-
count: PropTypes.node.isRequired,
99+
count: PropTypes.number,
90100
owner: PropTypes.string.isRequired,
91101
repo: PropTypes.string.isRequired,
92-
variant: PropTypes.oneOf(["star", "fork", "watch", "usedby"]),
102+
variant: PropTypes.oneOf(["star", "fork", "watch", "usedby", "sponsor"]),
103+
showCount: PropTypes.bool,
104+
};
105+
106+
GithubButton.defaultProps = {
107+
count: 0,
108+
showCount: true,
93109
};

src/lib/icons/sponsorIcon.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from "react";
2+
import classes from "../../styles.css";
3+
4+
export default function SponsorIcon() {
5+
return (
6+
<svg
7+
className={classes.svgicon}
8+
viewBox="0 0 12 16"
9+
version="1.1"
10+
width="12"
11+
height="16"
12+
style={{ fill: "#ea4aaa" }}
13+
>
14+
<path
15+
fillRule="evenodd"
16+
// tslint:disable-next-line:max-line-length
17+
d="M9 2c-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-1.632.086-2.954 1.333-3 3 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.047-1.69-1.342-2.913-3-3z" />
18+
</svg>
19+
);
20+
}

src/lib/icons/usedByIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function UsedByIcon() {
1111
height="16"
1212
>
1313
<path
14-
fill-rule="evenodd"
14+
fillRule="evenodd"
1515
// tslint:disable-next-line:max-line-length
1616
d="M1 4.27v7.47c0 .45.3.84.75.97l6.5 1.73c.16.05.34.05.5 0l6.5-1.73c.45-.13.75-.52.75-.97V4.27c0-.45-.3-.84-.75-.97l-6.5-1.74a1.4 1.4 0 0 0-.5 0L1.75 3.3c-.45.13-.75.52-.75.97zm7 9.09l-6-1.59V5l6 1.61v6.75zM2 4l2.5-.67L11 5.06l-2.5.67L2 4zm13 7.77l-6 1.59V6.61l2-.55V8.5l2-.53V5.53L15 5v6.77zm-2-7.24L6.5 2.8l2-.53L15 4l-2 .53z"
1717
/>

src/sponsor.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @function Sponsor
3+
*/
4+
import * as PropTypes from "prop-types";
5+
import * as React from "react";
6+
7+
import GithubButton from "./lib/githubButton";
8+
9+
export interface IPropTypes {
10+
owner: string;
11+
repo: string;
12+
}
13+
14+
export default function Sponsor(props: IPropTypes) {
15+
return <GithubButton variant="sponsor" showCount={false} { ...props } />;
16+
}
17+
18+
Sponsor.propTypes = {
19+
owner: PropTypes.string.isRequired,
20+
repo: PropTypes.string.isRequired,
21+
};

0 commit comments

Comments
 (0)