From e5ea50b3c367d147de092b6a60d60b930fd1123d Mon Sep 17 00:00:00 2001 From: pprevautel Date: Wed, 9 Aug 2023 14:16:17 +0200 Subject: [PATCH] feat: Choose Hx level for Card title ref #160 --- src/Card.tsx | 6 ++++-- stories/Card.stories.tsx | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Card.tsx b/src/Card.tsx index da3fc421b..5f27db7c3 100644 --- a/src/Card.tsx +++ b/src/Card.tsx @@ -15,6 +15,7 @@ export type CardProps = { id?: string; className?: string; title: ReactNode; + titleAs?: `h${2 | 3 | 4 | 5 | 6}`; desc?: ReactNode; imageUrl?: string; imageAlt?: string; @@ -81,6 +82,7 @@ export const Card = memo( id: props_id, className, title, + titleAs: HtmlTitleTag = "h3", linkProps, desc, imageUrl, @@ -146,7 +148,7 @@ export const Card = memo( >
-

+ {linkProps !== undefined ? ( + {desc !== undefined && (

{desc}

)} diff --git a/stories/Card.stories.tsx b/stories/Card.stories.tsx index 1d35f9c76..0aac7a002 100644 --- a/stories/Card.stories.tsx +++ b/stories/Card.stories.tsx @@ -18,6 +18,15 @@ const { meta, getStory } = getStoryFactory({ - [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Card.tsx)`, "argTypes": { "title": { "description": `Required.` }, + titleAs: { + "description": `Heading level`, + "options": (() => { + const headings = ["h2", "h3", "h4", "h5", "h6"] as const; + assert>(); + return headings; + })(), + "control": { "type": "radio" } + }, "desc": { "description": `` }, linkProps: { "description": `Required only if enlargeLink is true. The Card Link props.` @@ -30,9 +39,7 @@ const { meta, getStory } = getStoryFactory({ "description": "Card title text sizing", "options": (() => { const sizes = ["small", "medium", "large"] as const; - assert>(); - return sizes; })(), "control": { "type": "radio" } @@ -49,6 +56,7 @@ export default meta; const defaultProps = { "enlargeLink": true as const, "title": "Intitulé de la carte (sur lequel se trouve le lien)", + "titleAs": "h3" as const, "linkProps": { "href": "#" },