Skip to content
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/purple-buttons-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

Buttons no longer accept 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.
24 changes: 7 additions & 17 deletions docs/content/Buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ To create a button group, wrap `Button` elements in the `ButtonGroup` element. `
<ButtonOutline>Button Outline</ButtonOutline>
<ButtonPrimary>Button Primary</ButtonPrimary>
<ButtonInvisible>Button Invisible</ButtonInvisible>
<ButtonClose onClick={() => window.alert('button clicked')}/>
<ButtonClose onClick={() => window.alert('button clicked')} />

<ButtonGroup display='block' my={2}>
<ButtonGroup display="block" my={2}>
<Button>Button</Button>
<Button>Button</Button>
<Button>Button</Button>
Expand All @@ -29,27 +29,17 @@ To create a button group, wrap `Button` elements in the `ButtonGroup` element. `
</>
```

## System props

<Note variant="warning">

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

</Note>

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

## Component props

Native `<button>` HTML attributes are forwarded to the underlying React `button` component and are not listed below.

### Button

| Prop name | Type | Default | Description |
| :-------- | :--------------- | :------: | :-------------------------------------------------------------------------------------------------------------------------- |
| as | String | `button` | sets the HTML tag for the component |
| fontSize | Number or String | | explicitly sets the font size for the Button text; overrides any value for the `variant` prop |
| variant | String | 'medium' | a value of `small`, `medium`, or `large` results in smaller or larger Button text size; no effect if `fontSize` prop is set |
| Prop name | Type | Default | Description |
| :-------- | :---------------- | :------: | :-------------------------------------------------------------------------------------------------------------------------- |
| as | String | `button` | sets the HTML tag for the component |
| sx | SystemStyleObject | {} | Additional styles |
| variant | String | 'medium' | a value of `small`, `medium`, or `large` results in smaller or larger Button text size; no effect if `fontSize` prop is set |

### ButtonGroup

Expand Down
5 changes: 2 additions & 3 deletions src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps, ButtonSystemProps, buttonSystemProps} from './ButtonBase'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'

const Button = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
const Button = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.btn.text')};
background-color: ${get('colors.btn.bg')};
border: 1px solid ${get('colors.btn.border')};
Expand Down Expand Up @@ -32,7 +32,6 @@ const Button = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
border-color: ${get('colors.btn.border')};
}

${buttonSystemProps};
${sx};
`

Expand Down
8 changes: 2 additions & 6 deletions src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import styled from 'styled-components'
import {compose, fontSize, FontSizeProps, variant} from 'styled-system'
import {COMMON, LAYOUT, SystemCommonProps, SystemLayoutProps} from '../constants'
import {variant} from 'styled-system'
import {ComponentProps} from '../utils/types'
import buttonBaseStyles from './ButtonStyles'

export const buttonSystemProps = compose(fontSize, COMMON, LAYOUT)
export type ButtonSystemProps = FontSizeProps & SystemCommonProps & SystemLayoutProps

