Skip to content

Commit 90c04bb

Browse files
author
Your Name
committed
Merge branch 'main' of https://github.com/chanzuckerberg/sci-components into prod
2 parents e6546a3 + 71d27ef commit 90c04bb

File tree

18 files changed

+401
-475
lines changed

18 files changed

+401
-475
lines changed

packages/components/src/common/styles-dictionary/css/variables.css

+130-380
Large diffs are not rendered by default.

packages/components/src/core/Button/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ButtonTypeMap = {
2020

2121
type ButtonSize = "small" | "medium" | "large";
2222

23-
interface BaseButtonProps {
23+
interface BaseButtonProps extends RawButtonProps {
2424
children?: React.ReactNode;
2525
isAllCaps?: boolean;
2626
}
@@ -51,7 +51,7 @@ export type SdsProps =
5151
| SdsMinimalButtonProps
5252
| SdsButtonProps;
5353

54-
export type ButtonProps = RawButtonProps & SdsProps;
54+
export type ButtonProps = SdsProps;
5555

5656
/**
5757
* (masoudmanson): The MUI variant prop is determined by the sdsType prop.

packages/components/src/core/ContentCard/ContentCard.types.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CardProps } from "@mui/material";
2+
import { ButtonProps } from "../Button";
23

34
interface BaseContentCardProps extends CardProps {
45
sdsType?: "wide" | "narrow";
@@ -10,7 +11,20 @@ interface BaseContentCardProps extends CardProps {
1011
decorativeBorder?: boolean;
1112
children?: React.ReactNode;
1213
clickableCard?: boolean;
14+
clickableCardProps?: ButtonProps;
1315
buttonsPosition?: "left" | "right";
16+
classes?: {
17+
cardPaper?: string;
18+
cardContent?: string;
19+
cardHeader?: string;
20+
cardMedia?: string;
21+
cardOverline?: string;
22+
cardTitle?: string;
23+
cardSubtitle?: string;
24+
cardMetadata?: string;
25+
cardActions?: string;
26+
clickableCardButton?: string;
27+
};
1428
}
1529

1630
export interface ImageContentCardProps extends BaseContentCardProps {

packages/components/src/core/ContentCard/__storybook__/index.stories.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ export default {
4747
defaultValue: { summary: "left" },
4848
},
4949
},
50+
classes: {
51+
control: {
52+
type: "object",
53+
},
54+
description:
55+
"Defines the css classes to be applied to the card components.",
56+
table: {
57+
type: { summary: "Experimental" },
58+
},
59+
},
5060
clickableCard: {
5161
control: {
5262
type: "boolean",
@@ -57,6 +67,16 @@ export default {
5767
defaultValue: { summary: "false" },
5868
},
5969
},
70+
clickableCardProps: {
71+
control: {
72+
type: "object",
73+
},
74+
description:
75+
"If clickableCard is set to true, this prop accepts a ButtonProps object to be passed to the button.",
76+
table: {
77+
type: { summary: "ButtonProps" },
78+
},
79+
},
6080
decorativeBorder: {
6181
control: {
6282
type: "boolean",
@@ -187,6 +207,10 @@ export const Default = {
187207
buttons: [CONTENT_CARD_BUTTONS_OPTIONS[2], CONTENT_CARD_BUTTONS_OPTIONS[5]],
188208
buttonsPosition: "left",
189209
clickableCard: false,
210+
clickableCardProps: {
211+
component: "a",
212+
href: "https://chanzuckerberg.com",
213+
},
190214
decorativeBorder: false,
191215
icon: CONTENT_CARD_ICON_OPTIONS[1],
192216
image: CONTENT_CARD_IMAGE_OPTIONS[4],

packages/components/src/core/ContentCard/__tests__/__snapshots__/index.test.tsx.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`ContentCard Default story renders snapshot 1`] = `
44
<div
5-
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 MuiCard-root css-hu9jj8-MuiPaper-root-MuiCard-root"
5+
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 MuiCard-root css-ok5j5u-MuiPaper-root-MuiCard-root"
66
>
77
<div
88
class="css-20z69m"
@@ -14,7 +14,7 @@ exports[`ContentCard Default story renders snapshot 1`] = `
1414
/>
1515
</div>
1616
<div
17-
class="css-u4mrcz"
17+
class="css-15wqe76"
1818
>
1919
<div>
2020
<div

packages/components/src/core/ContentCard/components/ContentCardActions/index.tsx

+23-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import {
66
showWarningIfFirstOccurence,
77
} from "src/common/warnings";
88
import { ContentCardProps } from "../..";
9+
import { EMPTY_OBJECT } from "src/common/utils";
910

1011
export interface ContentCardActionsProps {
1112
buttonsPosition?: "left" | "right";
1213
clickableCard?: ContentCardProps["clickableCard"];
14+
classes?: {
15+
cardActions?: string;
16+
};
1317
children:
1418
| React.ReactElement<ButtonProps>
1519
| Array<React.ReactElement<ButtonProps>>;
@@ -34,7 +38,14 @@ const ContentCardActions = forwardRef<HTMLDivElement, ContentCardActionsProps>(
3438
props: ContentCardActionsProps,
3539
ref
3640
): JSX.Element | null {
37-
const { buttonsPosition, clickableCard, children } = props;
41+
const {
42+
buttonsPosition,
43+
clickableCard,
44+
children,
45+
classes = EMPTY_OBJECT,
46+
} = props;
47+
48+
const { cardActions }: ContentCardActionsProps["classes"] = classes;
3849

3950
/**
4051
* (masoudmanson):
@@ -72,12 +83,16 @@ const ContentCardActions = forwardRef<HTMLDivElement, ContentCardActionsProps>(
7283
}
7384

7485
return (
75-
<StyledCardActions ref={ref} buttonsPosition={buttonsPosition}>
86+
<StyledCardActions
87+
ref={ref}
88+
buttonsPosition={buttonsPosition}
89+
className={cardActions}
90+
>
7691
{[
7792
React.cloneElement(
7893
clickableCardButton as React.ReactElement<ButtonProps>,
7994
{
80-
component: "a",
95+
component: "div",
8196
...(clickableCardButton?.props as ButtonProps),
8297
}
8398
),
@@ -87,7 +102,11 @@ const ContentCardActions = forwardRef<HTMLDivElement, ContentCardActionsProps>(
87102
}
88103

89104
return (
90-
<StyledCardActions ref={ref} buttonsPosition={buttonsPosition}>
105+
<StyledCardActions
106+
ref={ref}
107+
buttonsPosition={buttonsPosition}
108+
className={cardActions}
109+
>
91110
{validChildren}
92111
</StyledCardActions>
93112
);

packages/components/src/core/ContentCard/components/ContentCardImageMedia/index.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ContentCardImageMediaProps {
1010
sdsType: ContentCardProps["sdsType"];
1111
imageSize: ContentCardProps["imageSize"];
1212
image?: ContentCardProps["image"];
13+
className?: string;
1314
}
1415

1516
/**
@@ -21,8 +22,8 @@ const ContentCardImageMedia = forwardRef<
2122
>(function ContentCardImageMedia(
2223
props: ContentCardImageMediaProps,
2324
ref
24-
): JSX.Element {
25-
const { image, imageSize, sdsType } = props;
25+
): JSX.Element | null {
26+
const { image, imageSize, sdsType, className } = props;
2627

2728
/**
2829
* (masoudmanson): These styles makes the image responsive and
@@ -41,6 +42,8 @@ const ContentCardImageMedia = forwardRef<
4142
* (masoudmanson): We need to make sure the image is wrapped in a CardMedia component.
4243
* - If it's a string, wrap it in CardMedia with proper styles.
4344
* - If it's already a CardMedia component, clone it and apply the styles.
45+
* - If it's a valid element, clone it and apply the styles.
46+
* - If it's null, return null.
4447
*/
4548
const imageElement =
4649
typeof image === "string" ? (
@@ -58,10 +61,18 @@ const ContentCardImageMedia = forwardRef<
5861
...imageMediaStyles,
5962
},
6063
})
64+
) : React.isValidElement(image) ? (
65+
React.cloneElement(image as React.ReactElement, {
66+
style: {
67+
...imageMediaStyles,
68+
objectFit: "cover",
69+
objectPosition: "center",
70+
},
71+
})
6172
) : null;
6273

