Skip to content

Commit 5d01c97

Browse files
committed
Adjustment on the Card component
1 parent c6ea749 commit 5d01c97

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/Card.tsx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type CardProps = {
2626
badges?: ReactNode[]; // todo: restrict to badge component ? these badges are display on the image
2727
/** where actions can be placed */
2828
footer?: ReactNode;
29-
/** only affect the text */
29+
/** Default: "medium", only affect the text */
3030
size?: "small" | "medium" | "large";
3131
/** make the whole card clickable */
3232
enlargeLink?: boolean;
@@ -57,16 +57,11 @@ export type CardProps = {
5757
string
5858
>
5959
>;
60-
} & (CardProps.Default | CardProps.Horizontal) &
61-
(CardProps.EnlargedLink | CardProps.NotEnlargedLink);
60+
/** Default false */
61+
horizontal?: boolean;
62+
} & (CardProps.EnlargedLink | CardProps.NotEnlargedLink);
6263

6364
export namespace CardProps {
64-
export type Default = {
65-
horizontal?: never;
66-
};
67-
export type Horizontal = {
68-
horizontal: true;
69-
};
7065
export type EnlargedLink = {
7166
enlargeLink: true;
7267
iconId?: FrIconClassName | RiIconClassName;
@@ -112,20 +107,31 @@ export const Card = memo(
112107
return (
113108
<div
114109
className={cx(
115-
fr.cx("fr-card"),
116-
enlargeLink && fr.cx("fr-enlarge-link"),
117-
horizontal && fr.cx("fr-card--horizontal"),
118-
size === "small" && fr.cx("fr-card--sm"),
119-
size === "large" && fr.cx("fr-card--lg"),
120-
background === false && fr.cx("fr-card--no-background"),
121-
border === false && fr.cx("fr-card--no-border"),
122-
shadow && fr.cx("fr-card--shadow"),
123-
grey && fr.cx("fr-card--grey"),
124-
iconId !== undefined && fr.cx(iconId),
110+
fr.cx(
111+
"fr-card",
112+
enlargeLink && "fr-enlarge-link",
113+
horizontal && "fr-card--horizontal",
114+
(() => {
115+
switch (size) {
116+
case "large":
117+
return "fr-card--lg";
118+
case "small":
119+
return "fr-card--sm";
120+
case "medium":
121+
return undefined;
122+
}
123+
})(),
124+
!background && "fr-card--no-background",
125+
!border && "fr-card--no-border",
126+
shadow && "fr-card--shadow",
127+
grey && "fr-card--grey",
128+
iconId !== undefined && iconId
129+
),
125130
classes.root,
126131
className
127132
)}
128133
ref={ref}
134+
{...rest}
129135
>
130136
<div className={cx(fr.cx("fr-card__body"), classes.body)}>
131137
<div className={cx(fr.cx("fr-card__content"), classes.content)}>
@@ -158,7 +164,7 @@ export const Card = memo(
158164
<p className={cx(fr.cx("fr-card__footer"), classes.footer)}>{footer}</p>
159165
)}
160166
</div>
161-
{/* ensure we dont have an empty imageUrl string */}
167+
{/* ensure we don't have an empty imageUrl string */}
162168
{imageUrl !== undefined && imageUrl.length && (
163169
<div className={cx(fr.cx("fr-card__header"), classes.header)}>
164170
<div className={cx(fr.cx("fr-card__img"), classes.img)}>

0 commit comments

Comments
 (0)