const variants = variant({
variants: {
small: {
Expand All @@ -26,7 +22,7 @@ const variants = variant({
type StyledButtonBaseProps = {
as?: 'button' | 'a' | 'summary' | 'input' | string | React.ReactType
variant?: 'small' | 'medium' | 'large'
} & FontSizeProps
}

const ButtonBase = styled.button.attrs<StyledButtonBaseProps>(({disabled, onClick}) => ({
onClick: disabled ? undefined : onClick
Expand Down
8 changes: 2 additions & 6 deletions src/Button/ButtonClose.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {XIcon} from '@primer/octicons-react'
import React, {forwardRef} from 'react'
import styled from 'styled-components'
import {COMMON, get, LAYOUT, SystemCommonProps, SystemLayoutProps} from '../constants'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'

type StyledButtonProps = SystemCommonProps & SystemLayoutProps & SxProp

const StyledButton = styled.button<StyledButtonProps>`
const StyledButton = styled.button<SxProp>`
border: none;
padding: 0;
background: transparent;
Expand All @@ -23,8 +21,6 @@ const StyledButton = styled.button<StyledButtonProps>`
&:hover {
color: ${get('colors.accent.fg')};
}
${COMMON};
${LAYOUT};
${sx};
`

Expand Down
5 changes: 2 additions & 3 deletions src/Button/ButtonDanger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps, ButtonSystemProps, buttonSystemProps} from './ButtonBase'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'

const ButtonDanger = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
const ButtonDanger = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.btn.danger.text')};
border: 1px solid ${get('colors.btn.border')};
background-color: ${get('colors.btn.bg')};
Expand Down Expand Up @@ -35,7 +35,6 @@ const ButtonDanger = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & Sx
border-color: ${get('colors.btn.danger.disabledBorder')};
}

${buttonSystemProps};
${sx};
`

Expand Down
5 changes: 2 additions & 3 deletions src/Button/ButtonInvisible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps, ButtonSystemProps, buttonSystemProps} from './ButtonBase'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'

const ButtonInvisible = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
const ButtonInvisible = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.accent.fg')};
background-color: transparent;
border: 0;
Expand All @@ -24,7 +24,6 @@ const ButtonInvisible = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps &
background-color: ${get('colors.btn.selectedBg')};
}

${buttonSystemProps};
${sx}
`

Expand Down
5 changes: 2 additions & 3 deletions src/Button/ButtonOutline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps, ButtonSystemProps, buttonSystemProps} from './ButtonBase'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'

const ButtonOutline = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
const ButtonOutline = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.btn.outline.text')};
border: 1px solid ${get('colors.btn.border')};
background-color: ${get('colors.btn.bg')};
Expand Down Expand Up @@ -35,7 +35,6 @@ const ButtonOutline = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & S
border-color: ${get('colors.btn.border')};
}

${buttonSystemProps};
${sx};
`

Expand Down
5 changes: 2 additions & 3 deletions src/Button/ButtonPrimary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps, ButtonSystemProps, buttonSystemProps} from './ButtonBase'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'

export const ButtonPrimary = styled(ButtonBase)<ButtonBaseProps & ButtonSystemProps & SxProp>`
export const ButtonPrimary = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.btn.primary.text')};
border: 1px solid ${get('colors.btn.primary.border')};
background-color: ${get('colors.btn.primary.bg')};
Expand Down Expand Up @@ -33,7 +33,6 @@ export const ButtonPrimary = styled(ButtonBase)<ButtonBaseProps & ButtonSystemPr
border-color: ${get('colors.btn.primary.disabledBorder')};
}

${buttonSystemProps};
${sx};
`

Expand Down
17 changes: 2 additions & 15 deletions src/Button/ButtonTableList.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import styled from 'styled-components'
import {
COMMON,
get,
LAYOUT,
SystemCommonProps,
SystemLayoutProps,
SystemTypographyProps,
TYPOGRAPHY
} from '../constants'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'

type StyledButtonTableListProps = SystemCommonProps & SystemTypographyProps & SystemLayoutProps & SxProp

const ButtonTableList = styled.summary<StyledButtonTableListProps>`
const ButtonTableList = styled.summary<SxProp>`
display: inline-block;
padding: 0;
font-size: ${get('fontSizes.1')};
Expand Down Expand Up @@ -48,9 +38,6 @@ const ButtonTableList = styled.summary<StyledButtonTableListProps>`
border: 4px solid transparent;
border-top-color: currentcolor;
}
${COMMON}
${TYPOGRAPHY}
${LAYOUT}
${sx};
`

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Button', () => {
})

it('respects width props', () => {
expect(render(<Button width={200} />)).toHaveStyleRule('width', '200px')
expect(render(<Button sx={{width: 200}} />)).toHaveStyleRule('width', '200px')
})

it('respects the "disabled" prop', () => {
Expand All @@ -63,7 +63,7 @@ describe('Button', () => {
})

it('respects the "fontSize" prop over the "variant" prop', () => {
expect(render(<Button variant="small" fontSize={20} />)).toHaveStyleRule('font-size', '20px')
expect(render(<Button variant="small" sx={{fontSize: 20}} />)).toHaveStyleRule('font-size', '20px')
})
})

Expand Down