Skip to content

Commit 62524f7

Browse files
author
Emily
authored
Merge pull request #62 from primer/task/status-icon
Merge Status Component
2 parents 8174e96 + c3f9bc3 commit 62524f7

File tree

8 files changed

+88
-46
lines changed

8 files changed

+88
-46
lines changed

docs/bundle.js

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 4 additions & 2 deletions
Large diffs are not rendered by default.

examples/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
TextInput,
2626
Label,
2727
Link,
28+
MergeStatus,
2829
StateLabel,
2930
Text,
3031
Tooltip,
@@ -212,10 +213,10 @@ const Index = props => (
212213
<Details render={() => 'hi'}/>
213214
</Block>
214215
</Example>
215-
<Example name="Dropdown">
216+
<Example name='Dropdown'>
216217
<Block my={4}>
217-
<Heading tag="h2">Dropdown Primary</Heading>
218-
<Dropdown scheme={"primary"}>
218+
<Heading tag='h2'>Dropdown Primary</Heading>
219+
<Dropdown scheme={'primary'}>
219220
<ul>
220221
<li>Item 1</li>
221222
<li>Item 2</li>
@@ -224,7 +225,7 @@ const Index = props => (
224225
</Dropdown>
225226
</Block>
226227
<Block my={4}>
227-
<Heading tag="h2">Dropdown</Heading>
228+
<Heading tag='h2'>Dropdown</Heading>
228229
<Dropdown>
229230
<ul>
230231
<li>Item 1</li>
@@ -234,8 +235,8 @@ const Index = props => (
234235
</Dropdown>
235236
</Block>
236237
<Block my={4}>
237-
<Heading tag="h2">Dropdown with title</Heading>
238-
<Dropdown title="Options">
238+
<Heading tag='h2'>Dropdown with title</Heading>
239+
<Dropdown title='Options'>
239240
<ul>
240241
<li>Item 1</li>
241242
<li>Item 2</li>
@@ -460,11 +461,16 @@ const Index = props => (
460461
</Block>
461462
</Detail>
462463
</Example>
464+
<Example name='MergeStatus'>
465+
<span className='mr-2'>
466+
<MergeStatus state='pending'/>
467+
</span>
468+
</Example>
463469
<Example name='Text'>
464470
<Text tag='div'>Text</Text>
465471
<Text tag='div' fontWeight='bold'>Text bold</Text>
466472
<Text tag='div' color='green'>Text green</Text>
467-
<Text tag='div' lineHeight='condensed'>Text lineHeight "condensed"</Text>
473+
<Text tag='div' lineHeight='condensed'>Text lineHeight 'condensed'</Text>
468474
<Text tag='div' fontSize={4}>Text fontSize 4</Text>
469475
<Text tag='div' p={4}>Text padding 4</Text>
470476
</Example>

src/Button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Button({
2727
);
2828

2929
return (
30-
<Tag {...props} type="button" disabled={disabled} onClick={disabled ? undefined : onClick} className={classes}>
30+
<Tag {...props} type='button' disabled={disabled} onClick={disabled ? undefined : onClick} className={classes}>
3131
{children}
3232
</Tag>
3333
)

src/MergeStatus.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, {Fragment} from 'react'
2+
import classnames from 'classnames'
3+
import Octicon from '@github/octicons-react'
4+
import StateLabel from './StateLabel'
5+
6+
const stateColorMap = {
7+
ready: 'green',
8+
invalid: 'invalid',
9+
merged: 'purple',
10+
pending: 'yellow'
11+
}
12+
13+
export default function MergeStatus({ state }) {
14+
return (
15+
<StateLabel scheme={stateColorMap[state]} small icon={<Octicon name='git-merge'/>} />
16+
)
17+
}

src/StateLabel.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, {Fragment} from 'react'
22
import classnames from 'classnames'
33
import Octicon from '@github/octicons-react'
4+
import theme from './theme'
5+
6+
const { colors } = theme
47

58
const stateColorMap = {
69
open: 'green',
@@ -26,6 +29,15 @@ function getOcticon(state) {
2629
return <Octicon name={name}/>
2730
}
2831

32+
const getIconComponent = (icon, children) => {
33+
if (icon && children) {
34+
return <span className='mr-1'>{icon}</span>
35+
} else if (icon) {
36+
return <span className='d-flex m-1'>{icon}</span>
37+
}
38+
return null
39+
}
40+
2941
export default function StateLabel(props) {
3042
const {
3143
state,
@@ -34,20 +46,25 @@ export default function StateLabel(props) {
3446
children,
3547
} = props
3648

37-
let {icon} = props
49+
let { icon } = props
3850
if (icon !== false) {
3951
icon = icon || getOcticon(state)
4052
}
4153

4254
const color = scheme || stateColorMap[state]
55+
const styleProps = {}
56+
if (color === 'yellow') {
57+
styleProps.style = {backgroundColor: colors.yellow[7]}
58+
}
59+
const iconComponent = getIconComponent(icon, children)
4360
return (
4461
<span className={classnames(
4562
'State', {
4663
'State--small': small
4764
},
48-
color ? `State--${color}` : null
49-
)}>
50-
{icon ? <span className='mr-1'>{icon}</span> : null}
65+
color && color !== 'yellow' ? `State--${color}` : null,
66+
)} {...styleProps}>
67+
{iconComponent}
5168
{children}
5269
</span>
5370
)

src/__tests__/__snapshots__/StateLabel.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`StateLabel renders states as specific colors 1`] = `
55
className="State State--green"
66
>
77
<span
8-
className="mr-1"
8+
className="d-flex m-1"
99
>
1010
<svg
1111
aria-hidden="true"
@@ -38,7 +38,7 @@ exports[`StateLabel renders states as specific colors 2`] = `
3838
className="State State--green"
3939
>
4040
<span
41-
className="mr-1"
41+
className="d-flex m-1"
4242
>
4343
<svg
4444
aria-hidden="true"
@@ -71,7 +71,7 @@ exports[`StateLabel renders states as specific colors 3`] = `
7171
className="State State--purple"
7272
>
7373
<span
74-
className="mr-1"
74+
className="d-flex m-1"
7575
>
7676
<svg
7777
aria-hidden="true"
@@ -104,7 +104,7 @@ exports[`StateLabel renders states as specific colors 4`] = `
104104
className="State State--red"
105105
>
106106
<span
107-
className="mr-1"
107+
className="d-flex m-1"
108108
>
109109
<svg
110110
aria-hidden="true"

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export { default as Heading } from './Heading'
2727
export { default as Label } from './Label'
2828
export { default as BranchName } from './BranchName'
2929
export { default as Link } from './Link'
30+
export { default as MergeStatus } from './MergeStatus'
3031
export { default as Text } from './Text'
3132
export { default as Tooltip } from './Tooltip'
3233

0 commit comments

Comments
 (0)