Skip to content

Commit 5089c1c

Browse files
authored
Merge pull request #13560 from TylerAPfledderer/refactor/shadcn-ButtonLink
refactor: connect ShadCN `Link` to ShadCN `ButtonLink`
2 parents 23712db + 18fe6a9 commit 5089c1c

File tree

7 files changed

+45
-46
lines changed

7 files changed

+45
-46
lines changed

src/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Translation from "@/components/Translation"
99
import { cn } from "@/lib/utils/cn"
1010
import { scrollIntoView } from "@/lib/utils/scrollIntoView"
1111

12-
import { BaseLink } from "../../tailwind/Link"
1312
import { Button } from "../../tailwind/ui/buttons/Button"
13+
import { BaseLink } from "../../tailwind/ui/Link"
1414

1515
import { List, ListItem } from "./ui/list"
1616

src/components/SkipLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useTranslation } from "next-i18next"
22

33
import { MAIN_CONTENT_ID } from "@/lib/constants"
44

5-
import { BaseLink } from "../../tailwind/Link"
5+
import { BaseLink } from "../../tailwind/ui/Link"
66

77
export const SkipLink = () => {
88
const { t } = useTranslation()
File renamed without changes.

tailwind/ui/__stories__/Button.stories.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { MdChevronRight, MdExpandMore, MdNightlight } from "react-icons/md"
1+
import { MdChevronRight, MdExpandMore } from "react-icons/md"
22
import type { Meta, StoryObj } from "@storybook/react"
33

4-
import Translation from "@/components/Translation"
5-
64
import { HStack, VStack } from "../../../src/components/ui/flex"
75
import { Button, type ButtonVariantProps } from "../buttons/Button"
8-
import { ButtonLink } from "../buttons/Button"
96

107
const meta = {
118
title: "Atoms / Form / ShadCn Buttons",
@@ -105,25 +102,3 @@ export const MultiLineText: Story = {
105102
</HStack>
106103
),
107104
}
108-
109-
export const OverrideStyles: Story = {
110-
render: () => (
111-
<>
112-
<p>
113-
Show custom styling examples here for visual testing of overrides from
114-
the theme config
115-
</p>
116-
<VStack>
117-
<Button aria-label="toggle" className="px-1.5">
118-
<MdNightlight />
119-
</Button>
120-
<ButtonLink
121-
className="rounded-full px-0 py-0"
122-
linkProps={{ href: "#" }}
123-
>
124-
<Translation id="get-involved" />
125-
</ButtonLink>
126-
</VStack>
127-
</>
128-
),
129-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Meta, StoryObj } from "@storybook/react/*"
2+
3+
import { ButtonLink as ButtonLinkComponent } from "../buttons/Button"
4+
5+
const meta = {
6+
title: "Atoms / Form / ShadCn Buttons",
7+
component: ButtonLinkComponent,
8+
} satisfies Meta<typeof ButtonLinkComponent>
9+
10+
export default meta
11+
12+
export const ButtonLink: StoryObj<typeof meta> = {
13+
args: {
14+
href: "#",
15+
children: "What is Ethereum?",
16+
},
17+
}

tailwind/ui/buttons/Button.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import * as React from "react"
22
import { cva, type VariantProps } from "class-variance-authority"
33
import { Slot } from "@radix-ui/react-slot"
44

5-
import { BaseLink, type LinkProps } from "@/components/Link"
6-
75
import { cn } from "@/lib/utils/cn"
86
import { type MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
97
import { scrollIntoView } from "@/lib/utils/scrollIntoView"
108

9+
import { BaseLink, type LinkProps } from "../Link"
10+
1111
const buttonVariants = cva(
1212
"pointer inline-flex gap-2 items-center justify-center rounded border border-solid border-current text-primary transition focus-visible:outline focus-visible:outline-4 focus-visible:outline-primary-hover focus-visible:-outline-offset-1 disabled:text-disabled disabled:pointer-events-none hover:text-primary-hover [&[data-secondary='true']]:text-body [&>svg]:flex-shrink-0",
1313
{
1414
variants: {
1515
variant: {
1616
solid:
17-
"!text-background bg-primary border-transparent disabled:bg-disabled disabled:text-background hover:text-background hover:bg-primary-hover hover:shadow-button-hover active:shadow-none",
17+
"text-background bg-primary border-transparent disabled:bg-disabled disabled:text-background hover:text-background hover:bg-primary-hover hover:shadow-button-hover active:shadow-none",
1818
outline: "hover:shadow-button-hover active:shadow-none",
1919
ghost: "border-transparent",
2020
link: "border-transparent font-bold underline py-0 px-1 active:text-primary",
@@ -106,29 +106,22 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
106106
)
107107
Button.displayName = "Button"
108108

109-
type ButtonLinkProps = ButtonProps & {
110-
linkProps: LinkProps
109+
type ButtonLinkProps = Omit<LinkProps, "onClick"> & {
110+
buttonProps?: ButtonProps
111111
customEventOptions?: MatomoEventOptions
112112
}
113113

114114
const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
115-
({ linkProps, customEventOptions, children, ...buttonProps }, ref) => {
115+
({ buttonProps, customEventOptions, children, ...linkProps }, ref) => {
116116
const handleClick = () => {
117117
customEventOptions && trackCustomEvent(customEventOptions)
118118
}
119119
return (
120120
<Button asChild {...buttonProps}>
121121
<BaseLink
122122
ref={ref}
123-
activeStyle={{}}
124-
// TODO: Redress this override when migrating the link component
125-
color={
126-
buttonProps.variant === "solid" ? "background.base" : undefined
127-
}
128-
textDecor="none"
129-
_hover={{
130-
textDecor: "none",
131-
}}
123+
className="no-underline hover:no-underline"
124+
activeClassName=""
132125
{...linkProps}
133126
onClick={handleClick}
134127
>

tailwind/ui/buttons/ButtonTwoLines.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,20 @@ const ButtonTwoLines = ({
6363
)
6464

6565
if (props.componentType === "link") {
66+
const { buttonProps, ...rest } = props
6667
return (
67-
<ButtonLink className={commonClassStyles} size={size} {...props}>
68-
<ChildContent {...props} size={size} isIconLeft={isIconLeft} />
68+
<ButtonLink
69+
className={commonClassStyles}
70+
// size={size}
71+
buttonProps={buttonProps}
72+
{...rest}
73+
>
74+
<ChildContent
75+
{...rest}
76+
size={size}
77+
isSecondary={buttonProps?.isSecondary}
78+
isIconLeft={isIconLeft}
79+
/>
6980
</ButtonLink>
7081
)
7182
}
@@ -79,7 +90,10 @@ const ButtonTwoLines = ({
7990
export default ButtonTwoLines
8091

8192
const ChildContent = (
82-
props: Omit<ButtonTwoLinesProps, "iconAlignment"> & { isIconLeft: boolean }
93+
props: Omit<ButtonTwoLinesProps, "iconAlignment" | "buttonProps"> & {
94+
isIconLeft: boolean
95+
isSecondary?: boolean
96+
}
8397
) => {
8498
const {
8599
reverseTextOrder = false,

0 commit comments

Comments
 (0)