Skip to content

StyledOcticon no longer accepts styled system props #1616

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

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/mean-bananas-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

StyledOcticon no longer accepts styled-system props. Please use the `sx` prop to extend Primer component styling instead. See also https://primer.style/react/overriding-styles for information about `sx` and https://primer.style/react/system-props for context on the removal.
23 changes: 7 additions & 16 deletions docs/content/StyledOcticon.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@ StyledOcticon renders an [Octicon](https://octicons.github.com) with common syst
</>
```

## System props

<Note variant="warning">

System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.

</Note>

StyledOcticon components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

StyledOcticon passes all of its props except the common system props down to the [Octicon component](https://github.com/primer/octicons/tree/master/lib/octicons_react#usage), including:

| Name | Type | Default | Description |
| :------------ | :-------- | :-----------: | :----------------------------------------------------------------------------------------------------------- |
| ariaLabel | String | | Specifies the `aria-label` attribute, which is read verbatim by screen readers |
| icon | Component | | [Octicon component](https://github.com/primer/octicons/tree/master/lib/octicons_react) used in the component |
| size | Number | 16 | Sets the uniform `width` and `height` of the SVG element |
| verticalAlign | String | `text-bottom` | Sets the `vertical-align` CSS property |
| Name | Type | Default | Description |
| :------------ | :---------------- | :-----------: | :----------------------------------------------------------------------------------------------------------- |
| ariaLabel | String | | Specifies the `aria-label` attribute, which is read verbatim by screen readers |
| icon | Component | | [Octicon component](https://github.com/primer/octicons/tree/master/lib/octicons_react) used in the component |
| size | Number | 16 | Sets the uniform `width` and `height` of the SVG element |
| verticalAlign | String | `text-bottom` | Sets the `vertical-align` CSS property |
| sx | SystemStyleObject | {} | Style to be applied to the component |
2 changes: 1 addition & 1 deletion src/DropdownMenu/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const DropdownButton = React.forwardRef<HTMLElement, React.PropsWithChild
({children, ...props}: React.PropsWithChildren<DropdownButtonProps>, ref): JSX.Element => (
<Button ref={ref} type="button" {...props}>
{children}
<StyledOcticon icon={TriangleDownIcon} ml={1} />
<StyledOcticon icon={TriangleDownIcon} sx={{ml: 1}} />
</Button>
)
)
2 changes: 1 addition & 1 deletion src/StateLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function StateLabel({children, status, variant: variantProp, ...rest}: StateLabe
return (
<StateLabelBase {...rest} variant={variantProp} status={status}>
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
{status && <StyledOcticon mr={1} {...octiconProps} icon={octiconMap[status] || QuestionIcon} />}
{status && <StyledOcticon {...octiconProps} icon={octiconMap[status] || QuestionIcon} sx={{mr: 1}} />}
{children}
</StateLabelBase>
)
Expand Down
4 changes: 1 addition & 3 deletions src/StyledOcticon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {IconProps} from '@primer/octicons-react'
import React from 'react'
import styled from 'styled-components'
import {COMMON, SystemCommonProps} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

Expand All @@ -11,8 +10,7 @@ function Octicon({icon: IconComponent, ...rest}: OcticonProps) {
return <IconComponent {...rest} />
}

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

Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/StyledOcticon.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {MoonIcon} from '@primer/octicons-react'
import React from 'react'
import StyledOcticon from '../StyledOcticon'

export function shouldAcceptCallWithNoProps() {
return <StyledOcticon icon={MoonIcon} />
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
return <StyledOcticon backgroundColor="wheat" />
}