Skip to content

Commit c367c99

Browse files
committed
Remove link button
1 parent 2abd7b7 commit c367c99

File tree

8 files changed

+60
-236
lines changed

8 files changed

+60
-236
lines changed

docs/content/drafts/Button2.mdx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Use button for the main actions on a page or form.
99

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

1414
## Usage
1515

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

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

8990
```jsx live drafts
9091
<IconButton icon={SearchIcon}>Search</IconButton>
9192
```
9293

93-
### Different sized icon buttons
94-
95-
`IconButton` also supports the three different sizes. `small`, `medium`, `large`.
96-
97-
```jsx live drafts
98-
<>
99-
<IconButton icon={SearchIcon} size="small">
100-
Search
101-
</IconButton>
102-
<IconButton sx={{ml: 2}} icon={SearchIcon}>
103-
Search
104-
</IconButton>
105-
<IconButton sx={{ml: 2}} icon={SearchIcon} size="large">
106-
Search
107-
</IconButton>
108-
</>
109-
```
110-
11194
### Counter component
11295

11396
A common use case for primer is a button with a counter component which shows the child count value.

docs/content/drafts/LinkButton.mdx

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/Button2/Button.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1-
import React, {forwardRef} from 'react'
2-
import {ButtonProps} from './types'
3-
import {ButtonBase} from './ButtonBase'
1+
import React, {ComponentPropsWithRef, forwardRef, ComponentType} from 'react'
2+
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '@radix-ui/react-polymorphic'
3+
import Box from '../Box'
4+
import {merge, SxProp} from '../sx'
5+
import {useTheme} from '../ThemeProvider'
6+
import {ButtonProps as ButtonComponentProps, StyledButton} from './types'
7+
import {getVariantStyles, getSizeStyles, getButtonStyles} from './styles'
48

