Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

sx

Manav Rathi2c2b8c1522fd
diff --git a/web/packages/accounts/pages/change-email.tsx b/web/packages/accounts/pages/change-email.tsx
index eaf898b210..2926e36392 100644
--- a/web/packages/accounts/pages/change-email.tsx
+++ b/web/packages/accounts/pages/change-email.tsx
@@ -186,11 +186,11 @@ const ChangeEmailForm: React.FC = () => {
</form>
<FormPaperFooter
- style={{
- justifyContent: ottInputVisible
- ? "space-between"
- : "normal",
- }}
+ sx={[
+ ottInputVisible
+ ? { justifyContent: "space-between" }
+ : { justifyContent: "normal" },
+ ]}
>
{ottInputVisible && (
<LinkButton
diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx
index 23cd710b0b..975f842fec 100644
--- a/web/packages/accounts/pages/recover.tsx
+++ b/web/packages/accounts/pages/recover.tsx
@@ -118,7 +118,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
buttonText={t("recover")}
disableAutoComplete
/>
- <FormPaperFooter style={{ justifyContent: "space-between" }}>
+ <FormPaperFooter sx={{ justifyContent: "space-between" }}>
<LinkButton onClick={showNoRecoveryKeyMessage}>
{t("no_recovery_key_title")}
</LinkButton>
diff --git a/web/packages/accounts/pages/two-factor/recover.tsx b/web/packages/accounts/pages/two-factor/recover.tsx
index 0edccfe39b..130e4e947d 100644
--- a/web/packages/accounts/pages/two-factor/recover.tsx
+++ b/web/packages/accounts/pages/two-factor/recover.tsx
@@ -176,7 +176,7 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {
buttonText={t("recover")}
disableAutoComplete
/>
- <FormPaperFooter style={{ justifyContent: "space-between" }}>
+ <FormPaperFooter sx={{ justifyContent: "space-between" }}>
<LinkButton onClick={() => showContactSupportDialog()}>
{t("no_recovery_key_title")}
</LinkButton>
diff --git a/web/packages/base/components/FormPaper.tsx b/web/packages/base/components/FormPaper.tsx
index 10b870dcd9..83f9cee15b 100644
--- a/web/packages/base/components/FormPaper.tsx
+++ b/web/packages/base/components/FormPaper.tsx
@@ -4,10 +4,10 @@ import {
Paper,
styled,
Typography,
- type BoxProps,
type TypographyProps,
} from "@mui/material";
import React from "react";
+import { isSxArray } from "./utils/sx";
export const FormPaper = styled(Paper)(({ theme }) => ({
padding: theme.spacing(4, 2),
@@ -24,24 +24,18 @@ export const FormPaperTitle: React.FC<TypographyProps> = ({ sx, ...props }) => {
);
};
-export const FormPaperFooter: React.FC<BoxProps> = ({
- sx,
- style,
- ...props
-}) => {
- return (
- <>
- <Divider />
- <VerticallyCentered
- style={{ flexDirection: "row", ...style }}
- sx={{
- mt: 3,
- ...sx,
- }}
- {...props}
- >
- {props.children}
- </VerticallyCentered>
- </>
- );
-};
+export const FormPaperFooter: React.FC<
+ React.PropsWithChildren<{ sx?: TypographyProps["sx"] }>
+> = ({ sx, children }) => (
+ <>
+ <Divider />
+ <VerticallyCentered
+ sx={[
+ { mt: 3, flexDirection: "row" },
+ ...(sx ? (isSxArray(sx) ? sx : [sx]) : []),
+ ]}
+ >
+ {children}
+ </VerticallyCentered>
+ </>
+);
diff --git a/web/packages/base/components/utils/sx.ts b/web/packages/base/components/utils/sx.ts
new file mode 100644
index 0000000000..3e0ef52a82
--- /dev/null
+++ b/web/packages/base/components/utils/sx.ts
@@ -0,0 +1,25 @@
+import { type SxProps, type Theme } from "@mui/material";
+import { type SystemStyleObject } from "@mui/system";
+
+/**
+ * Wrapper over Array.isArray that retains the TypeScript type for SxProps when
+ * trying to spread them.
+ *
+ * The recommended pattern to use sx props in our own component (whilst
+ * forwarding them to the underyling MUI component) is to:
+ *
+ * ...(Array.isArray(sx) ? sx : [sx])
+ *
+ * However, currently (as of MUI v6), this runs afoul of the
+ * 'no-unsafe-assignment' eslint rule. This function provides a workaround, and
+ * can be used as a drop-in replacement of Array.isArray in the above pattern.
+ *
+ * Ref: https://github.com/mui/material-ui/issues/37730
+ */
+export const isSxArray = (
+ sx: SxProps<Theme>,
+): sx is readonly (
+ | boolean
+ | SystemStyleObject<Theme>
+ | ((theme: Theme) => SystemStyleObject<Theme>)
+)[] => Array.isArray(sx);