Skip to content

Commit

Permalink
Avatar, BranchName, Details, Heading, and ProgressBar no longer accep…
Browse files Browse the repository at this point in the history
…t styled-system props. (#1643)
  • Loading branch information
jfuchs authored Nov 30, 2021
1 parent cc6ecc8 commit 3938550
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-clocks-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

Details 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.
5 changes: 5 additions & 0 deletions .changeset/rude-squids-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

Avatar 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.
5 changes: 5 additions & 0 deletions .changeset/ten-doors-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

BranchName 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.
5 changes: 5 additions & 0 deletions .changeset/three-moose-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

Heading 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.
11 changes: 6 additions & 5 deletions docs/content/BranchName.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ BranchName is a label-type component rendered as an `<a>` tag by default with mo

## Props

| Name | Type | Default | Description |
| :--- | :----- | :-----: | :---------------------------------- |
| as | String | `<a>` | sets the HTML tag for the component |
| href | String | | a URL to link the component to |
| Name | Type | Default | Description |
| :--- | :---------------- | :-----: | :----------------------------------- |
| as | String | `<a>` | sets the HTML tag for the component |
| href | String | | a URL to link the component to |
| sx | SystemStyleObject | {} | Style to be applied to the component |

## Component status

<ComponentChecklist
items={{
items={{
propsDocumented: true,
noUnnecessaryDeps: true,
adaptsToThemes: true,
Expand Down
12 changes: 4 additions & 8 deletions docs/content/Details.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,11 @@ In previous versions of Primer React Components, we allowed users to pass in a c
</State>
```
## `Details` System props
## Details props
<Note variant="warning">
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
</Note>
Details components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
| Name | Type | Default | Description |
| :--- | :---------------- | :-----: | :----------------------------------- |
| sx | SystemStyleObject | {} | Style to be applied to the component |
## `useDetails` hook configuration options
Expand Down
15 changes: 5 additions & 10 deletions docs/content/Heading.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ The Heading component will render an html `h2` tag without any default styling.
## Default example

```jsx live
<Heading fontSize={1} mb={2}>
H2 heading with fontSize={1}
</Heading>
<Heading sx={{fontSize: 1, mb: 2}}>H2 heading with fontSize={1}</Heading>
```

## System props

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

## Component props

| Prop name | Type | Description |
| :-------- | :---------------------- | :---------------------------------- |
| as | String or React element | sets the HTML tag for the component |
| Name | Type | Default | Description |
| :--- | :---------------------- | :-----: | :----------------------------------- |
| as | String or React element | | sets the HTML tag for the component |
| sx | SystemStyleObject | {} | Style to be applied to the component |
13 changes: 6 additions & 7 deletions docs/content/Label.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ The Label component is used to add contextual metadata to a design. Visually it

## Component props

| Name | Type | Default | Description |
| :--------- | :---------------- | :--------------------: | :----------------------------------------------------------------------------- |
| outline | Boolean | | Creates an outline style label |
| variant | String | 'medium' | Can be one of `small`, `medium` (default), `large` or `xl` . |
| dropshadow | Boolean | | Adds a dropshadow to the label |
| bg | String | 'label.primary.border' | Part of the `COMMON` system props, used to change the background of the label. |
| sx | SystemStyleObject | {} | Style to be applied to the component |
| Name | Type | Default | Description |
| :--------- | :---------------- | :------: | :----------------------------------------------------------- |
| outline | Boolean | | Creates an outline style label |
| variant | String | 'medium' | Can be one of `small`, `medium` (default), `large` or `xl` . |
| dropshadow | Boolean | | Adds a dropshadow to the label |
| sx | SystemStyleObject | {} | Style to be applied to the component |
13 changes: 7 additions & 6 deletions docs/content/ProgressBar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ If you'd like to use ProgressBar inline, pass the `inline` boolean prop & **be s

## Component props

| Name | Type | Default | Description |
| :------- | :------ | :-----------------: | :------------------------------------------------------------------------------------------------------------------------------- |
| progress | Number | | Used to set the size of the green bar |
| barSize | String | 'default' | Controls the height of the progress bar. Can be 'small', 'large', or 'default'. If omitted, height is set to the default height. |
| inline | Boolean | false | Styles the progress bar inline |
| bg | String | 'bg.successInverse' | Set the progress bar color, defaults to bg-green |
| Name | Type | Default | Description |
| :------- | :---------------- | :-----------------: | :------------------------------------------------------------------------------------------------------------------------------- |
| progress | Number | | Used to set the size of the green bar |
| barSize | String | 'default' | Controls the height of the progress bar. Can be 'small', 'large', or 'default'. If omitted, height is set to the default height. |
| inline | Boolean | false | Styles the progress bar inline |
| bg | String | 'bg.successInverse' | Set the progress bar color, defaults to bg-green |
| sx | SystemStyleObject | {} | Style to be applied to the component |
6 changes: 0 additions & 6 deletions docs/content/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ The Text component is a wrapper component that will apply typography styles to t

## System props

<Note variant="warning">

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

</Note>

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

## Component props
Expand Down
2 changes: 1 addition & 1 deletion docs/content/system-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {PropsList, COMMON, LAYOUT, BORDER, TYPOGRAPHY, FLEX, POSITION, GRID} fro

<Note variant="warning">

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

</Note>

Expand Down
6 changes: 2 additions & 4 deletions src/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components'
import {COMMON, get, SystemCommonProps} from './constants'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

Expand All @@ -12,8 +12,7 @@ type StyledAvatarProps = {
src: string
/** Provide alt text when the Avatar is used without the user's name next to it. */
alt?: string
} & SystemCommonProps &
SxProp
} & SxProp

function getBorderRadius({size, square}: StyledAvatarProps) {
if (square) {
Expand All @@ -32,7 +31,6 @@ const Avatar = styled.img.attrs<StyledAvatarProps>(props => ({
line-height: ${get('lineHeights.condensedUltra')};
vertical-align: middle;
border-radius: ${props => getBorderRadius(props)};
${COMMON};
${sx}
`

Expand Down
6 changes: 3 additions & 3 deletions src/BranchName.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import styled from 'styled-components'
import {COMMON, get, SystemCommonProps} from './constants'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

const BranchName = styled.a<SystemCommonProps & SxProp>`
const BranchName = styled.a<SxProp>`
display: inline-block;
padding: 2px 6px;
font-size: ${get('fontSizes.0')};
font-family: ${get('fonts.mono')};
color: ${get('colors.fg.muted')};
background-color: ${get('colors.accent.subtle')};
border-radius: ${get('radii.2')};
${COMMON};
${sx};
`

Expand Down
6 changes: 1 addition & 5 deletions src/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import styled from 'styled-components'
import {COMMON, SystemCommonProps} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

type StyledDetailsProps = SystemCommonProps & SxProp

const Details = styled.details<StyledDetailsProps>`
const Details = styled.details<SxProp>`
& > summary {
list-style: none;
}
& > summary::-webkit-details-marker {
display: none;
}
${COMMON}
${sx};
`

Expand Down
11 changes: 2 additions & 9 deletions src/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import styled from 'styled-components'
import {COMMON, get, SystemCommonProps, SystemTypographyProps, TYPOGRAPHY} from './constants'
import {get} from './constants'
import sx, {SxProp} from './sx'
import theme from './theme'
import {ComponentProps} from './utils/types'

const Heading = styled.h2<SystemTypographyProps & SystemCommonProps & SxProp>`
const Heading = styled.h2<SxProp>`
font-weight: ${get('fontWeights.bold')};
font-size: ${get('fontSizes.5')};
margin: 0;
${TYPOGRAPHY};
${COMMON};
${sx};
`

Heading.defaultProps = {
theme
}

export type HeadingProps = ComponentProps<typeof Heading>
export default Heading
21 changes: 11 additions & 10 deletions src/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react'
import styled from 'styled-components'
import {width, WidthProps} from 'styled-system'
import {COMMON, get, SystemCommonProps} from './constants'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

const Bar = styled.span<{progress?: string | number} & SystemCommonProps>`
type ProgressProp = {progress?: string | number}

const Bar = styled.span<ProgressProp & SxProp>`
width: ${props => (props.progress ? `${props.progress}%` : 0)};
${COMMON}
${sx};
`

const sizeMap = {
Expand All @@ -20,7 +22,6 @@ type StyledProgressContainerProps = {
inline?: boolean
barSize?: keyof typeof sizeMap
} & WidthProps &
SystemCommonProps &
SxProp

const ProgressContainer = styled.span<StyledProgressContainerProps>`
Expand All @@ -29,17 +30,17 @@ const ProgressContainer = styled.span<StyledProgressContainerProps>`
background-color: ${get('colors.border.default')};
border-radius: ${get('radii.1')};
height: ${props => sizeMap[props.barSize || 'default']};
${COMMON}
${width}
${sx};
`

export type ProgressBarProps = ComponentProps<typeof ProgressContainer> & ComponentProps<typeof Bar>
export type ProgressBarProps = {bg: string} & StyledProgressContainerProps & ProgressProp

function ProgressBar({progress, bg, theme, ...rest}: ProgressBarProps) {
function ProgressBar({progress, bg, ...rest}: ProgressBarProps) {
return (
<ProgressContainer theme={theme} {...rest}>
<Bar progress={progress} bg={bg} theme={theme} />
<ProgressContainer {...rest}>
<Bar progress={progress} sx={{bg}} />
</ProgressContainer>
)
}
Expand Down
4 changes: 1 addition & 3 deletions src/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 Down Expand Up @@ -40,7 +39,7 @@ function Spinner({size: sizeKey = 'medium', ...props}: SpinnerInternalProps) {
)
}

const StyledSpinner = styled(Spinner)<SystemCommonProps & SxProp>`
const StyledSpinner = styled(Spinner)<SxProp>`
@keyframes rotate-keyframes {
100% {
transform: rotate(360deg);
Expand All @@ -49,7 +48,6 @@ const StyledSpinner = styled(Spinner)<SystemCommonProps & SxProp>`
animation: rotate-keyframes 1s linear infinite;
${COMMON}
${sx}
`

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ describe('Avatar', () => {
})

it('respects margin props', () => {
expect(render(<Avatar m={2} src="primer.png" alt="" />)).toHaveStyleRule('margin', px(theme.space[2]))
expect(render(<Avatar src="primer.png" alt="" sx={{m: 2}} />)).toHaveStyleRule('margin', px(theme.space[2]))
})
})
11 changes: 11 additions & 0 deletions src/__tests__/Avatar.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import Avatar from '../Avatar'

export function shouldAcceptCallWithNoProps() {
return <Avatar src="https://avatars.githubusercontent.com/primer" />
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
return <Avatar src="https://avatars.githubusercontent.com/primer" backgroundColor="thistle" />
}
11 changes: 11 additions & 0 deletions src/__tests__/BranchName.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import BranchName from '../BranchName'

export function shouldAcceptCallWithNoProps() {
return <BranchName />
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
return <BranchName backgroundColor="thistle" />
}
11 changes: 11 additions & 0 deletions src/__tests__/Details.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import Details from '../Details'

export function shouldAcceptCallWithNoProps() {
return <Details />
}

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

0 comments on commit 3938550

Please sign in to comment.