6374
return (
64-
<StyledImageMediaWrapper ref={ref} {...props}>
75+
<StyledImageMediaWrapper ref={ref} {...props} className={className}>
6576
{imageElement}
6677
</StyledImageMediaWrapper>
6778
);

packages/components/src/core/ContentCard/components/ContentCardTitle/index.tsx

+36-6
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,64 @@ import {
66
StyledMetadataText,
77
StyledTitleWrapper,
88
} from "./style";
9+
import { EMPTY_OBJECT } from "src/common/utils";
910

1011
export interface ContentCardTitleProps {
1112
overlineText?: string;
1213
titleText?: string;
1314
subtitleText?: string;
1415
metadataText?: string;
16+
classes?: {
17+
cardHeader?: string;
18+
cardOverline?: string;
19+
cardTitle?: string;
20+
cardSubtitle?: string;
21+
cardMetadata?: string;
22+
};
1523
}
1624

1725
/**
1826
* @see https://mui.com/material-ui/react-dialog/
1927
*/
2028
const ContentCardTitle = forwardRef<HTMLDivElement, ContentCardTitleProps>(
2129
function ContentCardTitle(props: ContentCardTitleProps, ref): JSX.Element {
22-
const { overlineText, titleText, subtitleText, metadataText } = props;
30+
const {
31+
overlineText,
32+
titleText,
33+
subtitleText,
34+
metadataText,
35+
classes = EMPTY_OBJECT,
36+
} = props;
37+
38+
const {
39+
cardHeader,
40+
cardOverline,
41+
cardTitle,
42+
cardSubtitle,
43+
cardMetadata,
44+
}: ContentCardTitleProps["classes"] = classes;
2345

2446
return (
2547
<div ref={ref}>
26-
<StyledTitleWrapper>
48+
<StyledTitleWrapper className={cardHeader}>
2749
{overlineText && (
28-
<StyledOverlineText>{overlineText}</StyledOverlineText>
50+
<StyledOverlineText className={cardOverline}>
51+
{overlineText}
52+
</StyledOverlineText>
53+
)}
54+
{titleText && (
55+
<StyledTitleText className={cardTitle}>{titleText}</StyledTitleText>
2956
)}
30-
{titleText && <StyledTitleText>{titleText}</StyledTitleText>}
3157
{subtitleText && (
32-
<StyledSubtitleText>{subtitleText}</StyledSubtitleText>
58+
<StyledSubtitleText className={cardSubtitle}>
59+
{subtitleText}
60+
</StyledSubtitleText>
3361
)}
3462
</StyledTitleWrapper>
3563
{metadataText && (
36-
<StyledMetadataText>{metadataText}</StyledMetadataText>
64+
<StyledMetadataText className={cardMetadata}>
65+
{metadataText}
66+
</StyledMetadataText>
3767
)}
3868
</div>
3969
);

0 commit comments

Comments
 (0)