@@ -7,17 +7,38 @@ import * as React from "react";
77import classes from "../styles.css" ;
88
99import StarIcon from "./icons/starIcon" ;
10+ import ForkIcon from "./icons/forkIcon" ;
1011
11- function getDataForVariant ( variant : string , count : number ) : { title : string ; label : string ; Icon : ( ) => JSX . Element ; } {
12+ function getDataForVariant (
13+ variant : string ,
14+ count : number ,
15+ owner : string ,
16+ repo : string
17+ ) : {
18+ title : string ;
19+ btnTitle : string ;
20+ label : string ;
21+ countUrl : string ;
22+ Icon : ( ) => JSX . Element ;
23+ } {
1224 let title : string ;
25+ let btnTitle : string ;
1326 let label : string ;
27+ let countUrl : string ;
1428 if ( variant === "star" ) {
1529 title = "Star" ;
16- label = `${ count } user starred this repository` ;
17- return { title, label, Icon : StarIcon } ;
30+ btnTitle = `Star ${ owner } /${ repo } ` ;
31+ label = `${ count } users starred this repository` ;
32+ countUrl = `https://github.com/${ owner } /${ repo } /stargazers` ;
33+ return { title, btnTitle, label, countUrl, Icon : StarIcon } ;
34+ } else if ( variant === "fork" ) {
35+ title = "Fork" ;
36+ btnTitle = `Fork your own copy of ${ owner } /${ repo } to your account` ;
37+ label = `${ count } users forked this repository` ;
38+ countUrl = `https://github.com/vaibhavhrt/react-github-buttons/network/members` ;
39+ return { title, btnTitle, label, countUrl, Icon : ForkIcon } ;
1840 }
19- // throw new Error("Invalid Variant, supply one of [star, ]");
20- return { title : "" , label : "" , Icon : StarIcon } ;
41+ throw new Error ( "Invalid Variant, supply one of [star, fork]" ) ;
2142}
2243
2344export interface IPropTypes {
@@ -29,17 +50,17 @@ export interface IPropTypes {
2950
3051export default function GithubButton ( props : IPropTypes ) {
3152 const { owner, repo, variant, count } = props ;
32- const { title, label, Icon } = getDataForVariant ( variant , count ) ;
53+ const { title, btnTitle , label, countUrl , Icon } = getDataForVariant ( variant , count , owner , repo ) ;
3354
3455 return (
3556 < div className = { classes . root } >
36- < button title = { `Star ${ owner } / ${ repo } ` } className = { classes . button } >
57+ < button title = { btnTitle } className = { classes . button } >
3758 < Icon />
3859 { title }
3960 </ button >
4061 < a
4162 className = { classes . count }
42- href = { `https://github.com/ ${ owner } / ${ repo } /stargazers` }
63+ href = { countUrl }
4364 aria-label = { label }
4465 target = "_blank"
4566 rel = "noreferrer noopener"
0 commit comments