Skip to content

Commit

Permalink
FIx: card itself is no longer an anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
GerwinTerpstra committed Jan 10, 2025
1 parent 49a8ab8 commit 30530e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
8 changes: 8 additions & 0 deletions packages/components-css/src/card/_mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@
text-decoration: var(--rhc-card-as-link-link-text-decoration, underline);
}

@mixin rhc-card__anchor {
a::after {
content: "";
inset: 0;
position: absolute;
}
}

@mixin rhc-card__link--active {
--utrecht-link-color: var(--rhc-card-as-link-link-active-color, #42145f);

Expand Down
4 changes: 4 additions & 0 deletions packages/components-css/src/card/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
@include mixin.rhc-card__link;
}

.rhc-card__anchor {
@include mixin.rhc-card__anchor;
}

.rhc-card:active {
@include mixin.rhc-card--active;
}
Expand Down
55 changes: 23 additions & 32 deletions packages/components-react/src/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import clsx from 'clsx';
import { AnchorHTMLAttributes, ForwardedRef, forwardRef, PropsWithChildren, ReactNode } from 'react';
import { ForwardedRef, forwardRef, PropsWithChildren, ReactNode } from 'react';
import { Image } from './Image';
import { Link } from './Link';

interface CardPropsBase extends AnchorHTMLAttributes<HTMLAnchorElement> {
interface CardPropsBase {
href: string;
title?: string;
className?: string;
heading: ReactNode;
}
Expand Down Expand Up @@ -37,7 +38,7 @@ export interface HorizontalImageCardProps extends CardPropsBase {
export const Card = forwardRef(
(
props: PropsWithChildren<CardProps | FullBleedCardProps | HorizontalImageCardProps>,
ref: ForwardedRef<HTMLAnchorElement>,
ref: ForwardedRef<HTMLDivElement>,
) => {
const { appearance, ...cardProps } = props;
switch (appearance) {
Expand Down Expand Up @@ -70,16 +71,10 @@ const DefaultCard = forwardRef(
children,
...restProps
}: PropsWithChildren<CardProps>,
ref: ForwardedRef<HTMLAnchorElement>,
ref: ForwardedRef<HTMLDivElement>,
) => {
return (
<a
className={clsx('rhc-card', 'rhc-card--default', className)}
href={href}
ref={ref}
title={title}
{...restProps}
>
<div className={clsx('rhc-card', 'rhc-card--default', className)} ref={ref} {...restProps}>
<div className="rhc-card__content">
<div className="rhc-card__image-container">
{<Image alt={imageAlt} className="rhc-card__image" src={imageSrc} />}
Expand All @@ -91,12 +86,14 @@ const DefaultCard = forwardRef(
{children}
</div>
<div className="rhc-card__footer">
<div className="rhc-card__link">
<Link>{linkLabel}</Link>
<div className="rhc-card__link rhc-card__anchor">
<Link href={href} title={title}>
{linkLabel}
</Link>
</div>
<div className="rhc-card__button">{button}</div>
</div>
</a>
</div>
);
},
);
Expand All @@ -117,23 +114,20 @@ export const FullBleedCard = forwardRef(
imageAlt,
...restProps
}: PropsWithChildren<FullBleedCardProps>,
ref: ForwardedRef<HTMLAnchorElement>,
ref: ForwardedRef<HTMLDivElement>,
) => (
<a
className={clsx('rhc-card', 'rhc-card--full-bleed', className)}
href={href}
ref={ref}
title={title}
{...restProps}
>
<div className={clsx('rhc-card', 'rhc-card--full-bleed', className)} ref={ref} {...restProps}>
<span className="rhc-card__anchor">
<a href={href} title={title}></a>
</span>
{<Image alt={imageAlt} className="rhc-card__image" src={imageSrc} />}
<div className="rhc-card__content">
<div className="rhc-card__heading">{heading}</div>
<div className="rhc-card__description">{description}</div>
<div className="rhc-card__metadata">{metadata}</div>
{children}
</div>
</a>
</div>
),
);

Expand All @@ -151,23 +145,20 @@ export const HorizontalImageCard = forwardRef(
className,
...restProps
}: PropsWithChildren<HorizontalImageCardProps>,
ref: ForwardedRef<HTMLAnchorElement>,
ref: ForwardedRef<HTMLDivElement>,
) => (
<a
className={clsx('rhc-card', 'rhc-card--horizontal', className)}
href={href}
ref={ref}
title={title}
{...restProps}
>
<div className={clsx('rhc-card', 'rhc-card--horizontal', className)} ref={ref} title={title} {...restProps}>
<span className="rhc-card__anchor">
<a href={href} title={title}></a>
</span>
<div className="rhc-card__image-container">
<Image alt={imageAlt} className="rhc-card__image" src={imageSrc} />
</div>
<div className="rhc-card__content">
<div className="rhc-card__heading">{heading}</div>
{children}
</div>
</a>
</div>
),
);

Expand Down

0 comments on commit 30530e8

Please sign in to comment.