Skip to content

chore: use emotion for styling (pt. 6) #10298

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

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
emotion: Section
  • Loading branch information
aslilac committed Oct 16, 2023
commit 8b6c1be73cd57a145167c98a1a45477280313ff4
38 changes: 16 additions & 22 deletions site/src/components/SettingsLayout/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { makeStyles } from "@mui/styles";
import { useTheme } from "@emotion/react";
import Typography from "@mui/material/Typography";
import { FC, ReactNode, PropsWithChildren } from "react";
import { type FC, type ReactNode, type PropsWithChildren } from "react";
import { SectionAction } from "./SectionAction";
import { type Interpolation, type Theme } from "@emotion/react";

type SectionLayout = "fixed" | "fluid";

Expand Down Expand Up @@ -31,31 +32,30 @@ export const Section: SectionFC = ({
children,
layout = "fixed",
}) => {
const styles = useStyles({ layout });
const theme = useTheme();

return (
<section className={className} id={id} data-testid={id}>
<div className={styles.inner}>
<div css={{ maxWidth: layout === "fluid" ? "100%" : 500 }}>
{(title || description) && (
<div className={styles.header}>
<div css={styles.header}>
<div>
{title && (
<Typography variant="h4" sx={{ fontSize: 24 }}>
{title}
</Typography>
)}
{description && typeof description === "string" && (
<Typography className={styles.description}>
{description}
</Typography>
<Typography css={styles.description}>{description}</Typography>
)}
{description && typeof description !== "string" && (
<div className={styles.description}>{description}</div>
<div css={styles.description}>{description}</div>
)}
</div>
{toolbar && <div>{toolbar}</div>}
</div>
)}
{alert && <div className={styles.alert}>{alert}</div>}
{alert && <div css={{ marginBottom: theme.spacing(1) }}>{alert}</div>}
{children}
</div>
</section>
Expand All @@ -65,23 +65,17 @@ export const Section: SectionFC = ({
// Sub-components
Section.Action = SectionAction;

const useStyles = makeStyles((theme) => ({
inner: ({ layout }: { layout: SectionLayout }) => ({
maxWidth: layout === "fluid" ? "100%" : 500,
}),
alert: {
marginBottom: theme.spacing(1),
},
header: {
const styles = {
header: (theme) => ({
marginBottom: theme.spacing(3),
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
},
description: {
}),
description: (theme) => ({
color: theme.palette.text.secondary,
fontSize: 16,
marginTop: theme.spacing(0.5),
lineHeight: "140%",
},
}));
}),
} satisfies Record<string, Interpolation<Theme>>;