Skip to content

Commit

Permalink
Merge pull request #993 from primer/cb/ts-styled-octicon
Browse files Browse the repository at this point in the history
Migrate StyledOcticon to TypeScript
  • Loading branch information
colebemis authored Feb 2, 2021
2 parents 885e810 + f06e9a6 commit 62f0925
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-pots-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `StyledOcticon` to TypeScript
31 changes: 0 additions & 31 deletions src/StyledOcticon.js

This file was deleted.

36 changes: 36 additions & 0 deletions src/StyledOcticon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {COMMON, SystemCommonProps} from './constants'
import theme from './theme'
import sx, {SxProp} from './sx'
import {IconProps} from '@primer/octicons-react'
import {ComponentProps} from './utils/types'

type OcticonProps = {icon: React.ElementType} & IconProps

function Octicon({icon: IconComponent, ...rest}: OcticonProps) {
return <IconComponent {...rest} />
}

const StyledOcticon = styled(Octicon)<SystemCommonProps & SxProp>`
${COMMON}
${sx}
`

StyledOcticon.defaultProps = {
theme,
size: 16
}

StyledOcticon.propTypes = {
...COMMON.propTypes,
...sx.propTypes,
icon: PropTypes.any.isRequired,
size: PropTypes.any,
theme: PropTypes.object,
verticalAlign: PropTypes.oneOf(['middle', 'text-bottom', 'text-top', 'top'])
}

export type StyledOcticonProps = ComponentProps<typeof StyledOcticon>
export default StyledOcticon
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ describe('StyledOcticon', () => {
default: StyledOcticon
})

it('implements system props', () => {
expect(StyledOcticon).toImplementSystemProps(COMMON)
})

it('should have no axe violations', async () => {
const {container} = HTMLRender(<StyledOcticon icon={XIcon} />)
const results = await axe(container)
Expand Down

1 comment on commit 62f0925

@vercel
Copy link

@vercel vercel bot commented on 62f0925 Feb 2, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.