Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Label to TypeScript #976

Merged
merged 5 commits into from
Jan 21, 2021
Merged
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
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'
Copy link

Choose a reason for hiding this comment

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

I didn't know you could do this syntax! Nice! 🙌

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.