Skip to content

Commit 3237a4e

Browse files
chore(LinkButton): remove sx from LinkButton (#6866)
Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
1 parent 51fa404 commit 3237a4e

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

.changeset/stale-avocados-enjoy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@primer/react": major
3+
"@primer/styled-react": minor
4+
---
5+
6+
chore(LinkButton): remove sx from LinkButton

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const config = defineConfig([
4242
'contributor-docs/adrs/*',
4343
'examples/codesandbox/**/*',
4444
'packages/react/src/utils/polymorphic.ts',
45-
'packages/styled-react/src/polymorphic.d.ts',
45+
'packages/styled-react/src/polymorphic.ts',
4646
'**/storybook-static',
4747
'**/CHANGELOG.md',
4848
'**/node_modules/**/*',
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import {forwardRef} from 'react'
2-
import type {LinkButtonProps, ButtonProps} from './types'
2+
import type {LinkButtonProps as BaseLinkButtonProps, ButtonProps} from './types'
33
import {ButtonBase} from './ButtonBase'
44
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
5-
import {defaultSxProp} from '../utils/defaultSxProp'
65

7-
type MyProps = LinkButtonProps & ButtonProps
6+
export type LinkButtonProps = Omit<BaseLinkButtonProps & ButtonProps, 'sx'>
87

9-
const LinkButton = forwardRef(
10-
({children, as: Component = 'a', sx = defaultSxProp, ...props}, forwardedRef): JSX.Element => {
11-
return (
12-
<ButtonBase as={Component} ref={forwardedRef} sx={sx} {...props}>
13-
{children}
14-
</ButtonBase>
15-
)
16-
},
17-
) as PolymorphicForwardRefComponent<'a', MyProps>
8+
const LinkButton = forwardRef(({children, as: Component = 'a', ...props}, forwardedRef): JSX.Element => {
9+
return (
10+
<ButtonBase as={Component} ref={forwardedRef} {...props}>
11+
{children}
12+
</ButtonBase>
13+
)
14+
}) as PolymorphicForwardRefComponent<'a', LinkButtonProps>
1815

1916
export {LinkButton}

packages/react/src/Button/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {IconButton} from './IconButton'
22
import {LinkButton} from './LinkButton'
33
export type {ButtonProps, IconButtonProps, ButtonBaseProps} from './types'
4+
export type {LinkButtonProps} from './LinkButton'
45
export {IconButton, LinkButton}
56
export {ButtonComponent as Button} from './Button'
67
export {ButtonBase} from './ButtonBase'

packages/react/src/ButtonGroup/ButtonGroup.dev.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const ButtonGroupSingleButton = () => (
5454

5555
export const LinkButtonWithIconButtons = () => (
5656
<ButtonGroup>
57-
<LinkButton size="small" sx={{color: 'deeppink'}} href="https://primer.style">
57+
<LinkButton size="small" style={{color: 'deeppink'}} href="https://primer.style">
5858
Small link
5959
</LinkButton>
6060
<Button className="testCustomClassnameColor">Pink link</Button>

packages/react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ exports[`@primer/react > should not update exports without a semver change 1`] =
9090
"type LabelProps",
9191
"Link",
9292
"LinkButton",
93+
"type LinkButtonProps",
9394
"type LinkProps",
9495
"merge",
9596
"NavList",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
LinkButton as PrimerLinkButton,
3+
type LinkButtonProps as PrimerLinkButtonProps,
4+
sx,
5+
type SxProp,
6+
} from '@primer/react'
7+
import styled from 'styled-components'
8+
import {type ForwardRefComponent} from '../polymorphic'
9+
10+
type LinkButtonProps = PrimerLinkButtonProps & SxProp
11+
12+
const LinkButton: ForwardRefComponent<'a', LinkButtonProps> = styled(PrimerLinkButton).withConfig({
13+
shouldForwardProp: prop => (prop as keyof LinkButtonProps) !== 'sx',
14+
})<LinkButtonProps>`
15+
${sx}
16+
`
17+
18+
export {LinkButton}
19+
export type {LinkButtonProps}

packages/styled-react/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import type {
3030
SpaceProps,
3131
TypographyProps,
3232
} from 'styled-system'
33+
import {LinkButton, type LinkButtonProps} from './components/LinkButton'
3334

3435
type StyledProps = SxProp &
3536
SpaceProps &
@@ -98,7 +99,7 @@ const ToggleSwitch = forwardRef<HTMLButtonElement, ToggleSwitchProps>(function T
9899
return <Box as={PrimerToggleSwitch} ref={ref} {...props} />
99100
})
100101

101-
export {Checkbox, SegmentedControl, StateLabel, SubNav, ToggleSwitch}
102+
export {LinkButton, type LinkButtonProps, Checkbox, SegmentedControl, StateLabel, SubNav, ToggleSwitch}
102103

103104
export {
104105
ActionList,
@@ -119,7 +120,6 @@ export {
119120
IconButton,
120121
Label,
121122
Link,
122-
LinkButton,
123123
NavList,
124124
Overlay,
125125
PageHeader,

0 commit comments

Comments
 (0)