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: Badges
  • Loading branch information
aslilac committed Sep 29, 2023
commit af80a93d4d40e96c30736c6d86ac10c0aa3eb44f
181 changes: 74 additions & 107 deletions site/src/components/DeploySettingsLayout/Badges.tsx
Original file line number Diff line number Diff line change
@@ -1,104 +1,131 @@
import { makeStyles } from "@mui/styles";
import { Stack } from "components/Stack/Stack";
import { PropsWithChildren, FC } from "react";
import { MONOSPACE_FONT_FAMILY } from "theme/constants";
import { combineClasses } from "utils/combineClasses";
import type { PropsWithChildren, FC } from "react";
import Tooltip from "@mui/material/Tooltip";
import { type Interpolation, type Theme } from "@emotion/react";
import { Stack } from "components/Stack/Stack";

const styles = {
badge: (theme) => ({
fontSize: 10,
height: 24,
fontWeight: 600,
textTransform: "uppercase",
letterSpacing: "0.085em",
padding: theme.spacing(0, 1.5),
borderRadius: 9999,
display: "flex",
alignItems: "center",
width: "fit-content",
whiteSpace: "nowrap",
}),

enabledBadge: (theme) => ({
border: `1px solid ${theme.palette.success.light}`,
backgroundColor: theme.palette.success.dark,
}),
errorBadge: (theme) => ({
border: `1px solid ${theme.palette.error.light}`,
backgroundColor: theme.palette.error.dark,
}),
warnBadge: (theme) => ({
border: `1px solid ${theme.palette.warning.light}`,
backgroundColor: theme.palette.warning.dark,
}),
} satisfies Record<string, Interpolation<Theme>>;

export const EnabledBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.enabledBadge])}>
Enabled
</span>
);
return <span css={[styles.badge, styles.enabledBadge]}>Enabled</span>;
};

export const EntitledBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.enabledBadge])}>
Entitled
</span>
);
return <span css={[styles.badge, styles.enabledBadge]}>Entitled</span>;
};

export const HealthyBadge: FC<{ derpOnly: boolean }> = ({ derpOnly }) => {
const styles = useStyles();
let text = "Healthy";
if (derpOnly) {
text = "Healthy (DERP Only)";
}
interface HealthyBadge {
derpOnly: boolean;
}
export const HealthyBadge: FC<HealthyBadge> = (props) => {
const { derpOnly } = props;
return (
<span className={combineClasses([styles.badge, styles.enabledBadge])}>
{text}
<span css={[styles.badge, styles.enabledBadge]}>
{derpOnly ? "Healthy (DERP only)" : "Healthy"}
</span>
);
};

export const NotHealthyBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.errorBadge])}>
Unhealthy
</span>
);
return <span css={[styles.badge, styles.errorBadge]}>Unhealthy</span>;
};

export const NotRegisteredBadge: FC = () => {
const styles = useStyles();
return (
<Tooltip title="Workspace Proxy has never come online and needs to be started.">
<span className={combineClasses([styles.badge, styles.warnBadge])}>
Never Seen
</span>
<span css={[styles.badge, styles.warnBadge]}>Never seen</span>
</Tooltip>
);
};

export const NotReachableBadge: FC = () => {
const styles = useStyles();
return (
<Tooltip title="Workspace Proxy not responding to http(s) requests.">
<span className={combineClasses([styles.badge, styles.warnBadge])}>
Not Dialable
</span>
<span css={[styles.badge, styles.warnBadge]}>Not reachable</span>
</Tooltip>
);
};

export const DisabledBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.disabledBadge])}>
<span
css={[
styles.badge,
(theme) => ({
border: `1px solid ${theme.palette.divider}`,
backgroundColor: theme.palette.background.paper,
}),
]}
>
Disabled
</span>
);
};

export const EnterpriseBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.enterpriseBadge])}>
<span
css={[
styles.badge,
(theme) => ({
backgroundColor: theme.palette.info.dark,
border: `1px solid ${theme.palette.info.light}`,
}),
]}
>
Enterprise
</span>
);
};

export const AlphaBadge: FC = () => {
const styles = useStyles();
return (
<span className={combineClasses([styles.badge, styles.alphaBadge])}>
<span
css={[
styles.badge,
(theme) => ({
border: `1px solid ${theme.palette.error.light}`,
backgroundColor: theme.palette.error.dark,
}),
]}
>
Alpha
</span>
);
};

export const Badges: FC<PropsWithChildren> = ({ children }) => {
const styles = useStyles();
return (
<Stack
className={styles.badges}
css={(theme) => ({
margin: theme.spacing(0, 0, 2),
})}
direction="row"
alignItems="center"
spacing={1}
Expand All @@ -107,63 +134,3 @@ export const Badges: FC<PropsWithChildren> = ({ children }) => {
</Stack>
);
};

const useStyles = makeStyles((theme) => ({
badges: {
margin: theme.spacing(0, 0, 2),
},

badge: {
fontSize: 10,
height: 24,
fontWeight: 600,
textTransform: "uppercase",
letterSpacing: "0.085em",
padding: theme.spacing(0, 1.5),
borderRadius: 9999,
display: "flex",
alignItems: "center",
width: "fit-content",
whiteSpace: "nowrap",
},

enterpriseBadge: {
backgroundColor: theme.palette.info.dark,
border: `1px solid ${theme.palette.info.light}`,
},

alphaBadge: {
border: `1px solid ${theme.palette.error.light}`,
backgroundColor: theme.palette.error.dark,
},

versionBadge: {
border: `1px solid ${theme.palette.success.light}`,
backgroundColor: theme.palette.success.dark,
textTransform: "none",
color: "white",
fontFamily: MONOSPACE_FONT_FAMILY,
textDecoration: "none",
fontSize: 12,
},

enabledBadge: {
border: `1px solid ${theme.palette.success.light}`,
backgroundColor: theme.palette.success.dark,
},

errorBadge: {
border: `1px solid ${theme.palette.error.light}`,
backgroundColor: theme.palette.error.dark,
},

warnBadge: {
border: `1px solid ${theme.palette.warning.light}`,
backgroundColor: theme.palette.warning.dark,
},

disabledBadge: {
border: `1px solid ${theme.palette.divider}`,
backgroundColor: theme.palette.background.paper,
},
}));