-
Notifications
You must be signed in to change notification settings - Fork 646
Button deprecation #1908
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
Button deprecation #1908
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dd11ad5
Move old button to deprecated
pksjce eaec908
Move Button2 to main bundle
pksjce 6084fa0
Add migration docs
pksjce f096f3a
More changes from the checklist
pksjce 5660989
More deprecation
pksjce 222dddb
Update tests
pksjce e81a242
Add deprecated details
pksjce 0c286b7
Create many-roses-hammer.md
pksjce 0489b6a
Update .changeset/many-roses-hammer.md
pksjce b11a858
Update many-roses-hammer.md
pksjce c97fd6e
Update many-roses-hammer.md
pksjce d8c962e
Update many-roses-hammer.md
pksjce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| "@primer/react": patch | ||
| --- | ||
|
|
||
| ## Button deprecation | ||
|
|
||
| The new set of Button components brings a much needed update. | ||
| The older version was a set of seven different components. Each variant of the component had a separate component. | ||
| The guidelines to put in icons inside the buttons was also vague. With the new components, we now have a great guidance for common button usage. | ||
|
|
||
| ## Change list | ||
|
|
||
| ### Button variants | ||
|
|
||
| We now support a variant property which takes values `primary`, `invisible`, `outline` and `danger` | ||
|
|
||
| #### Before | ||
|
|
||
| ```jsx | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo for later.. we'd want to make these tables, but we can do this in a follow up PR |
||
| import {ButtonPrimary, ButtonInvisible, ButtonOutline, ButtonDanger} from '@primer/react' | ||
| <ButtonPrimary>Primary Button</ButtonPrimary> | ||
| <ButtonInvisible>Invisible Button</ButtonInvisible> | ||
| <ButtonOutline>Outline Button</ButtonOutline> | ||
| <ButtonDanger>Danger Button</ButtonDanger> | ||
| ``` | ||
|
|
||
| #### After | ||
|
|
||
| ```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> | ||
| ``` | ||
|
|
||
| ### 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. | ||
|
|
||
| #### Before | ||
|
|
||
| ```jsx | ||
| <Button> | ||
| <SearchIcon /> | ||
| Search | ||
| </Button> | ||
| ``` | ||
|
|
||
| #### After | ||
|
|
||
| ```jsx | ||
| <Button leadingIcon={SearchIcon}>Search</Button> | ||
| ``` | ||
|
|
||
| ### Icon buttons | ||
|
|
||
| Icon only buttons are common usages in products. So we now have a component for the specific usecase | ||
|
|
||
| #### Before | ||
|
|
||
| ```jsx | ||
| <Button> | ||
| <XIcon /> | ||
| </Button> | ||
| ``` | ||
|
|
||
| #### After | ||
|
|
||
| ```jsx | ||
| <IconButton aria-label="Close button" icon={XIcon} /> | ||
| ``` | ||
|
|
||
| ### Size property | ||
|
|
||
| Earlier we used `variant` to mean size property. Now we have a new property called `size` which is more semantically correct. | ||
|
|
||
| #### Before | ||
|
|
||
| ```jsx | ||
| <Button variant="small">Small button</Button> | ||
| ``` | ||
|
|
||
| #### After | ||
|
|
||
| ```jsx | ||
| <Button size="small">Small button</Button> | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,42 @@ | ||
| import styled from 'styled-components' | ||
| import {variant} from 'styled-system' | ||
| import {ComponentProps} from '../utils/types' | ||
| import buttonBaseStyles from './ButtonStyles' | ||
| import React, {ComponentPropsWithRef, forwardRef} from 'react' | ||
| import {ForwardRefComponent as PolymorphicForwardRefComponent} from '@radix-ui/react-polymorphic' | ||
| import Box from '../Box' | ||
| import {merge, SxProp} from '../sx' | ||
| import {useTheme} from '../ThemeProvider' | ||
| import {ButtonProps, StyledButton} from './types' | ||
| import {getVariantStyles, getSizeStyles, getButtonStyles} from './styles' | ||
|
|
||
| const variants = variant({ | ||
| variants: { | ||
| small: { | ||
| p: '4px 12px', | ||
| fontSize: 0 | ||
| }, | ||
| medium: { | ||
| fontSize: 1 | ||
| }, | ||
| large: { | ||
| fontSize: 2, | ||
| p: '10px 20px' | ||
| const ButtonBase = forwardRef<HTMLElement, ButtonProps>( | ||
| ({children, as: Component = 'button', sx: sxProp = {}, ...props}, forwardedRef): JSX.Element => { | ||
| const {leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium'} = props | ||
| const {theme} = useTheme() | ||
| const iconWrapStyles = { | ||
| display: 'inline-block' | ||
| } | ||
| const sxStyles = merge.all([ | ||
| getButtonStyles(theme), | ||
| getSizeStyles(size, variant, false), | ||
| getVariantStyles(variant, theme), | ||
| sxProp as SxProp | ||
| ]) | ||
| return ( | ||
| <StyledButton as={Component} sx={sxStyles} {...props} ref={forwardedRef}> | ||
| {LeadingIcon && ( | ||
| <Box as="span" data-component="leadingIcon" sx={iconWrapStyles}> | ||
| <LeadingIcon /> | ||
| </Box> | ||
| )} | ||
| {children && <span data-component="text">{children}</span>} | ||
| {TrailingIcon && ( | ||
| <Box as="span" data-component="trailingIcon" sx={{...iconWrapStyles, ml: 2}}> | ||
| <TrailingIcon /> | ||
| </Box> | ||
| )} | ||
| </StyledButton> | ||
| ) | ||
| } | ||
| }) | ||
| ) as PolymorphicForwardRefComponent<'button' | 'a', ButtonProps> | ||
|
|
||
| type StyledButtonBaseProps = { | ||
| as?: 'button' | 'a' | 'summary' | 'input' | string | React.ReactType | ||
| variant?: 'small' | 'medium' | 'large' | ||
| } | ||
| export type ButtonBaseProps = ComponentPropsWithRef<typeof ButtonBase> | ||
|
|
||
| const ButtonBase = styled.button.attrs<StyledButtonBaseProps>(({disabled, onClick}) => ({ | ||
| onClick: disabled ? undefined : onClick | ||
| }))<StyledButtonBaseProps>` | ||
| ${buttonBaseStyles} | ||
| ${variants} | ||
| ` | ||
|
|
||
| ButtonBase.defaultProps = { | ||
| variant: 'medium' | ||
| } | ||
|
|
||
| export type ButtonBaseProps = ComponentProps<typeof ButtonBase> | ||
| export default ButtonBase | ||
| export {ButtonBase} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,10 @@ | ||
| export {default} from './Button' | ||
| export type {ButtonProps} from './Button' | ||
| export {default as ButtonDanger} from './ButtonDanger' | ||
| export type {ButtonDangerProps} from './ButtonDanger' | ||
| export {default as ButtonGroup} from './ButtonGroup' | ||
| export type {ButtonGroupProps} from './ButtonGroup' | ||
| export {default as ButtonOutline} from './ButtonOutline' | ||
| export type {ButtonOutlineProps} from './ButtonOutline' | ||
| export {default as ButtonPrimary} from './ButtonPrimary' | ||
| export type {ButtonPrimaryProps} from './ButtonPrimary' | ||
| export {default as ButtonInvisible} from './ButtonInvisible' | ||
| export type {ButtonInvisibleProps} from './ButtonInvisible' | ||
| export {default as ButtonTableList} from './ButtonTableList' | ||
| export type {ButtonTableListProps} from './ButtonTableList' | ||
| export {default as ButtonClose} from './ButtonClose' | ||
| export type {ButtonCloseProps} from './ButtonClose' | ||
| import {ButtonComponent} from './Button' | ||
| import {Counter} from './ButtonCounter' | ||
| import {IconButton} from './IconButton' | ||
| import {LinkButton} from './LinkButton' | ||
| export type {ButtonProps, IconButtonProps} from './types' | ||
| export {IconButton, LinkButton} | ||
|
|
||
| export const Button = Object.assign(ButtonComponent, { | ||
| Counter | ||
| }) |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.