Skip to content

Commit 0f69549

Browse files
committed
emotion: FileTreeView
1 parent 0b1874e commit 0f69549

File tree

1 file changed

+50
-60
lines changed

1 file changed

+50
-60
lines changed

site/src/pages/TemplateVersionEditorPage/FileTreeView.tsx

Lines changed: 50 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { makeStyles } from "@mui/styles";
21
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
32
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
43
import TreeView from "@mui/lab/TreeView";
54
import TreeItem from "@mui/lab/TreeItem";
65
import Menu from "@mui/material/Menu";
76
import MenuItem from "@mui/material/MenuItem";
8-
import { CSSProperties, FC, useState } from "react";
7+
import { type CSSProperties, type FC, useState } from "react";
8+
import { css } from "@emotion/react";
99
import { FileTree } from "utils/filetree";
1010
import { DockerIcon } from "components/Icons/DockerIcon";
1111
import { colors } from "theme/colors";
@@ -35,7 +35,6 @@ export const FileTreeView: FC<{
3535
fileTree: FileTree;
3636
activePath?: string;
3737
}> = ({ fileTree, activePath, onDelete, onRename, onSelect }) => {
38-
const styles = useStyles();
3938
const [contextMenu, setContextMenu] = useState<ContextMenu | undefined>();
4039

4140
const buildTreeItems = (
@@ -60,9 +59,54 @@ export const FileTreeView: FC<{
6059
nodeId={currentPath}
6160
key={currentPath}
6261
label={filename}
63-
className={`${styles.fileTreeItem} ${
64-
currentPath === activePath ? "active" : ""
65-
}`}
62+
css={(theme) => css`
63+
overflow: hidden;
64+
user-select: none;
65+
66+
&:focus:not(.active) > .MuiTreeItem-content {
67+
background: ${theme.palette.action.hover};
68+
color: ${theme.palette.text.primary};
69+
}
70+
71+
&:not(:focus):not(.active) > .MuiTreeItem-content:hover {
72+
background: ${theme.palette.action.hover};
73+
color: ${theme.palette.text.primary};
74+
}
75+
76+
& > .MuiTreeItem-content {
77+
padding: ${theme.spacing(0.25, 2)};
78+
color: ${theme.palette.text.secondary};
79+
80+
& svg {
81+
width: 16px;
82+
height: 16px;
83+
}
84+
85+
& > .muitreeitem-label {
86+
margin-left: 4px;
87+
font-size: 13px;
88+
color: inherit;
89+
}
90+
}
91+
92+
&.active {
93+
& > .MuiTreeItem-content {
94+
color: ${theme.palette.text.primary};
95+
background: ${colors.gray[13]};
96+
pointer-events: none;
97+
}
98+
}
99+
100+
& .MuiTreeItem-group {
101+
margin-left: 0;
102+
103+
// We need to find a better way to recursive padding here
104+
& .MuiTreeItem-content {
105+
padding-left: calc(var(--level) * ${theme.spacing(5)});
106+
}
107+
}
108+
`}
109+
className={currentPath === activePath ? "active" : ""}
66110
onClick={() => {
67111
onSelect(currentPath);
68112
}}
@@ -161,60 +205,6 @@ export const FileTreeView: FC<{
161205
);
162206
};
163207

164-
const useStyles = makeStyles((theme) => ({
165-
fileTreeItem: {
166-
overflow: "hidden",
167-
userSelect: "none",
168-
169-
"&:focus:not(.active) > .MuiTreeItem-content": {
170-
background: theme.palette.action.hover,
171-
color: theme.palette.text.primary,
172-
},
173-
174-
"&:not(:focus):not(.active) > .MuiTreeItem-content:hover": {
175-
background: theme.palette.action.hover,
176-
color: theme.palette.text.primary,
177-
},
178-
179-
"& > .MuiTreeItem-content": {
180-
padding: theme.spacing(0.25, 2),
181-
color: theme.palette.text.secondary,
182-
183-
"& svg": {
184-
width: 16,
185-
height: 16,
186-
},
187-
188-
"& > .MuiTreeItem-label": {
189-
marginLeft: 4,
190-
fontSize: 13,
191-
color: "inherit",
192-
},
193-
},
194-
195-
"&.active": {
196-
"& > .MuiTreeItem-content": {
197-
color: theme.palette.text.primary,
198-
background: colors.gray[13],
199-
pointerEvents: "none",
200-
},
201-
},
202-
203-
"& .MuiTreeItem-group": {
204-
marginLeft: 0,
205-
206-
// We need to find a better way to recursive padding here
207-
"& .MuiTreeItem-content": {
208-
paddingLeft: `calc(var(--level) * ${theme.spacing(5)})`,
209-
},
210-
},
211-
},
212-
editor: {
213-
flex: 1,
214-
},
215-
preview: {},
216-
}));
217-
218208
const FileTypeTerraform = () => (
219209
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="#813cf3">
220210
<title>file_type_terraform</title>

0 commit comments

Comments
 (0)