Skip to content

Commit 06c0b82

Browse files
authored
feat: add support for text body tag (#487)
1 parent 77c6b05 commit 06c0b82

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/Highlight.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type HighlightProps = {
1010
id?: string;
1111
className?: string;
1212
classes?: Partial<Record<"root" | "content", string>>;
13+
bodyAs?: "p" | "div";
1314
size?: HighlightProps.Size;
1415
style?: CSSProperties;
1516
children: NonNullable<ReactNode>;
@@ -22,7 +23,16 @@ export namespace HighlightProps {
2223
/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-highlight> */
2324
export const Highlight = memo(
2425
forwardRef<HTMLDivElement, HighlightProps>((props, ref) => {
25-
const { className, classes = {}, style, children, size, id: id_props, ...rest } = props;
26+
const {
27+
className,
28+
classes = {},
29+
style,
30+
children,
31+
bodyAs: HtmlBodyTag = "p",
32+
size,
33+
id: id_props,
34+
...rest
35+
} = props;
2636

2737
assert<Equals<keyof typeof rest, never>>();
2838

@@ -39,9 +49,9 @@ export const Highlight = memo(
3949
style={style}
4050
{...rest}
4151
>
42-
<p className={cx(fr.cx({ [`fr-text--${size}`]: size }), classes.content)}>
52+
<HtmlBodyTag className={cx(fr.cx({ [`fr-text--${size}`]: size }), classes.content)}>
4353
{children}
44-
</p>
54+
</HtmlBodyTag>
4555
</div>
4656
);
4757
})

test/integration/vite/src/Home.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Alert } from "@codegouvfr/react-dsfr/Alert";
22
import { Button } from "@codegouvfr/react-dsfr/Button";
33
import { ButtonsGroup } from "@codegouvfr/react-dsfr/ButtonsGroup";
4+
import { Highlight } from "@codegouvfr/react-dsfr/Highlight";
45

56
import { Input } from "@codegouvfr/react-dsfr/Input";
67
import { Select } from "@codegouvfr/react-dsfr/SelectNext";
@@ -80,6 +81,9 @@ export function Home() {
8081
<TileExample />
8182
<TableExample />
8283
<ControlledAccordion />
84+
<div className={fr.cx("fr-my-4w")}>
85+
<HighlightExample />
86+
</div>
8387
</>
8488
);
8589
}
@@ -252,3 +256,12 @@ function ControlledAccordion() {
252256
</Accordion>
253257
);
254258
}
259+
260+
function HighlightExample() {
261+
return (
262+
<Highlight
263+
children={`Les parents d’enfants de 11 à 14 ans n’ont aucune démarche à accomplir : les CAF versent automatiquement l’ARS aux familles déjà allocataires qui remplissent les conditions.`}
264+
bodyAs="p"
265+
/>
266+
)
267+
}

0 commit comments

Comments
 (0)