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 StyledOcticon to TypeScript #993

Merged
merged 5 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
StyledOcticon.js → StyledOcticon.tsx
  • Loading branch information
colebemis committed Jan 27, 2021
commit 5b628ab46db0753bd4458088b0e267511419574a
15 changes: 10 additions & 5 deletions src/StyledOcticon.js → src/StyledOcticon.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {COMMON} from './constants'
import {COMMON, SystemCommonProps} from './constants'
import theme from './theme'
import sx from './sx'
import sx, {SxProp} from './sx'
import {IconProps} from '@primer/octicons-react'
import {ComponentProps} from './utils/types'

function IconWrapper({icon: IconComponent, className, ...rest}) {
return <IconComponent className={className} {...rest} />
type OcticonProps = {icon: React.ElementType} & IconProps

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

const StyledOcticon = styled(IconWrapper)`
const StyledOcticon = styled(Octicon)<SystemCommonProps & SxProp>`
${COMMON}
${sx}
`
Expand All @@ -28,4 +32,5 @@ StyledOcticon.propTypes = {
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)
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is run in the behavesAsComponent() test helper.


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