Skip to content

refactor: start using emotion for styling #9909

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 17 commits into from
Sep 29, 2023
Prev Previous commit
Next Next commit
Merge branch 'main' into emotional-damage
  • Loading branch information
aslilac committed Sep 29, 2023
commit f8f9ed2747256d6575bf7419f2bf07ba19cf1898
74 changes: 44 additions & 30 deletions site/src/components/DeploySettingsLayout/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { useTheme } from "@mui/system";
import { DisabledBadge, EnabledBadge } from "./Badges";
import { css } from "@emotion/react";

export const OptionName: FC<PropsWithChildren> = ({ children }) => {
export const OptionName: FC<PropsWithChildren> = (props) => {
const { children } = props;

return (
<span
css={{
Expand All @@ -17,8 +19,10 @@ export const OptionName: FC<PropsWithChildren> = ({ children }) => {
);
};

export const OptionDescription: FC<PropsWithChildren> = ({ children }) => {
export const OptionDescription: FC<PropsWithChildren> = (props) => {
const { children } = props;
const theme = useTheme();

return (
<span
css={{
Expand All @@ -33,7 +37,12 @@ export const OptionDescription: FC<PropsWithChildren> = ({ children }) => {
);
};

export const OptionValue: FC<{ children?: unknown }> = ({ children }) => {
interface OptionValueProps {
children?: boolean | number | string | string[];
}

export const OptionValue: FC<OptionValueProps> = (props) => {
const { children } = props;
const theme = useTheme();

const optionStyles = css`
Expand All @@ -55,15 +64,15 @@ export const OptionValue: FC<{ children?: unknown }> = ({ children }) => {
return <span css={optionStyles}>{children}</span>;
}

if (!children || children.length < 1) {
return <span css={optionStyles}>Not set</span>;
}

if (typeof children === "string") {
return <span css={optionStyles}>{children}</span>;
}

if (Array.isArray(children)) {
if (children.length === 0) {
return <span css={optionStyles}>Not set</span>;
}

return (
<ul
css={{
Expand All @@ -84,21 +93,24 @@ export const OptionValue: FC<{ children?: unknown }> = ({ children }) => {
);
}

if (children === "") {
return <span css={optionStyles}>Not set</span>;
}

return <span css={optionStyles}>{JSON.stringify(children)}</span>;
};

interface OptionConfigProps extends BoxProps {
source?: boolean;
}

// OptionalConfig takes a source bool to indicate if the Option is the source of the configured value.
export const OptionConfig = ({
source,
...boxProps
}: { source?: boolean } & BoxProps) => {
export const OptionConfig = (props: OptionConfigProps) => {
const { source, sx, ...attrs } = props;
const theme = useTheme();
const borderColor = source
? theme.palette.primary.main
: theme.palette.divider;

return (
<Box
{...boxProps}
{...attrs}
sx={{
fontSize: 13,
fontFamily: MONOSPACE_FONT_FAMILY,
Expand All @@ -111,35 +123,37 @@ export const OptionConfig = ({
alignItems: "center",
borderRadius: 0.25,
padding: (theme) => theme.spacing(0, 1),
border: (theme) =>
`1px solid ${
source ? theme.palette.primary.main : theme.palette.divider
}`,
"& .option-config-flag": {
backgroundColor: source ? "rgba(0, 0, 0, 0.7)" : undefined,
},
...boxProps.sx,
border: `1px solid ${borderColor}`,
...sx,
}}
/>
);
};

export const OptionConfigFlag = (props: BoxProps) => {
interface OptionConfigFlagProps extends BoxProps {
source?: boolean;
}

export const OptionConfigFlag = (props: OptionConfigFlagProps) => {
const { children, source, sx, ...attrs } = props;

return (
<Box
{...props}
className={combineClasses([props.className, "option-config-flag"])}
{...attrs}
sx={{
fontSize: 10,
fontWeight: 600,
margin: (theme) => theme.spacing(0, 0.75, 0, -0.5),
display: "block",
backgroundColor: (theme) => theme.palette.divider,
backgroundColor: (theme) =>
source ? "rgba(0, 0, 0, 0.7)" : theme.palette.divider,
lineHeight: 1,
padding: (theme) => theme.spacing(0.25, 0.5),
borderRadius: 0.25,
...props.sx,
...sx,
}}
/>
>
{children}
</Box>
);
};
You are viewing a condensed version of this merge commit. You can view the full changes here.