Skip to content

Commit 923b7c1

Browse files
fix(card): make link optional when enlargeLink false (#133)
* fix(card): optional link when enlargeLink false * fix(card): set default enlargeLink to false
1 parent d4a7e1c commit 923b7c1

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/Card.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { cx } from "./tools/cx";
1313
export type CardProps = {
1414
className?: string;
1515
title: ReactNode;
16-
linkProps: RegisteredLinkProps;
1716
desc?: ReactNode;
1817
imageUrl?: string;
1918
imageAlt?: string;
@@ -63,10 +62,12 @@ export type CardProps = {
6362
export namespace CardProps {
6463
export type EnlargedLink = {
6564
enlargeLink: true;
65+
linkProps: RegisteredLinkProps;
6666
iconId?: FrIconClassName | RiIconClassName;
6767
};
6868
export type NotEnlargedLink = {
6969
enlargeLink?: false;
70+
linkProps?: RegisteredLinkProps;
7071
iconId?: never;
7172
};
7273
}
@@ -90,7 +91,7 @@ export const Card = memo(
9091
horizontal = false,
9192
size = "medium",
9293
classes = {},
93-
enlargeLink = true,
94+
enlargeLink = false,
9495
background = true,
9596
border = true,
9697
shadow = false,
@@ -137,9 +138,16 @@ export const Card = memo(
137138
<div className={cx(fr.cx("fr-card__body"), classes.body)}>
138139
<div className={cx(fr.cx("fr-card__content"), classes.content)}>
139140
<h3 className={cx(fr.cx("fr-card__title"), classes.title)}>
140-
<Link {...linkProps} className={cx(linkProps.className, classes.link)}>
141-
{title}
142-
</Link>
141+
{linkProps !== undefined ? (
142+
<Link
143+
{...linkProps}
144+
className={cx(linkProps.className, classes.link)}
145+
>
146+
{title}
147+
</Link>
148+
) : (
149+
title
150+
)}
143151
</h3>
144152
{desc !== undefined && (
145153
<p className={cx(fr.cx("fr-card__desc"), classes.desc)}>{desc}</p>

stories/Card.stories.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const { meta, getStory } = getStoryFactory({
2020
"title": { "description": `Required.` },
2121
"desc": { "description": `` },
2222
linkProps: {
23-
"description": `Required. the Card Link props`
23+
"description": `Required only if enlargeLink is true. The Card Link props.`
2424
},
2525
enlargeLink: {
26-
"description": `default: true. Set to false to restrict the link area to the Card title only.`,
26+
"description": `Set to false to restrict the link area to the Card title only.`,
2727
"control": { "type": "boolean" }
2828
},
2929
size: {
@@ -277,7 +277,17 @@ export const CardGrey = getStory(
277277
{
278278
...defaultProps,
279279
"horizontal": true,
280-
"grey": false
280+
"grey": true
281281
},
282282
{ "description": "Carte horizontale grey", "defaultContainerWidth": 900 }
283283
);
284+
285+
export const CardNoLink = getStory(
286+
{
287+
...defaultProps,
288+
"enlargeLink": false,
289+
"horizontal": true,
290+
"linkProps": undefined
291+
},
292+
{ "description": "Carte horizontale sans lien", "defaultContainerWidth": 900 }
293+
);

0 commit comments

Comments
 (0)