Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/StateLabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ StateLabel components get `COMMON` system props. Read our [System Props](/system

| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| small | Boolean | | Used to create a smaller version of the default StateLabel |
| variant | String | 'large' | a value of `small` or `large` results in a smaller or larger version of the StateLabel. |
| status | String | | Can be one of `issueOpened`, `issueClosed`, `pullOpened`, `pullClosed` or `pullMerged`.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ declare module '@primer/components' {
export interface SelectMenuModalProps extends CommonProps, Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {}

export interface SelectMenuListProps extends CommonProps, Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {}

export interface SelectMenuItemProps extends Omit<CommonProps, 'as'>,
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> {
selected?: boolean
Expand Down Expand Up @@ -368,7 +368,7 @@ declare module '@primer/components' {
}

export interface StateLabelProps extends CommonProps {
small?: boolean
variant?: 'small' | 'large'
status: 'issueOpened' | 'issueClosed' | 'pullOpened' | 'pullClosed' | 'pullMerged'
}

Expand Down
37 changes: 24 additions & 13 deletions src/StateLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {GitMerge, GitPullRequest, IssueClosed, IssueOpened} from '@primer/octicons-react'
import {variant} from 'styled-system'
import theme, {colors} from './theme'
import {COMMON, get} from './constants'
import StyledOcticon from './StyledOcticon'

const statusMap = {
issueClosed: colors.red[6],
pullClosed: colors.red[5],
pullMerged: colors.purple[5],
issueClosed: get('colors.red.6'),
pullClosed: get('colors.red.5'),
pullMerged: get('colors.purple.5'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note as I'm passing by! We should double check that this will respect a custom theme passed in via props. this might need to be:
issueClosed: get('colors.red.6')(props)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emplums You're correct; I have a few proposed changes in a branch but haven't gotten back to this yet

issueOpened: '#159739', // Custom green
pullOpened: '#2cbe4e', // This was generated by a sass function in Primer, so using a hex here
gray: colors.gray[5]
gray: get('colors.gray.5')
}

const octiconMap = {
Expand All @@ -23,8 +24,21 @@ const octiconMap = {
pullMerged: GitMerge
}

function StateLabelBase({className, status, small = false, children}) {
const octiconProps = small ? {width: '1em'} : {}
const sizeVariant = variant({
variants: {
small: {
padding: `4px 8px`,
fontSize: get('fontSizes.0')
},
large: {
padding: `8px 12px`,
fontSize: get('fontSizes.1')
}
}
})

function StateLabelBase({className, status, variant = 'large', children}) {
const octiconProps = variant === 'small' ? {width: '1em'} : {}
return (
<span className={className}>
{status && <StyledOcticon mr={1} {...octiconProps} icon={octiconMap[status]} />}
Expand All @@ -36,28 +50,25 @@ function StateLabelBase({className, status, small = false, children}) {
const StateLabel = styled(StateLabelBase)`
display: inline-flex;
align-items: center;
padding: ${props => (props.small ? `4px 8px` : `8px 12px`)};
font-weight: 600;
line-height: 16px;
color: ${colors.white};
font-size: ${props =>
props.small
? theme.fontSizes[0]
: theme.fontSizes[1]}; // TODO: these should use the get function instead of referencing the theme directly
text-align: center;
background-color: ${props => (props.status ? statusMap[props.status] : statusMap.gray)};
border-radius: ${get('radii.3')};
${sizeVariant}
${COMMON};
`

StateLabel.defaultProps = {
theme
theme,
variant: 'large'
}

StateLabel.propTypes = {
small: PropTypes.bool,
status: PropTypes.oneOf(['issueOpened', 'pullOpened', 'issueClosed', 'pullClosed', 'pullMerged']),
theme: PropTypes.object,
variant: PropTypes.oneOf(['small', 'large']),
...COMMON.propTypes
}

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/StateLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('StateLabel', () => {
expect(StateLabel).toSetDefaultTheme()
})

it('respects the small flag', () => {
expect(render(<StateLabel small />)).toMatchSnapshot()
expect(render(<StateLabel small={false} />)).toMatchSnapshot()
it('respects the variant prop', () => {
expect(render(<StateLabel variant="small" />)).toMatchSnapshot()
expect(render(<StateLabel variant="large" />)).toMatchSnapshot()
})

it('renders children', () => {
Expand Down
116 changes: 58 additions & 58 deletions src/__tests__/__snapshots__/StateLabel.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ exports[`StateLabel renders children 1`] = `
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 8px 12px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 14px;
text-align: center;
background-color: #6a737d;
border-radius: 100px;
padding: 8px 12px;
font-size: 14px;
}

<span
Expand All @@ -27,56 +27,6 @@ exports[`StateLabel renders children 1`] = `
</span>
`;

exports[`StateLabel respects the small flag 1`] = `
.c0 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 4px 8px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 12px;
text-align: center;
background-color: #6a737d;
border-radius: 100px;
}

<span
className="c0"
/>
`;

exports[`StateLabel respects the small flag 2`] = `
.c0 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 8px 12px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 14px;
text-align: center;
background-color: #6a737d;
border-radius: 100px;
}

<span
className="c0"
/>
`;

exports[`StateLabel respects the status prop 1`] = `
.c1 {
margin-right: 4px;
Expand All @@ -91,14 +41,14 @@ exports[`StateLabel respects the status prop 1`] = `
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 8px 12px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 14px;
text-align: center;
background-color: #159739;
border-radius: 100px;
padding: 8px 12px;
font-size: 14px;
}

<span
Expand Down Expand Up @@ -142,14 +92,14 @@ exports[`StateLabel respects the status prop 2`] = `
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 8px 12px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 14px;
text-align: center;
background-color: #cb2431;
border-radius: 100px;
padding: 8px 12px;
font-size: 14px;
}

<span
Expand Down Expand Up @@ -193,14 +143,14 @@ exports[`StateLabel respects the status prop 3`] = `
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 8px 12px;
font-weight: 600;
line-height: 16px;
color: #fff;
font-size: 14px;
text-align: center;
background-color: #6f42c1;
border-radius: 100px;
padding: 8px 12px;
font-size: 14px;
}

<span
Expand Down Expand Up @@ -229,3 +179,53 @@ exports[`StateLabel respects the status prop 3`] = `
</svg>
</span>
`;

exports[`StateLabel respects the variant prop 1`] = `
.c0 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-weight: 600;
line-height: 16px;
color: #fff;
text-align: center;
background-color: #6a737d;
border-radius: 100px;
padding: 4px 8px;
font-size: 12px;
}

<span
className="c0"
/>
`;

exports[`StateLabel respects the variant prop 2`] = `
.c0 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-weight: 600;
line-height: 16px;
color: #fff;
text-align: center;
background-color: #6a737d;
border-radius: 100px;
padding: 8px 12px;
font-size: 14px;
}

<span
className="c0"
/>
`;