Skip to content

Commit bae0468

Browse files
committed
refactor status labels to look the same
1 parent 09bf3a5 commit bae0468

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

docs/src/PackageHeader.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import {Comment, Info, FileCode, Alert, PrimitiveDot} from '@githubprimer/octicons-react'
44
import {BorderBox, Box, Flex, Link, StyledOcticon as Octicon, Text} from '@primer/components'
5+
import StatusLabel from './StatusLabel'
56

67
export default function PackageHeader(props) {
78
const {description, internal = false, package: pkg, source = '', status, status_issue: issue, ...rest} = props
@@ -38,12 +39,7 @@ export default function PackageHeader(props) {
3839
return (
3940
<Flex justifyContent="space-between" mb={4} {...rest}>
4041
<Text is="div" fontSize={1}>
41-
{status ? (
42-
<BorderBox is="a" href="/css/whats-new/status-key" display="inline-block" px={2} py={1} mr={2}>
43-
<Octicon icon={PrimitiveDot} color={getStatusColor(status)} mr={2} />
44-
{status}
45-
</BorderBox>
46-
) : null}
42+
{status ? <StatusLabel status={status} is="a" href="/css/whats-new/status-key" mr={2} /> : null}
4743
{info}
4844
</Text>
4945
<Box>
@@ -69,14 +65,3 @@ PackageHeader.propTypes = {
6965
source: PropTypes.string,
7066
status: PropTypes.string
7167
}
72-
73-
function getStatusColor(status) {
74-
return (
75-
{
76-
stable: 'green.6',
77-
'new release': 'yellow.7',
78-
deprecated: 'red.7',
79-
experimental: 'orange.5'
80-
}[status.toLowerCase()] || 'gray.5'
81-
)
82-
}

docs/src/StatusLabel.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import styled from 'styled-components'
2+
import {BorderBox, StyledOcticon as Octicon, Text} from '@primer/components'
3+
import {PrimitiveDot} from '@githubprimer/octicons-react'
4+
5+
const StyledLabel = styled(BorderBox)`
6+
display: inline-block;
7+
white-space: nowrap;
8+
`
9+
10+
export const STATUS_COLORS = {
11+
stable: 'green.6',
12+
'new release': 'green.6',
13+
experimental: 'yellow.7',
14+
'in review': 'yellow.7',
15+
deprecated: 'red.6'
16+
}
17+
18+
export default function StatusLabel({status, children, ...rest}) {
19+
return (
20+
<StyledLabel px={2} py={1} {...rest}>
21+
<Octicon icon={PrimitiveDot} color={getStatusColor(status)} mr={2} />
22+
<Text color='black' fontSize={1}>{children || status}</Text>
23+
</StyledLabel>
24+
)
25+
}
26+
27+
export function getStatusColor(status) {
28+
return STATUS_COLORS[status.toLowerCase()] || 'gray.5'
29+
}

0 commit comments

Comments
 (0)