Skip to content

Commit

Permalink
Merge pull request #976 from primer/cb/ts-label
Browse files Browse the repository at this point in the history
Migrate Label to TypeScript
  • Loading branch information
colebemis authored Jan 21, 2021
2 parents 33282e2 + 397a46f commit 6500595
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-kangaroos-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `Label` to TypeScript
5 changes: 5 additions & 0 deletions .changeset/lovely-walls-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `LabelGroup` to TypeScript
26 changes: 19 additions & 7 deletions src/Label.js → src/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PropTypes from 'prop-types'
import styled, {css} from 'styled-components'
import {variant, borderColor} from 'styled-system'
import {borderColor, BorderColorProps, variant} from 'styled-system'
import {COMMON, get, SystemCommonProps} from './constants'
import sx, {SxProp} from './sx'
import theme from './theme'
import {COMMON, get} from './constants'
import sx from './sx'

const outlineStyles = css`
margin-top: -1px; // offsets the 1px border
Expand Down Expand Up @@ -42,18 +42,29 @@ const sizeVariant = variant({
}
})

const Label = styled('span')`
const Label = styled.span<
{
variant?: 'small' | 'medium' | 'large' | 'xl'
dropshadow?: boolean
outline?: boolean
} & BorderColorProps &
SystemCommonProps &
SxProp
>`
display: inline-block;
font-weight: ${get('fontWeights.semibold')};
color: ${get('colors.white')};
border-radius: ${get('radii.3')};
&:hover {
text-decoration: none;
}
${sizeVariant}
${COMMON} ${props => (props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '')};
${props => (props.outline ? outlineStyles : '')}; // must be last to override other values
${sx};
${COMMON}
${props => (props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '')}
${props => (props.outline ? outlineStyles : '')} // must be last to override other values
${sx}
`

Label.defaultProps = {
Expand All @@ -71,4 +82,5 @@ Label.propTypes = {
...sx.propTypes
}

export type LabelProps = React.ComponentProps<typeof Label>
export default Label
10 changes: 4 additions & 6 deletions src/LabelGroup.js → src/LabelGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react'
import styled from 'styled-components'
import {COMMON, get, SystemCommonProps} from './constants'
import sx, {SxProp} from './sx'
import theme from './theme'
import {COMMON, get} from './constants'
import sx from './sx'

const StyledLabelGroup = styled.span`
const LabelGroup = styled.span<SystemCommonProps & SxProp>`
${COMMON}
& * {
margin-right: ${get('space.1')};
Expand All @@ -15,8 +14,6 @@ const StyledLabelGroup = styled.span`
${sx};
`

const LabelGroup = ({children, ...rest}) => <StyledLabelGroup {...rest}>{children}</StyledLabelGroup>

LabelGroup.defaultProps = {
theme
}
Expand All @@ -26,4 +23,5 @@ LabelGroup.propTypes = {
...sx.propTypes
}

export type LabelGroupProps = React.ComponentProps<typeof LabelGroup>
export default LabelGroup
File renamed without changes.
File renamed without changes.
File renamed without changes.

1 comment on commit 6500595

@vercel
Copy link

@vercel vercel bot commented on 6500595 Jan 21, 2021

Choose a reason for hiding this comment

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

Please # to comment.