Skip to content

Commit 57b52ff

Browse files
author
Julien Bouquillon
committed
fix: cleanup
1 parent 1d7b061 commit 57b52ff

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

src/Quote.tsx

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ import React, { memo, forwardRef, ReactNode } from "react";
22
import { symToStr } from "tsafe/symToStr";
33
import { assert } from "tsafe/assert";
44
import type { Equals } from "tsafe";
5-
import { fr } from "./lib";
5+
6+
import { FrClassName } from "./lib/generatedFromCss/classNames";
67
import { cx } from "./lib/tools/cx";
8+
import { fr } from "./lib";
79

8-
// We make users import dsfr.css, so we don't need to import the scoped CSS
9-
// but in the future if we have a complete component coverage it
10-
// we could stop requiring users to import the hole CSS and only import on a
11-
// per component basis.
1210
import "./dsfr/component/quote/quote.css";
13-
import { FrClassName } from "./lib/generatedFromCss/classNames";
1411

1512
export type QuoteProps = {
1613
className?: string;
17-
text: string;
18-
author?: string;
14+
text: ReactNode;
15+
author?: ReactNode;
1916
source?: ReactNode;
2017
sourceUrl?: string;
21-
image?: string;
22-
size?: "md" | "lg" | "xl";
18+
imageUrl?: string;
19+
size?: "medium" | "large" | "xlarge";
2320
accentColor?: QuoteProps.AccentColor;
21+
classes?: Partial<Record<"root" | "author" | "source" | "image" | "imageTag" | "text", string>>;
2422
};
2523

2624
export namespace QuoteProps {
@@ -34,37 +32,57 @@ export namespace QuoteProps {
3432
/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-quote> */
3533
export const Quote = memo(
3634
forwardRef<HTMLDivElement, QuoteProps>((props, ref) => {
37-
const { className, text, author, source, sourceUrl, image, size, accentColor, ...rest } =
38-
props;
35+
const {
36+
className,
37+
text,
38+
author,
39+
source,
40+
sourceUrl,
41+
imageUrl,
42+
size = "xlarge",
43+
accentColor,
44+
classes = {},
45+
...rest
46+
} = props;
3947

4048
assert<Equals<keyof typeof rest, never>>();
4149

4250
return (
4351
<figure
4452
className={cx(
4553
fr.cx("fr-quote"),
46-
image && fr.cx("fr-quote--column"),
54+
imageUrl && fr.cx("fr-quote--column"),
4755
accentColor && `fr-quote--${accentColor}`,
56+
classes.root,
4857
className
4958
)}
5059
ref={ref}
5160
>
5261
<blockquote cite={sourceUrl}>
5362
<p
5463
className={cx(
55-
size === "lg" && fr.cx("fr-text--lg"),
56-
size === "md" && fr.cx("fr-text--md")
64+
size === "large" && fr.cx("fr-text--lg"),
65+
size === "medium" && fr.cx("fr-text--md"),
66+
classes.text
5767
)}
5868
>
5969
« {text} »
6070
</p>
6171
</blockquote>
6272
<figcaption>
63-
{author && <p className="fr-quote__author">{author}</p>}
64-
{source && <ul className="fr-quote__source">{source}</ul>}
65-
{image !== undefined && (
66-
<div className="fr-quote__image">
67-
<img src={image} className="fr-responsive-img" alt="" />
73+
{author !== undefined && (
74+
<p className={cx(fr.cx("fr-quote__author"), classes.author)}>{author}</p>
75+
)}
76+
{source !== undefined && (
77+
<ul className={cx(fr.cx("fr-quote__source"), classes.source)}>{source}</ul>
78+
)}
79+
{imageUrl !== undefined && (
80+
<div className={cx("fr-quote__image", classes.image)}>
81+
<img
82+
src={imageUrl}
83+
className={cx(fr.cx("fr-responsive-img"), classes.imageTag)}
84+
alt=""
85+
/>
6886
</div>
6987
)}
7088
</figcaption>

stories/Quote.stories.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export const Default = getStory({
3535
</li>
3636
</>
3737
),
38-
image: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
39-
size: "xl",
38+
imageUrl: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
39+
size: "xlarge",
4040
className: ""
4141
});
4242

@@ -61,20 +61,20 @@ export const QuoteMediumAndAccent = getStory({
6161
</li>
6262
</>
6363
),
64-
image: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
65-
size: "md",
64+
imageUrl: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
65+
size: "medium",
6666
accentColor: "pink-macaron"
6767
});
6868

6969
export const QuoteWithoutDetails = getStory({
7070
text: "Lorem [...] elit ut. ",
7171
author: "Auteur",
72-
image: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png"
72+
imageUrl: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png"
7373
});
7474

7575
export const QuoteWithoutSource = getStory({
7676
text: "Lorem [...] elit ut. ",
77-
image: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png"
77+
imageUrl: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png"
7878
});
7979

8080
export const QuoteWithoutIllustration = getStory({
@@ -102,7 +102,7 @@ export const QuoteWithoutIllustration = getStory({
102102

103103
export const QuoteWithAccent = getStory({
104104
text: "Lorem [...] elit ut. ",
105-
image: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
105+
imageUrl: "//www.systeme-de-design.gouv.fr/img/placeholder.1x1.png",
106106
accentColor: "yellow-moutarde",
107107
author: "Someone"
108108
});

0 commit comments

Comments
 (0)