Skip to content

Commit 62f0925

Browse files
authored
Merge pull request #993 from primer/cb/ts-styled-octicon
Migrate StyledOcticon to TypeScript
2 parents 885e810 + f06e9a6 commit 62f0925

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

.changeset/funny-pots-explain.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 `StyledOcticon` to TypeScript

src/StyledOcticon.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/StyledOcticon.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import styled from 'styled-components'
4+
import {COMMON, SystemCommonProps} from './constants'
5+
import theme from './theme'
6+
import sx, {SxProp} from './sx'
7+
import {IconProps} from '@primer/octicons-react'
8+
import {ComponentProps} from './utils/types'
9+
10+
type OcticonProps = {icon: React.ElementType} & IconProps
11+
12+
function Octicon({icon: IconComponent, ...rest}: OcticonProps) {
13+
return <IconComponent {...rest} />
14+
}
15+
16+
const StyledOcticon = styled(Octicon)<SystemCommonProps & SxProp>`
17+
${COMMON}
18+
${sx}
19+
`
20+
21+
StyledOcticon.defaultProps = {
22+
theme,
23+
size: 16
24+
}
25+
26+
StyledOcticon.propTypes = {
27+
...COMMON.propTypes,
28+
...sx.propTypes,
29+
icon: PropTypes.any.isRequired,
30+
size: PropTypes.any,
31+
theme: PropTypes.object,
32+
verticalAlign: PropTypes.oneOf(['middle', 'text-bottom', 'text-top', 'top'])
33+
}
34+
35+
export type StyledOcticonProps = ComponentProps<typeof StyledOcticon>
36+
export default StyledOcticon

src/__tests__/StyledOcticon.js renamed to src/__tests__/StyledOcticon.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ describe('StyledOcticon', () => {
1515
default: StyledOcticon
1616
})
1717

18-
it('implements system props', () => {
19-
expect(StyledOcticon).toImplementSystemProps(COMMON)
20-
})
21-
2218
it('should have no axe violations', async () => {
2319
const {container} = HTMLRender(<StyledOcticon icon={XIcon} />)
2420
const results = await axe(container)

0 commit comments

Comments
 (0)