@@ -10,6 +10,7 @@ import ForkIcon from "./icons/forkIcon";
1010import StarIcon from "./icons/starIcon" ;
1111import WatchIcon from "./icons/watchIcon" ;
1212import UsedByIcon from './icons/usedByIcon' ;
13+ import SponsorIcon from './icons/sponsorIcon' ;
1314
1415function 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
5865export interface IPropTypes {
5966 owner : string ;
6067 repo : string ;
6168 variant : string ;
6269 count : number ;
70+ showCount : boolean ;
6371}
6472
6573export 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
8898GithubButton . 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} ;
0 commit comments