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 3 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-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,
Comment on lines +29 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These propTypes were causing errors. Since we'll be removing propTypes soon, I think any is fine for now.

Copy link
Member

Choose a reason for hiding this comment

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

I’d personally go ahead and remove PropTypes from this file, but this is fine too!

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)
})
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