Skip to content

Commit 698f8b0

Browse files
authored
Merge pull request #49 from primer/branch-name
Creating a BranchName component
2 parents 6568a35 + 583768d commit 698f8b0

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

examples/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ButtonPrimary,
1313
ButtonOutline,
1414
ButtonLink,
15+
BranchName,
1516
CounterLabel,
1617
Heading,
1718
Label,
@@ -67,6 +68,15 @@ const Index = props => (
6768
<Example name='Box'>
6869
<Box p={3} bg='gray.1'> Box </Box>
6970
</Example>
71+
<Example name='BranchName'>
72+
<BranchName>a_new_feature_branch</BranchName>
73+
<Detail>
74+
<Heading tag='h3' fontSize={3} mb={2} mt={3}>Linked BranchName</Heading>
75+
<BranchName tag='a' href='/'>a_new_feature_branch</BranchName>
76+
<Heading tag='h3' fontSize={3} mb={2} mt={3}>BranchName with Octicon</Heading>
77+
<BranchName><Octicon name='git-branch' /> a_new_feature_branch</BranchName>
78+
</Detail>
79+
</Example>
7080
<Example name='Button'>
7181
<Button> Button </Button>
7282
</Example>

src/BranchName.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
3+
const BranchName = ({ children, href, tag }) => {
4+
5+
const Tag = tag === 'a' ? 'a' : 'span'
6+
7+
// We don't want someone to use href on a non tag
8+
if (tag != 'a') {
9+
href = null
10+
}
11+
12+
return <Tag
13+
href={href}
14+
className='branch-name'>
15+
{ children }
16+
</Tag>
17+
}
18+
19+
export default BranchName

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export { default as ButtonLink } from './ButtonLink'
1717

1818
export { default as Heading } from './Heading'
1919
export { default as Label } from './Label'
20+
export { default as BranchName } from './BranchName'
2021
export { default as Link } from './Link'
2122
export { default as Text } from './Text'
2223
export { default as Tooltip } from './Tooltip'

0 commit comments

Comments
 (0)