Skip to content

chore: use emotion for styling (pt. 2) #9951

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 19 commits into from
Oct 2, 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: Fieldset
  • Loading branch information
aslilac committed Sep 29, 2023
commit 2eb0c9963e5ab4db7ad1917a6f5f280a4fbfe556
124 changes: 67 additions & 57 deletions site/src/components/DeploySettingsLayout/Fieldset.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,82 @@
import { makeStyles } from "@mui/styles";
import { FC, ReactNode, FormEventHandler } from "react";
import type { FC, ReactNode, FormEventHandler } from "react";
import Button from "@mui/material/Button";
import { type CSSObject, useTheme } from "@emotion/react";

export const Fieldset: FC<{
interface FieldsetProps {
children: ReactNode;
title: string | JSX.Element;
subtitle?: string | JSX.Element;
validation?: string | JSX.Element | false;
button?: JSX.Element | false;
onSubmit: FormEventHandler<HTMLFormElement>;
isSubmitting?: boolean;
}> = ({
title,
subtitle,
children,
validation,
button,
onSubmit,
isSubmitting,
}) => {
const styles = useStyles();
}

export const Fieldset: FC<FieldsetProps> = (props) => {
const {
title,
subtitle,
children,
validation,
button,
onSubmit,
isSubmitting,
} = props;
const theme = useTheme();

return (
<form className={styles.fieldset} onSubmit={onSubmit}>
<header className={styles.header}>
<div className={styles.title}>{title}</div>
{subtitle && <div className={styles.subtitle}>{subtitle}</div>}
<div className={styles.body}>{children}</div>
<form
css={{
borderRadius: theme.spacing(1),
border: `1px solid ${theme.palette.divider}`,
background: theme.palette.background.paper,
marginTop: theme.spacing(4),
}}
onSubmit={onSubmit}
>
<header css={{ padding: theme.spacing(3) }}>
<div
css={{
fontSize: theme.spacing(2.5),
margin: 0,
fontWeight: 600,
}}
>
{title}
</div>
{subtitle && (
<div
css={{
color: theme.palette.text.secondary,
fontSize: 14,
marginTop: theme.spacing(1),
}}
>
{subtitle}
</div>
)}
<div
css={[
theme.typography.body2 as CSSObject,
{ paddingTop: theme.spacing(2) },
]}
>
{children}
</div>
</header>
<footer className={styles.footer}>
<div className={styles.validation}>{validation}</div>
<footer
css={[
theme.typography.body2 as CSSObject,
{
background: theme.palette.background.paperLight,
padding: `${theme.spacing(2)} ${theme.spacing(3)}`,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
},
]}
>
<div css={{ color: theme.palette.text.secondary }}>{validation}</div>
{button || (
<Button type="submit" disabled={isSubmitting}>
Submit
Expand All @@ -39,40 +86,3 @@ export const Fieldset: FC<{
</form>
);
};

const useStyles = makeStyles((theme) => ({
fieldset: {
borderRadius: theme.spacing(1),
border: `1px solid ${theme.palette.divider}`,
background: theme.palette.background.paper,
marginTop: theme.spacing(4),
},
title: {
fontSize: theme.spacing(2.5),
margin: 0,
fontWeight: 600,
},
subtitle: {
color: theme.palette.text.secondary,
fontSize: 14,
marginTop: theme.spacing(1),
},
body: {
...theme.typography.body2,
paddingTop: theme.spacing(2),
},
validation: {
color: theme.palette.text.secondary,
},
header: {
padding: theme.spacing(3),
},
footer: {
...theme.typography.body2,
background: theme.palette.background.paperLight,
padding: `${theme.spacing(2)} ${theme.spacing(3)}`,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
},
}));