feat(SW-1806): Implemented design systems button inside buttonLink component and changed teasercard buttons
Approved-by: Matilda Landström
This commit is contained in:
@@ -1,25 +1,47 @@
|
||||
"use client"
|
||||
|
||||
import NextLink from "next/link"
|
||||
import Link from "next/link"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useMemo } from "react"
|
||||
import { type ComponentProps, type PropsWithChildren, useMemo } from "react"
|
||||
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import { trackClick } from "@/utils/tracking"
|
||||
|
||||
import type { ButtonLinkProps } from "@/types/components/buttonLink"
|
||||
import { variants } from "./variants"
|
||||
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
export interface ButtonLinkProps
|
||||
extends PropsWithChildren,
|
||||
Omit<ComponentProps<typeof Link>, "color">,
|
||||
VariantProps<typeof variants> {
|
||||
trackingId?: string
|
||||
trackingParams?: Record<string, string>
|
||||
appendToCurrentPath?: boolean
|
||||
}
|
||||
|
||||
export default function ButtonLink({
|
||||
children,
|
||||
variant,
|
||||
color,
|
||||
size,
|
||||
typography,
|
||||
className,
|
||||
href,
|
||||
target,
|
||||
onClick = () => {},
|
||||
trackingId,
|
||||
trackingParams,
|
||||
onClick = () => {},
|
||||
appendToCurrentPath,
|
||||
...buttonProps
|
||||
...props
|
||||
}: ButtonLinkProps) {
|
||||
const currentPageSlug = usePathname()
|
||||
const classNames = variants({
|
||||
variant,
|
||||
color,
|
||||
size,
|
||||
|
||||
typography,
|
||||
className,
|
||||
})
|
||||
|
||||
const fullUrl = useMemo(() => {
|
||||
let newPath = href
|
||||
@@ -31,19 +53,17 @@ export default function ButtonLink({
|
||||
}, [href, appendToCurrentPath, currentPageSlug])
|
||||
|
||||
return (
|
||||
<Button {...buttonProps} asChild>
|
||||
<NextLink
|
||||
href={fullUrl}
|
||||
target={target}
|
||||
onClick={(e) => {
|
||||
onClick(e)
|
||||
if (trackingId) {
|
||||
trackClick(trackingId, trackingParams)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</NextLink>
|
||||
</Button>
|
||||
<Link
|
||||
className={classNames}
|
||||
href={fullUrl}
|
||||
target={target}
|
||||
onClick={(e) => {
|
||||
onClick(e)
|
||||
if (trackingId) {
|
||||
trackClick(trackingId, trackingParams)
|
||||
}
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user