Skip to content

Commit a613a0a

Browse files
refactor(site): improve settings option (#11489)
1 parent 6145086 commit a613a0a

File tree

2 files changed

+40
-47
lines changed

2 files changed

+40
-47
lines changed

site/src/components/DeploySettingsLayout/Option.tsx

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import CheckCircleOutlined from "@mui/icons-material/CheckCircleOutlined";
22
import { css, useTheme } from "@emotion/react";
3-
import type { HTMLAttributes, PropsWithChildren, FC } from "react";
3+
import { type HTMLAttributes, type PropsWithChildren, type FC } from "react";
44
import { MONOSPACE_FONT_FAMILY } from "theme/constants";
55
import { DisabledBadge, EnabledBadge } from "../Badges/Badges";
66

@@ -104,68 +104,61 @@ export const OptionValue: FC<OptionValueProps> = (props) => {
104104
return <span css={styles.option}>{JSON.stringify(value)}</span>;
105105
};
106106

107-
interface OptionConfigProps extends HTMLAttributes<HTMLDivElement> {
108-
source?: boolean;
109-
}
107+
type OptionConfigProps = HTMLAttributes<HTMLDivElement> & { isSource: boolean };
110108

111-
// OptionConfig takes a source bool to indicate if the Option is the source of the configured value.
112-
export const OptionConfig: FC<OptionConfigProps> = ({
113-
children,
114-
source,
115-
...attrs
116-
}) => {
109+
// OptionConfig takes a isSource bool to indicate if the Option is the source of the configured value.
110+
export const OptionConfig = ({ isSource, ...attrs }: OptionConfigProps) => {
117111
const theme = useTheme();
118-
const borderColor = source ? undefined : theme.palette.divider;
112+
const borderColor = isSource
113+
? theme.experimental.roles.active.outline
114+
: theme.palette.divider;
119115

120116
return (
121117
<div
122118
{...attrs}
123-
css={{
124-
fontSize: 13,
125-
fontFamily: MONOSPACE_FONT_FAMILY,
126-
fontWeight: 600,
127-
backgroundColor: source
128-
? theme.palette.primary.dark
129-
: theme.palette.background.paper,
130-
display: "inline-flex",
131-
alignItems: "center",
132-
borderRadius: 2,
133-
padding: "0 8px",
134-
border: `1px solid ${borderColor}`,
135-
}}
136-
>
137-
{children}
138-
</div>
119+
css={[
120+
{
121+
fontSize: 13,
122+
fontFamily: MONOSPACE_FONT_FAMILY,
123+
fontWeight: 600,
124+
backgroundColor: theme.palette.background.paper,
125+
display: "inline-flex",
126+
alignItems: "center",
127+
borderRadius: 4,
128+
padding: 6,
129+
lineHeight: 1,
130+
gap: 6,
131+
border: `1px solid ${borderColor}`,
132+
},
133+
isSource
134+
? {
135+
"& .OptionConfigFlag": {
136+
background: theme.experimental.roles.active.fill,
137+
},
138+
}
139+
: undefined,
140+
]}
141+
/>
139142
);
140143
};
141144

142-
interface OptionConfigFlagProps extends HTMLAttributes<HTMLDivElement> {
143-
source?: boolean;
144-
}
145-
146-
export const OptionConfigFlag: FC<OptionConfigFlagProps> = ({
147-
children,
148-
source,
149-
...attrs
150-
}) => {
145+
export const OptionConfigFlag = (props: HTMLAttributes<HTMLDivElement>) => {
151146
const theme = useTheme();
152147

153148
return (
154149
<div
155-
{...attrs}
150+
{...props}
151+
className="OptionConfigFlag"
156152
css={{
157153
fontSize: 10,
158154
fontWeight: 600,
159-
margin: "0 6px 0 -4px",
160155
display: "block",
161-
backgroundColor: source ? "rgba(0, 0, 0, 0.7)" : theme.palette.divider,
156+
backgroundColor: theme.palette.divider,
162157
lineHeight: 1,
163158
padding: "2px 4px",
164-
borderRadius: 2,
159+
borderRadius: 1,
165160
}}
166-
>
167-
{children}
168-
</div>
161+
/>
169162
);
170163
};
171164

site/src/components/DeploySettingsLayout/OptionsTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@ const OptionsTable: FC<OptionsTableProps> = ({ options, additionalValues }) => {
7070
}}
7171
>
7272
{option.flag && (
73-
<OptionConfig source={option.value_source === "flag"}>
73+
<OptionConfig isSource={option.value_source === "flag"}>
7474
<OptionConfigFlag>CLI</OptionConfigFlag>
7575
--{option.flag}
7676
</OptionConfig>
7777
)}
7878
{option.flag_shorthand && (
79-
<OptionConfig source={option.value_source === "flag"}>
79+
<OptionConfig isSource={option.value_source === "flag"}>
8080
<OptionConfigFlag>CLI</OptionConfigFlag>-
8181
{option.flag_shorthand}
8282
</OptionConfig>
8383
)}
8484
{option.env && (
85-
<OptionConfig source={option.value_source === "env"}>
85+
<OptionConfig isSource={option.value_source === "env"}>
8686
<OptionConfigFlag>ENV</OptionConfigFlag>
8787
{option.env}
8888
</OptionConfig>
8989
)}
9090
{option.yaml && (
91-
<OptionConfig source={option.value_source === "yaml"}>
91+
<OptionConfig isSource={option.value_source === "yaml"}>
9292
<OptionConfigFlag>YAML</OptionConfigFlag>
9393
{option.yaml}
9494
</OptionConfig>

0 commit comments

Comments
 (0)