Skip to content

refactor: remove usage of <Box> and sx #10702

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 8 commits into from
Dec 4, 2023
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
2 changes: 2 additions & 0 deletions site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ rules:
- name: "@mui/material/Typography"
message:
"You should use the native HTML elements as span, p, h1, h2, h3..."
- name: "@mui/material/Box"
message: "You should use a <div> instead"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion: I feel like the phrasing should push people to see if they can use a more semantic HTML element instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but I don't know how to word it in a way that fits in one line nicely. can definitely change it later!

no-unused-vars: "off"
"object-curly-spacing": "off"
react-hooks/exhaustive-deps: warn
Expand Down
1 change: 0 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@mui/icons-material": "5.14.0",
"@mui/lab": "5.0.0-alpha.129",
"@mui/material": "5.14.0",
"@mui/styles": "5.14.0",
"@mui/system": "5.14.0",
"@mui/utils": "5.14.11",
"@vitejs/plugin-react": "4.1.0",
Expand Down
109 changes: 1 addition & 108 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions site/src/@types/emotion.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { DefaultTheme as MuiTheme } from "@mui/system";
import type { NewTheme } from "theme/experimental";
import type { Theme as MuiTheme } from "@mui/material/styles";

declare module "@emotion/react" {
interface Theme extends MuiTheme {
experimental: NewTheme;
}
interface Theme extends MuiTheme {}
}
10 changes: 1 addition & 9 deletions site/src/@types/mui.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import type {
PaletteColor,
PaletteColorOptions,
Theme,
} from "@mui/material/styles";
import type { PaletteColor, PaletteColorOptions } from "@mui/material/styles";
import type { NewTheme } from "theme/experimental";

declare module "@mui/styles/defaultTheme" {
interface DefaultTheme extends Theme {}
}

declare module "@mui/material/styles" {
interface Theme {
experimental: NewTheme;
Expand Down
10 changes: 6 additions & 4 deletions site/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ export const ThemeProviders: FC<PropsWithChildren> = ({ children }) => {
);
};

export const AppProviders = ({
children,
queryClient = defaultQueryClient,
}: {
interface AppProvidersProps {
children: ReactNode;
queryClient?: QueryClient;
}

export const AppProviders: FC<AppProvidersProps> = ({
children,
queryClient = defaultQueryClient,
}) => {
return (
<HelmetProvider>
Expand Down
16 changes: 7 additions & 9 deletions site/src/components/ActiveUserChart/ActiveUserChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import Box from "@mui/material/Box";
import { Theme } from "@mui/material/styles";
import useTheme from "@mui/styles/useTheme";
import {
CategoryScale,
Chart as ChartJS,
Expand All @@ -22,7 +19,8 @@ import {
HelpTooltipText,
} from "components/HelpTooltip/HelpTooltip";
import dayjs from "dayjs";
import { FC } from "react";
import { useTheme } from "@emotion/react";
import { type FC } from "react";
import { Line } from "react-chartjs-2";
import annotationPlugin from "chartjs-plugin-annotation";

Expand All @@ -42,7 +40,7 @@ ChartJS.register(
const USER_LIMIT_DISPLAY_THRESHOLD = 60;

export interface ActiveUserChartProps {
data: { date: string; amount: number }[];
data: Array<{ date: string; amount: number }>;
interval: "day" | "week";
userLimit: number | undefined;
}
Expand All @@ -52,7 +50,7 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
interval,
userLimit,
}) => {
const theme: Theme = useTheme();
const theme = useTheme();

const labels = data.map((val) => dayjs(val.date).format("YYYY-MM-DD"));
const chartData = data.map((val) => val.amount);
Expand Down Expand Up @@ -137,9 +135,9 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
);
};

export const ActiveUsersTitle = () => {
export const ActiveUsersTitle: FC = () => {
return (
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<div css={{ display: "flex", alignItems: "center", gap: 8 }}>
Active Users
<HelpTooltip size="small">
<HelpTooltipTitle>How do we calculate active users?</HelpTooltipTitle>
Expand All @@ -148,7 +146,7 @@ export const ActiveUsersTitle = () => {
considered an active user. e.g. apps, web terminal, SSH
</HelpTooltipText>
</HelpTooltip>
</Box>
</div>
);
};

Expand Down
24 changes: 14 additions & 10 deletions site/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { useState, FC, ReactNode } from "react";
import {
useState,
type FC,
type ReactNode,
type PropsWithChildren,
} from "react";
import Collapse from "@mui/material/Collapse";
// eslint-disable-next-line no-restricted-imports -- It is the base component
import MuiAlert, { AlertProps as MuiAlertProps } from "@mui/material/Alert";
import MuiAlert, {
type AlertProps as MuiAlertProps,
} from "@mui/material/Alert";
import Button from "@mui/material/Button";
import Box from "@mui/material/Box";

export type AlertProps = MuiAlertProps & {
actions?: ReactNode;
Expand Down Expand Up @@ -32,7 +38,7 @@ export const Alert: FC<AlertProps> = ({
<Collapse in>
<MuiAlert
{...alertProps}
sx={{ textAlign: "left", ...alertProps.sx }}
css={{ textAlign: "left" }}
severity={severity}
action={
<>
Expand Down Expand Up @@ -62,15 +68,13 @@ export const Alert: FC<AlertProps> = ({
);
};

export const AlertDetail = ({ children }: { children: ReactNode }) => {
export const AlertDetail: FC<PropsWithChildren> = ({ children }) => {
return (
<Box
component="span"
color={(theme) => theme.palette.text.secondary}
fontSize={13}
<span
css={(theme) => ({ color: theme.palette.text.secondary, fontSize: 13 })}
data-chromatic="ignore"
>
{children}
</Box>
</span>
);
};
13 changes: 8 additions & 5 deletions site/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// This is the only place MuiAvatar can be used
// eslint-disable-next-line no-restricted-imports -- Read above
import MuiAvatar, { AvatarProps as MuiAvatarProps } from "@mui/material/Avatar";
import { FC, useId } from "react";
import MuiAvatar, {
type AvatarProps as MuiAvatarProps,
} from "@mui/material/Avatar";
import { type FC, useId } from "react";
import { css, type Interpolation, type Theme } from "@emotion/react";
import { Box } from "@mui/system";
import { visuallyHidden } from "@mui/utils";

export type AvatarProps = MuiAvatarProps & {
Expand Down Expand Up @@ -78,6 +79,8 @@ export const AvatarIcon: FC<AvatarIconProps> = ({ src, alt }) => {
const hookId = useId();
const avatarId = `${hookId}-avatar`;

// We use a `visuallyHidden` element instead of setting `alt` to avoid
// splatting the text out on the screen if the image fails to load.
return (
<>
<img
Expand All @@ -86,9 +89,9 @@ export const AvatarIcon: FC<AvatarIconProps> = ({ src, alt }) => {
css={{ maxWidth: "50%" }}
aria-labelledby={avatarId}
/>
<Box id={avatarId} sx={visuallyHidden}>
<div id={avatarId} css={{ ...visuallyHidden }}>
{alt}
</Box>
</div>
</>
);
};
Expand Down
Loading