Skip to content

Commit 6500595

Browse files
authored
Merge pull request #976 from primer/cb/ts-label
Migrate Label to TypeScript
2 parents 33282e2 + 397a46f commit 6500595

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

.changeset/funny-kangaroos-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/components": patch
3+
---
4+
5+
Migrate `Label` to TypeScript

.changeset/lovely-walls-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/components": patch
3+
---
4+
5+
Migrate `LabelGroup` to TypeScript

src/Label.js renamed to src/Label.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import PropTypes from 'prop-types'
22
import styled, {css} from 'styled-components'
3-
import {variant, borderColor} from 'styled-system'
3+
import {borderColor, BorderColorProps, variant} from 'styled-system'
4+
import {COMMON, get, SystemCommonProps} from './constants'
5+
import sx, {SxProp} from './sx'
46
import theme from './theme'
5-
import {COMMON, get} from './constants'
6-
import sx from './sx'
77

88
const outlineStyles = css`
99
margin-top: -1px; // offsets the 1px border
@@ -42,18 +42,29 @@ const sizeVariant = variant({
4242
}
4343
})
4444

45-
const Label = styled('span')`
45+
const Label = styled.span<
46+
{
47+
variant?: 'small' | 'medium' | 'large' | 'xl'
48+
dropshadow?: boolean
49+
outline?: boolean
50+
} & BorderColorProps &
51+
SystemCommonProps &
52+
SxProp
53+
>`
4654
display: inline-block;
4755
font-weight: ${get('fontWeights.semibold')};
4856
color: ${get('colors.white')};
4957
border-radius: ${get('radii.3')};
58+
5059
&:hover {
5160
text-decoration: none;
5261
}
62+
5363
${sizeVariant}
54-
${COMMON} ${props => (props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '')};
55-
${props => (props.outline ? outlineStyles : '')}; // must be last to override other values
56-
${sx};
64+
${COMMON}
65+
${props => (props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '')}
66+
${props => (props.outline ? outlineStyles : '')} // must be last to override other values
67+
${sx}
5768
`
5869

5970
Label.defaultProps = {
@@ -71,4 +82,5 @@ Label.propTypes = {
7182
...sx.propTypes
7283
}
7384

85+
export type LabelProps = React.ComponentProps<typeof Label>
7486
export default Label
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react'
21
import styled from 'styled-components'
2+
import {COMMON, get, SystemCommonProps} from './constants'
3+
import sx, {SxProp} from './sx'
34
import theme from './theme'
4-
import {COMMON, get} from './constants'
5-
import sx from './sx'
65

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

18-
const LabelGroup = ({children, ...rest}) => <StyledLabelGroup {...rest}>{children}</StyledLabelGroup>
19-
2017
LabelGroup.defaultProps = {
2118
theme
2219
}
@@ -26,4 +23,5 @@ LabelGroup.propTypes = {
2623
...sx.propTypes
2724
}
2825

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

0 commit comments

Comments
 (0)