5-
const ButtonComponent = forwardRef<HTMLButtonElement, ButtonProps>(
6-
({children, ...props}, forwardedRef): JSX.Element => {
9+
const Button = forwardRef<HTMLElement, ButtonComponentProps>(
10+
({children, as: Component = 'button', sx: sxProp = {}, ...props}, forwardedRef): JSX.Element => {
11+
const {leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium'} = props
12+
const {theme} = useTheme()
13+
const iconWrapStyles = {
14+
display: 'inline-block'
15+
}
16+
const sxStyles = merge.all([
17+
getButtonStyles(theme),
18+
getSizeStyles(size, variant, false),
19+
getVariantStyles(variant, theme),
20+
sxProp as SxProp
21+
])
722
return (
8-
<ButtonBase ref={forwardedRef} {...props} as="button">
9-
{children}
10-
</ButtonBase>
23+
<StyledButton as={Component} sx={sxStyles} {...props} ref={forwardedRef}>
24+
{LeadingIcon && (
25+
<Box as="span" data-component="leadingIcon" sx={iconWrapStyles}>
26+
<LeadingIcon />
27+
</Box>
28+
)}
29+
{children && <span data-component="text">{children}</span>}
30+
{TrailingIcon && (
31+
<Box as="span" data-component="trailingIcon" sx={{...iconWrapStyles, ml: 2}}>
32+
<TrailingIcon />
33+
</Box>
34+
)}
35+
</StyledButton>
1136
)
1237
}
13-
)
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
) as PolymorphicForwardRefComponent<string | ComponentType<any> | undefined, ButtonComponentProps>
1440

15-
ButtonComponent.displayName = 'Button'
41+
export type ButtonProps = ComponentPropsWithRef<typeof Button>
1642

17-
export {ButtonComponent}
43+
export {Button}

src/Button2/Button2.stories.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState, forwardRef} from 'react'
2-
import {Button, ButtonProps, IconButton, LinkButton} from '.'
2+
import {Button, ButtonProps, IconButton} from '.'
33
import {BaseStyles, ThemeProvider} from '..'
44
import {Meta} from '@storybook/react'
55
import {XIcon, SearchIcon, EyeIcon, EyeClosedIcon, TriangleDownIcon, TriangleRightIcon} from '@primer/octicons-react'
@@ -198,39 +198,39 @@ export const linkButton = ({...args}: ButtonProps) => {
198198
return (
199199
<>
200200
<Box mb={2} display="flex">
201-
<LinkButton href="https://primer.style/" {...args}>
201+
<Button href="https://primer.style/" {...args} as="a">
202202
Link to Primer
203-
</LinkButton>
203+
</Button>
204204
</Box>
205205
<Box mb={2} display="flex">
206-
<LinkButton href="https://primer.style/" variant="danger" {...args}>
206+
<Button href="https://primer.style/" variant="danger" {...args} as="a">
207207
Link to Primer
208-
</LinkButton>
208+
</Button>
209209
</Box>
210210
<Box mb={2} display="flex">
211-
<LinkButton href="https://primer.style/" variant="primary" {...args}>
211+
<Button href="https://primer.style/" variant="primary" {...args} as="a">
212212
Link to Primer
213-
</LinkButton>
213+
</Button>
214214
</Box>
215215
<Box mb={2} display="flex">
216-
<LinkButton href="https://primer.style/" variant="outline" {...args}>
216+
<Button href="https://primer.style/" variant="outline" {...args} as="a">
217217
Link to Primer
218-
</LinkButton>
218+
</Button>
219219
</Box>
220220
<Box mb={2} display="flex">
221-
<LinkButton href="https://primer.style/" variant="invisible" {...args}>
221+
<Button href="https://primer.style/" variant="invisible" {...args} as="a">
222222
Link to Primer
223-
</LinkButton>
223+
</Button>
224224
</Box>
225225
<Box mb={2} display="flex">
226-
<LinkButton href="https://primer.style/" variant="primary" trailingIcon={TriangleRightIcon} {...args}>
226+
<Button href="https://primer.style/" variant="primary" trailingIcon={TriangleRightIcon} {...args} as="a">
227227
Link to Primer
228-
</LinkButton>
228+
</Button>
229229
</Box>
230230
<Box mb={2} display="flex">
231-
<LinkButton to="/dummy" as={ReactRouterLikeLink} variant="primary" trailingIcon={TriangleRightIcon} {...args}>
231+
<Button to="/dummy" variant="primary" trailingIcon={TriangleRightIcon} {...args} as={ReactRouterLikeLink}>
232232
Link to Primer
233-
</LinkButton>
233+
</Button>
234234
</Box>
235235
</>
236236
)

src/Button2/ButtonBase.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Button2/LinkButton.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Button2/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {ButtonComponent} from './Button'
1+
import {Button as ButtonComponent} from './Button'
22
import {Counter} from './ButtonCounter'
33
import {IconButton} from './IconButton'
4-
import {LinkButton} from './LinkButton'
54
export type {ButtonProps, IconButtonProps} from './types'
6-
export {IconButton, LinkButton}
5+
export {IconButton}
76

87
export const Button = Object.assign(ButtonComponent, {
98
Counter

src/Button2/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {HTMLAttributes, ComponentPropsWithRef} from 'react'
1+
import React, {HTMLAttributes, ComponentPropsWithRef, ComponentType} from 'react'
22
import styled from 'styled-components'
33
import {IconProps} from '@primer/octicons-react'
44
import sx, {SxProp} from '../sx'
@@ -24,8 +24,10 @@ export type ButtonBaseProps = {
2424
* Items that are disabled can not be clicked, selected, or navigated through.
2525
*/
2626
disabled?: boolean
27+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28+
as?: string | ComponentType<any> | undefined
2729
} & SxProp &
28-
HTMLAttributes<HTMLButtonElement> &
30+
HTMLAttributes<HTMLElement> &
2931
StyledButtonProps
3032

3133
export type ButtonProps = {

0 commit comments

Comments
 (0)