Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useStyles from Components #1010

Merged
merged 16 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions apps/climatemappedafrica/src/components/AboutTeam/AboutTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import Card from "@/climatemappedafrica/components/Card";
import Carousel from "@/climatemappedafrica/components/Carousel";
import Section from "@/climatemappedafrica/components/Section";

// NOTE(kilemensi) useStyles uses import/definition order to determine how
// classes are ordered.
// see: https://material-ui.com/styles/advanced/#makestyles-withstyles-styled
// eslint-disable-next-line import/order
import useStyles from "./useStyles";

const responsive = {
desktop: {
items: 4,
Expand All @@ -24,9 +18,8 @@ const responsive = {
},
};

function AboutTeam({ title, members: membersProp, ...props }) {
function AboutTeam({ title, members: membersProp }) {
const membersCount = membersProp?.length ?? 0;
const classes = useStyles({ ...props, membersCount });
const theme = useTheme();
const isMdUp = useMediaQuery(theme.breakpoints.up("md"));
const ref = useRef();
Expand Down Expand Up @@ -54,7 +47,6 @@ function AboutTeam({ title, members: membersProp, ...props }) {
{title && (
<Typography
variant="h4"
className={classes.title}
sx={{
textAlign: "center",
paddingBottom: { xs: 5, md: 10 },
Expand All @@ -66,7 +58,23 @@ function AboutTeam({ title, members: membersProp, ...props }) {
<Carousel
afterChange={scrollToTeam}
responsive={responsive}
classes={{ dotList: classes.dotList }}
DotListProps={{
sx: {
display: {
xs: membersCount > 2 ? "flex" : "none",
md: membersCount > 4 ? "flex" : "none",
},
"& button": {
borderColor: "#000",
height: theme.typography.pxToRem(16),
marginRight: theme.typography.pxToRem(12),
width: theme.typography.pxToRem(16),
},
"& .react-multi-carousel-dot--active button": {
borderColor: "#000",
},
},
}}
>
{membersProp.map((member) => (
<Card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ exports[`<AboutTeam /> renders unchanged 1`] = `
class="MuiBox-root css-1termwk"
>
<div
class="makeStyles-root-7 makeStyles-root-5 makeStyles-root-3 makeStyles-fixed-4 MuiBox-root css-0"
class="makeStyles-root-5 makeStyles-root-3 makeStyles-root-1 makeStyles-fixed-2 MuiBox-root css-0"
>
<h4
class="MuiTypography-root MuiTypography-h4 css-1cvoujm-MuiTypography-root"
>
About Team
</h4>
<div
class="react-multi-carousel-list makeStyles-root-8"
dir="ltr"
class="MuiBox-root css-4jcry9"
>
<ul
class="react-multi-carousel-track "
style="transition: none; overflow: unset; transform: translate3d(0px,0,0);"
/>
<div
class="react-multi-carousel-list "
dir="ltr"
>
<ul
class="react-multi-carousel-track "
style="transition: none; overflow: unset; transform: translate3d(0px,0,0);"
/>
</div>
</div>
</div>
</div>
Expand Down
19 changes: 0 additions & 19 deletions apps/climatemappedafrica/src/components/AboutTeam/useStyles.js

This file was deleted.

36 changes: 20 additions & 16 deletions apps/climatemappedafrica/src/components/Card/ActionArea.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Link } from "@commons-ui/next";
import { CardActionArea } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import PropTypes from "prop-types";
import React from "react";

const useStyles = makeStyles(() => ({
root: {},
focusHighlight: {
background: "transparent",
},
focusVisible: {},
}));

function ActionArea({ href, children, onClick, ...props }) {
const classes = useStyles(props);

function ActionArea({
href,
children,
onClick,
ActionAreaRootProps,
FocusHighlightProps,
FocusVisibleProps,
...props
}) {
if (!(href || onClick)) {
return children;
}
Expand All @@ -26,10 +23,17 @@ function ActionArea({ href, children, onClick, ...props }) {
{...props}
href={href}
onClick={onClick}
classes={{
root: classes.root,
focusHighlight: classes.focusHighlight,
focusVisible: classes.focusVisible,
sx={{
"& .MuiCardActionArea-root": {
...ActionAreaRootProps,
},
"& .MuiCardActionArea-focusHighlight": {
background: "transparent",
...FocusHighlightProps,
},
"& .Mui-focusVisible": {
...FocusVisibleProps,
},
}}
>
{children}
Expand Down
70 changes: 44 additions & 26 deletions apps/climatemappedafrica/src/components/Card/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import React from "react";
import CardActionArea from "./ActionArea";
import CardContent from "./Content";
import CardMedia from "./Media";
import useStyles from "./useStyles";

function Card({
alt,
chart,
children,
className,
ctaText,
description,
descriptionProps,
Expand All @@ -28,10 +25,8 @@ function Card({
titleProps,
variant,
sx,
...props
}) {
const squareMedia = mediaProps?.square;
const classes = useStyles({ ...props, squareMedia });
const actionAreaProps = { href, onClick };
const contentProps = {
description,
Expand All @@ -46,34 +41,27 @@ function Card({
<MuiCard
elevation={0}
square
sx={(theme) => ({
sx={({ typography }) => ({
backgroundColor: "inherit",
boxShadow: "none",
borderRadius: 0,
padding: {
xs: squareMedia ? `0 ${theme.typography.pxToRem(36)}` : 0,
xs: squareMedia ? `0 ${typography.pxToRem(36)}` : 0,
md: 0,
},
minWidth: {
xs: theme.typography.pxToRem(350),
xs: typography.pxToRem(350),
md: "unset",
},
width: {
xs: "100%",
md: theme.typography.pxToRem(squareMedia ? 278 : 296),
lg: theme.typography.pxToRem(squareMedia ? 278 : 376),
md: typography.pxToRem(squareMedia ? 278 : 296),
lg: typography.pxToRem(squareMedia ? 278 : 376),
},
...sx,
})}
>
<CardActionArea
{...actionAreaProps}
classes={{
root: classes.actionArea,
focusHighlight: classes.actionAreaFocusHighlight,
focusVisible: classes.actionAreaFocusVisible,
}}
>
<CardActionArea {...actionAreaProps}>
<CardMedia
{...mediaProps}
alt={alt}
Expand All @@ -83,16 +71,46 @@ function Card({
imageProps={imageProps}
media={media}
variant={variant}
classes={{ root: classes.media, image: classes.mediaImage }}
/>
<CardContent
{...contentProps}
classes={{
root: classes.content,
description: classes.contentDescription,
link: classes.contentLink,
title: classes.contentTitle,
TitleProps={{
sx: ({ typography }) => ({
marginTop: typography.pxToRem(squareMedia ? 20 : 40),
overflow: "hidden",
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
textOverflow: "ellipsis",
}),
}}
DescriptionProps={{
sx: {
overflow: "hidden",
display: "-webkit-box",
WebkitLineClamp: 3,
WebkitBoxOrient: "vertical",
textOverflow: "ellipsis",
},
}}
sx={({ typography }) => ({
backgroundColor: "inherit",
boxShadow: "none",
borderRadius: 0,
padding: {
xs: squareMedia ? `0 ${typography.pxToRem(36)}` : 0,
md: 0,
},
minWidth: {
xs: typography.pxToRem(350),
md: "unset",
},
width: {
xs: "100%",
md: typography.pxToRem(squareMedia ? 278 : 296),
lg: typography.pxToRem(squareMedia ? 278 : 376),
},
})}
/>
</CardActionArea>
{href && ctaText && (
Expand All @@ -101,9 +119,9 @@ function Card({
underline="always"
variant="subtitle2"
{...linkProps}
sx={(theme) => ({
sx={({ typography }) => ({
display: "inline-flex",
marginTop: theme.typography.pxToRem(20),
marginTop: typography.pxToRem(20),
fontWeight: "bold",
})}
>
Expand Down
70 changes: 29 additions & 41 deletions apps/climatemappedafrica/src/components/Card/Content.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
import { RichTypography } from "@commons-ui/legacy";
import { RichText } from "@commons-ui/payload";
import { CardContent } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import clsx from "clsx";
import { CardContent, Typography } from "@mui/material";
import PropTypes from "prop-types";
import React from "react";

const useStyles = makeStyles(({ typography }) => ({
root: {
padding: 0,
"&:last-child": {
padding: 0,
},
},
title: {},
description: {
marginTop: typography.pxToRem(20),
},
link: {
display: "inline-flex",
marginTop: typography.pxToRem(20),
fontWeight: "bold",
},
}));

function Content({
className,
description,
descriptionProps,
DescriptionProps,
title,
titleProps,
TitleProps,
href,
ctaText,
linkProps,
...props
sx,
}) {
const classes = useStyles(props);
if (!(title || description || href)) {
return null;
}

return (
<CardContent className={clsx(classes.root, className)}>
<RichTypography variant="h5" {...titleProps} className={classes.title}>
<CardContent
sx={{
padding: 0,
"&:last-child": {
padding: 0,
},
...sx,
}}
>
<Typography
variant="h5"
{...TitleProps}
sx={{
...TitleProps?.sx,
}}
>
{title}
</RichTypography>
</Typography>
{/* Support for rich text while keeping backwards compatibility */}
{Array.isArray(description) ? (
<RichText
{...descriptionProps}
className={classes.description}
elements={description}
/>
<RichText {...DescriptionProps} elements={description} />
) : (
<RichTypography
<Typography
variant="subtitle2"
{...descriptionProps}
className={classes.description}
{...DescriptionProps}
sx={({ typography }) => ({
marginTop: typography.pxToRem(20),
...DescriptionProps?.sx,
})}
>
{description}
</RichTypography>
</Typography>
)}
</CardContent>
);
Expand Down
Loading
Loading