Skip to content

Commit

Permalink
Button deprecation (#1908)
Browse files Browse the repository at this point in the history
* Move old button to deprecated

* Move Button2 to main bundle

* Add migration docs

* More changes from the checklist

* More deprecation

* Update tests

* Add deprecated details

* Create many-roses-hammer.md

* Update .changeset/many-roses-hammer.md

Co-authored-by: Rez <rezrah@github.com>

* Update many-roses-hammer.md

* Update many-roses-hammer.md

* Update many-roses-hammer.md

Co-authored-by: Rez <rezrah@github.com>
  • Loading branch information
pksjce and rezrah committed Mar 1, 2022
1 parent a8a3de1 commit 61404ae
Show file tree
Hide file tree
Showing 61 changed files with 1,664 additions and 1,510 deletions.
145 changes: 145 additions & 0 deletions .changeset/many-roses-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
'@primer/react': major
---
### Button deprecation

A new set of `Button` components brings a much needed update. Previously to `v35`, `Button` was a set of seven independent components. In `v35`, we now have common `Button` usage guidelines and more convenient API.

#### Button variants
We now support a variant property which takes values `primary`, `invisible`, `outline` and `danger`

<table>
<tr>
<th> Before (v34)</th> <th> After (v35)</th>
</tr>
<tr>
<td valign="top">

```jsx

import { ButtonPrimary, ButtonInvisible,
ButtonOutline, ButtonDanger }
from '@primer/react'

<ButtonPrimary>
Primary Button
</ButtonPrimary>
<ButtonInvisible>
Invisible Button
</ButtonInvisible>
<ButtonOutline>
Outline Button
</ButtonOutline>
<ButtonDanger>
Danger Button
</ButtonDanger>
```

</td>
<td valign="top">

```jsx

import { Button } from '@primer/react'

<Button variant="primary">
Primary Button
</Button>
<Button variant="invisible">
Invisible Button
</Button>
<Button variant="outline">
Outline Button
</Button>
<Button variant="danger">
Danger Button
</Button>
```

</td>
</tr>
</table>

### Leading and Trailing icons

In the previous component, we allowed icon components to be direct children. This results in a lot of custom styling for the icon components.
In the new one, we now have `leadinIcon` and `trailingIcon` properties.

<table>
<tr>
<th> Before (v34)</th> <th> After (v35)</th>
</tr>
<tr>
<td valign="top">

```jsx
<Button>
<SearchIcon />
Search
</Button>
```

</td>
<td valign="top">

```jsx
<Button leadingIcon={SearchIcon}>Search</Button>
```

</td>
</tr>
</table>

### Icon buttons

Icon only buttons are common usages in products. So we now have a component for the specific usecase

<table>
<tr>
<th> Before (v34)</th> <th> After (v35)</th>
</tr>
<tr>
<td valign="top">

```jsx
<Button>
<XIcon />
</Button>
```

</td>
<td valign="top">

```jsx
<IconButton aria-label="Close button" icon={XIcon} />
```

</td>
</tr>
</table>

### Size property

Earlier we used `variant` to mean size property. Now we have a new property called `size` which is more semantically correct.

<table>
<tr>
<th> Before (v34)</th> <th> After (v35)</th>
</tr>
<tr>
<td valign="top">

```jsx
<Button variant="small">Small button</Button>
```

</td>
<td valign="top">

```jsx
<Button size="small">Small button</Button>
```

</td>
</tr>
</table>
6 changes: 2 additions & 4 deletions docs/content/drafts/Button2.mdx → docs/content/Button.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
componentId: button_v2
title: Button v2
componentId: button
title: Button
status: Alpha
source: https://github.com/primer/react/tree/main/src/Button2
storybook: '/react/storybook?path=/story/composite-components-button2'
description: Use button for the main actions on a page or form.
---

import {Props} from '../../src/props'
import {ComponentChecklist} from '../../src/component-checklist'
import {Button, IconButton, LinkButton} from '@primer/react/drafts'

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ storybook: '/react/storybook?path=/story/composite-components-button2'
description: An accessible button component with no text and only icon.
---

import {Props} from '../../src/props'
import {ComponentChecklist} from '../../src/component-checklist'

## Usage

### Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ storybook: '/react/storybook?path=/story/composite-components-button2'
description: It is a combination of a button and link. Use this to make your link look like a button.
---

import {Props} from '../../src/props'
import {ComponentChecklist} from '../../src/component-checklist'
import {ArrowRightIcon} from '@primer/octicons-react'

## Usage

### Installation
Expand Down
11 changes: 9 additions & 2 deletions docs/content/Buttons.mdx → docs/content/deprecated/Buttons.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
---
componentId: button
title: Button
status: Alpha
status: deprecated
source: https://github.com/primer/react/blob/main/src/Button
storybook: '/react/storybook?path=/story/composite-components-button--default-button'
---

## Deprecation

Use [Button](/Button) instead.

For more info on the changes, have a look at the migration guide.
[Button migration guide](/migration-guide/Button)

`Button` is used for actions, like in forms, while `Link` is used for destinations, or moving from one page to another.

In special cases where you'd like to use a `<a>` styled like a Button, use `<Button as='a'>` and provide an `href`.
Expand All @@ -16,7 +23,7 @@ To create a button group, wrap `Button` elements in the `ButtonGroup` element. `

### Kitchen sink

```jsx live
```jsx live deprecated
<>
<Button>Button</Button>
<ButtonDanger>Button danger</ButtonDanger>
Expand Down
16 changes: 8 additions & 8 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
url: /BranchName
- title: Breadcrumbs
url: /Breadcrumbs
- title: Buttons
url: /Buttons
- title: Button
url: /Button
- title: Checkbox
url: /Checkbox
- title: CheckboxGroup
Expand All @@ -79,12 +79,16 @@
url: /Header
- title: Heading
url: /Heading
- title: IconButton
url: /IconButton
- title: Label
url: /Label
- title: LabelGroup
url: /LabelGroup
- title: Link
url: /Link
- title: LinkButton
url: /LinkButton
- title: Overlay
url: /Overlay
- title: Pagehead
Expand Down Expand Up @@ -141,12 +145,6 @@
url: /UnderlineNav
- title: Drafts
children:
- title: Button v2
url: /drafts/Button2
- title: LinkButton
url: /drafts/LinkButton
- title: IconButton
url: /drafts/IconButton
- title: Deprecated
children:
- title: ActionList
Expand All @@ -155,6 +153,8 @@
url: /deprecated/ActionMenu
- title: BorderBox
url: /deprecated/BorderBox
- title: Buttons
url: /deprecated/Buttons
- title: Dialog
url: /deprecated/Dialog
- title: Dropdown
Expand Down
2 changes: 1 addition & 1 deletion src/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {OverlayProps} from './Overlay'
import {useProvidedRefOrCreate, useProvidedStateOrCreate, useMenuInitialFocus, useTypeaheadFocus} from './hooks'
import {Divider} from './ActionList/Divider'
import {ActionListContainerContext} from './ActionList/ActionListContainerContext'
import {Button, ButtonProps} from './Button2'
import {Button, ButtonProps} from './Button'
import {MandateProps} from './utils/types'

type MenuContextProps = Pick<
Expand Down
48 changes: 13 additions & 35 deletions src/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
import styled from 'styled-components'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'
import ButtonBase, {ButtonBaseProps} from './ButtonBase'
import React, {forwardRef} from 'react'
import {ButtonProps} from './types'
import {ButtonBase} from './ButtonBase'

const Button = styled(ButtonBase)<ButtonBaseProps & SxProp>`
color: ${get('colors.btn.text')};
background-color: ${get('colors.btn.bg')};
border: 1px solid ${get('colors.btn.border')};
box-shadow: ${get('shadows.btn.shadow')}, ${get('shadows.btn.insetShadow')}};
&:hover {
background-color: ${get('colors.btn.hoverBg')};
border-color: ${get('colors.btn.hoverBorder')};
}
// focus must come before :active so that the active box shadow overrides
&:focus {
border-color: ${get('colors.btn.focusBorder')};
box-shadow: ${get('shadows.btn.focusShadow')};
}
&:active {
background-color: ${get('colors.btn.selectedBg')};
box-shadow: ${get('shadows.btn.shadowActive')};
}
&:disabled {
color: ${get('colors.primer.fg.disabled')};
background-color: ${get('colors.btn.bg')};
border-color: ${get('colors.btn.border')};
const ButtonComponent = forwardRef<HTMLButtonElement, ButtonProps>(
({children, ...props}, forwardedRef): JSX.Element => {
return (
<ButtonBase ref={forwardedRef} {...props} as="button">
{children}
</ButtonBase>
)
}
)

${sx};
`
ButtonComponent.displayName = 'Button'

export type ButtonProps = ComponentProps<typeof Button>
export default Button
export {ButtonComponent}
File renamed without changes.
Loading

0 comments on commit 61404ae

Please sign in to comment.