Skip to content

Commit

Permalink
Remove link button (#1880)
Browse files Browse the repository at this point in the history
* Remove link button

* Fix up test

* Fix up tests

* Create rich-tools-cry.md
  • Loading branch information
pksjce committed Mar 1, 2022
1 parent dbcb557 commit 0256a5f
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 236 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-tools-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Remove link button from the new button
21 changes: 2 additions & 19 deletions docs/content/drafts/Button2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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'
import {Button} from '@primer/react/drafts'

## Usage

Expand Down Expand Up @@ -85,29 +85,12 @@ It is recommended to use an octicon here.
### Icon only button

A separate component called `IconButton` is used if the action shows only an icon with no text. This button will remain square in shape.
Read more at [IconButton docs](/drafts/IconButton)

```jsx live drafts
<IconButton icon={SearchIcon}>Search</IconButton>
```

### Different sized icon buttons

`IconButton` also supports the three different sizes. `small`, `medium`, `large`.

```jsx live drafts
<>
<IconButton icon={SearchIcon} size="small">
Search
</IconButton>
<IconButton sx={{ml: 2}} icon={SearchIcon}>
Search
</IconButton>
<IconButton sx={{ml: 2}} icon={SearchIcon} size="large">
Search
</IconButton>
</>
```

### Counter component

A common use case for primer is a button with a counter component which shows the child count value.
Expand Down
111 changes: 0 additions & 111 deletions docs/content/drafts/LinkButton.mdx

This file was deleted.

48 changes: 37 additions & 11 deletions src/Button2/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import React, {forwardRef} from 'react'
import {ButtonProps} from './types'
import {ButtonBase} from './ButtonBase'
import React, {ComponentPropsWithRef, forwardRef, ComponentType} 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 as ButtonComponentProps, StyledButton} from './types'
import {getVariantStyles, getSizeStyles, getButtonStyles} from './styles'

const ButtonComponent = forwardRef<HTMLButtonElement, ButtonProps>(
({children, ...props}, forwardedRef): JSX.Element => {
const Button = forwardRef<HTMLElement, ButtonComponentProps>(
({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 (
<ButtonBase ref={forwardedRef} {...props} as="button">
{children}
</ButtonBase>
<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>
)
}
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as PolymorphicForwardRefComponent<string | ComponentType<any> | undefined, ButtonComponentProps>

ButtonComponent.displayName = 'Button'
export type ButtonProps = ComponentPropsWithRef<typeof Button>

export {ButtonComponent}
export {Button}
30 changes: 15 additions & 15 deletions src/Button2/Button2.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, forwardRef} from 'react'
import {Button, ButtonProps, IconButton, LinkButton} from '.'
import {Button, ButtonProps, IconButton} from '.'
import {BaseStyles, ThemeProvider} from '..'
import {Meta} from '@storybook/react'
import {XIcon, SearchIcon, EyeIcon, EyeClosedIcon, TriangleDownIcon, TriangleRightIcon} from '@primer/octicons-react'
Expand Down Expand Up @@ -198,39 +198,39 @@ export const linkButton = ({...args}: ButtonProps) => {
return (
<>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" {...args}>
<Button href="https://primer.style/" {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" variant="danger" {...args}>
<Button href="https://primer.style/" variant="danger" {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" variant="primary" {...args}>
<Button href="https://primer.style/" variant="primary" {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" variant="outline" {...args}>
<Button href="https://primer.style/" variant="outline" {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" variant="invisible" {...args}>
<Button href="https://primer.style/" variant="invisible" {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton href="https://primer.style/" variant="primary" trailingIcon={TriangleRightIcon} {...args}>
<Button href="https://primer.style/" variant="primary" trailingIcon={TriangleRightIcon} {...args} as="a">
Link to Primer
</LinkButton>
</Button>
</Box>
<Box mb={2} display="flex">
<LinkButton to="/dummy" as={ReactRouterLikeLink} variant="primary" trailingIcon={TriangleRightIcon} {...args}>
<Button to="/dummy" variant="primary" trailingIcon={TriangleRightIcon} {...args} as={ReactRouterLikeLink}>
Link to Primer
</LinkButton>
</Button>
</Box>
</>
)
Expand Down
42 changes: 0 additions & 42 deletions src/Button2/ButtonBase.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions src/Button2/LinkButton.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions src/Button2/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ButtonComponent} from './Button'
import {Button as 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 {IconButton}

export const Button = Object.assign(ButtonComponent, {
Counter
})

Button.displayName = 'Button'
6 changes: 4 additions & 2 deletions src/Button2/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {HTMLAttributes, ComponentPropsWithRef} from 'react'
import React, {HTMLAttributes, ComponentPropsWithRef, ComponentType} from 'react'
import styled from 'styled-components'
import {IconProps} from '@primer/octicons-react'
import sx, {SxProp} from '../sx'
Expand All @@ -24,8 +24,10 @@ export type ButtonBaseProps = {
* Items that are disabled can not be clicked, selected, or navigated through.
*/
disabled?: boolean
// eslint-disable-next-line @typescript-eslint/no-explicit-any
as?: string | ComponentType<any> | undefined
} & SxProp &
HTMLAttributes<HTMLButtonElement> &
HTMLAttributes<HTMLElement> &
StyledButtonProps

export type ButtonProps = {
Expand Down

0 comments on commit 0256a5f

Please sign in to comment.