Skip to content

Commit e2f0ceb

Browse files
authored
Merge pull request #196 from IGNF/issue_164
feat(Card)!: update component to match dsfr guidelines (refs #164)
2 parents 3efa705 + 246ecb1 commit e2f0ceb

File tree

2 files changed

+118
-17
lines changed

2 files changed

+118
-17
lines changed

src/Card.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type CardProps = {
2323
detail?: ReactNode;
2424
end?: ReactNode;
2525
endDetail?: ReactNode;
26-
badges?: ReactNode[]; // todo: restrict to badge component ? these badges are display on the image
26+
badge?: ReactNode;
2727
/** where actions can be placed */
2828
footer?: ReactNode;
2929
/** Default: "medium", only affect the text */
@@ -52,7 +52,7 @@ export type CardProps = {
5252
| "detail"
5353
| "end"
5454
| "endDetail"
55-
| "badges"
55+
| "badge"
5656
| "footer",
5757
string
5858
>
@@ -91,7 +91,7 @@ export const Card = memo(
9191
detail,
9292
end,
9393
endDetail,
94-
badges,
94+
badge,
9595
footer,
9696
horizontal = false,
9797
size = "medium",
@@ -194,11 +194,9 @@ export const Card = memo(
194194
alt={imageAlt}
195195
/>
196196
</div>
197-
{badges !== undefined && badges.length && (
198-
<ul className={cx(fr.cx("fr-badges-group"), classes.badges)}>
199-
{badges.map((badge, i) => (
200-
<li key={i}>{badge}</li>
201-
))}
197+
{badge && (
198+
<ul className={cx(fr.cx("fr-badges-group"), classes.badge)}>
199+
<li>{badge}</li>
202200
</ul>
203201
)}
204202
</div>

stories/Card.stories.tsx

Lines changed: 112 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { Card, type CardProps } from "../dist/Card";
33
import { Badge } from "../dist/Badge";
4+
import { Tag } from "../dist/Tag";
45
import { sectionName } from "./sectionName";
56
import { getStoryFactory } from "./getStory";
67
import { assert } from "tsafe/assert";
@@ -33,19 +34,80 @@ const { meta, getStory } = getStoryFactory({
3334
},
3435
enlargeLink: {
3536
"description": `Set to false to restrict the link area to the Card title only.`,
37+
defaultValue: false,
3638
"control": { "type": "boolean" }
3739
},
40+
iconId: {
41+
"options": (() => {
42+
const options = ["fr-icon-checkbox-circle-line", "ri-ancient-gate-fill"] as const;
43+
44+
assert<
45+
typeof options[number] extends NonNullable<CardProps["iconId"]> ? true : false
46+
>();
47+
48+
return options;
49+
})(),
50+
"control": { "type": "radio" }
51+
},
3852
size: {
3953
"description": "Card title text sizing",
4054
"options": (() => {
4155
const sizes = ["small", "medium", "large"] as const;
4256
assert<Equals<typeof sizes[number] | undefined, CardProps["size"]>>();
4357
return sizes;
4458
})(),
59+
defaultValue: "medium",
4560
"control": { "type": "radio" }
4661
},
4762
imageUrl: {
4863
"description": "Use any image URL, or none"
64+
},
65+
imageAlt: {
66+
"description": "Alternative text for the image"
67+
},
68+
badge: {
69+
description: "Badge in the header"
70+
},
71+
start: {
72+
description:
73+
"Zone containing either tags group or badges group (not both) located above the card title"
74+
},
75+
detail: {
76+
description: "Hint text about the `start` zone"
77+
},
78+
end: {
79+
description: "Extra details or actions below the card content"
80+
},
81+
endDetail: {
82+
description: "Hint text about the `end` zone"
83+
},
84+
footer: {
85+
description: "Footer"
86+
},
87+
horizontal: {
88+
description: "Horizontal alignment",
89+
defaultValue: false,
90+
type: "boolean"
91+
},
92+
background: {
93+
description: "Card with opaque background",
94+
defaultValue: true,
95+
type: "boolean"
96+
},
97+
border: {
98+
description: "Card with border",
99+
defaultValue: true,
100+
type: "boolean"
101+
},
102+
shadow: {
103+
description: "Card with shadow",
104+
defaultValue: false,
105+
type: "boolean"
106+
},
107+
grey: {
108+
description: "Card content zone with grey background",
109+
defaultValue: false,
110+
type: "boolean"
49111
}
50112
},
51113
"disabledProps": ["lang"]
@@ -101,12 +163,12 @@ export const CardWithImageRatio = getStory(
101163
export const CardWithBadgeInTheHeader = getStory(
102164
{
103165
...defaultProps,
104-
"badges": [<Badge>LABEL BADGE</Badge>, <Badge severity="new">LABEL BADGE</Badge>]
166+
"badge": <Badge>LABEL BADGE</Badge>
105167
},
106-
{ "description": "Carte verticale avec badge dans l'image" }
168+
{ "description": "Carte verticale avec un badge dans l'image" }
107169
);
108170

109-
export const CardWithBadgeInTheContent = getStory(
171+
export const CardWithBadgesInTheContent = getStory(
110172
{
111173
...defaultProps,
112174
"start": (
@@ -120,13 +182,54 @@ export const CardWithBadgeInTheContent = getStory(
120182
</ul>
121183
)
122184
},
123-
{ "description": "Carte verticale avec badges dans le contenu" }
185+
{ "description": "Carte verticale avec plusieurs badges dans le contenu" }
186+
);
187+
188+
export const CardWithBadgeInTheHeaderAndTagsInTheContent = getStory(
189+
{
190+
...defaultProps,
191+
"badge": <Badge severity="new">LABEL BADGE</Badge>,
192+
"start": (
193+
<ul className={fr.cx("fr-tags-group")}>
194+
<li>
195+
<Tag>LABEL TAG 1</Tag>
196+
</li>
197+
<li>
198+
<Tag>LABEL TAG 2</Tag>
199+
</li>
200+
</ul>
201+
)
202+
},
203+
{
204+
"description":
205+
"Carte verticale avec un badge dans l'image et plusieurs tags dans le contenu"
206+
}
207+
);
208+
209+
export const CardWithTagsInTheContent = getStory(
210+
{
211+
...defaultProps,
212+
"start": (
213+
<ul className={fr.cx("fr-tags-group")}>
214+
<li>
215+
<Tag>LABEL TAG 1</Tag>
216+
</li>
217+
<li>
218+
<Tag>LABEL TAG 2</Tag>
219+
</li>
220+
</ul>
221+
)
222+
},
223+
{ "description": "Carte verticale avec plusieurs tags dans le contenu" }
124224
);
125225

126226
export const CardWithDetail = getStory(
127227
{
128228
...defaultProps,
129-
"detail": "détail(optionnel)"
229+
"detail": "détail(optionnel)",
230+
"classes": {
231+
detail: fr.cx("fr-icon-warning-fill")
232+
}
130233
},
131234
{ "description": "Carte verticale avec détail" }
132235
);
@@ -262,14 +365,14 @@ export const CardHorizontalWithActions = getStory(
262365
"enlargeLink": false,
263366
"horizontal": true,
264367
"size": "large",
265-
"badges": [<Badge>LABEL BADGE</Badge>],
368+
"badge": <Badge>LABEL BADGE</Badge>,
266369
"start": (
267-
<ul className={fr.cx("fr-badges-group")}>
370+
<ul className={fr.cx("fr-tags-group")}>
268371
<li>
269-
<Badge>LABEL BADGE</Badge>
372+
<Tag>LABEL TAG 1</Tag>
270373
</li>
271374
<li>
272-
<Badge severity="new">LABEL BADGE</Badge>
375+
<Tag>LABEL TAG 2</Tag>
273376
</li>
274377
</ul>
275378
),

0 commit comments

Comments
 (0)