Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c455b38

Browse files
committed
emotion: FileUpload
1 parent 8ef2a58 commit c455b38

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

site/src/components/FileUpload/FileUpload.tsx

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { makeStyles } from "@mui/styles";
21
import { Stack } from "components/Stack/Stack";
3-
import { FC, DragEvent, useRef, ReactNode } from "react";
2+
import { type FC, type DragEvent, useRef, type ReactNode } from "react";
43
import UploadIcon from "@mui/icons-material/CloudUploadOutlined";
54
import { useClickable } from "hooks/useClickable";
65
import CircularProgress from "@mui/material/CircularProgress";
7-
import { combineClasses } from "utils/combineClasses";
86
import IconButton from "@mui/material/IconButton";
97
import RemoveIcon from "@mui/icons-material/DeleteOutline";
108
import FileIcon from "@mui/icons-material/FolderOutlined";
9+
import { css, type Interpolation, type Theme } from "@emotion/react";
1110

1211
const useFileDrop = (
1312
callback: (file: File) => void,
@@ -62,7 +61,6 @@ export const FileUpload: FC<FileUploadProps> = ({
6261
extension,
6362
fileTypeRequired,
6463
}) => {
65-
const styles = useStyles();
6664
const inputRef = useRef<HTMLInputElement>(null);
6765
const tarDrop = useFileDrop(onUpload, fileTypeRequired);
6866

@@ -75,7 +73,7 @@ export const FileUpload: FC<FileUploadProps> = ({
7573
if (!isUploading && file) {
7674
return (
7775
<Stack
78-
className={styles.file}
76+
css={styles.file}
7977
direction="row"
8078
justifyContent="space-between"
8179
alignItems="center"
@@ -95,23 +93,20 @@ export const FileUpload: FC<FileUploadProps> = ({
9593
return (
9694
<>
9795
<div
98-
className={combineClasses({
99-
[styles.root]: true,
100-
[styles.disabled]: isUploading,
101-
})}
96+
css={[styles.root, isUploading && styles.disabled]}
10297
{...clickable}
10398
{...tarDrop}
10499
>
105100
<Stack alignItems="center" spacing={1}>
106101
{isUploading ? (
107102
<CircularProgress size={32} />
108103
) : (
109-
<UploadIcon className={styles.icon} />
104+
<UploadIcon css={styles.icon} />
110105
)}
111106

112107
<Stack alignItems="center" spacing={0.5}>
113-
<span className={styles.title}>{title}</span>
114-
<span className={styles.description}>{description}</span>
108+
<span css={styles.title}>{title}</span>
109+
<span css={styles.description}>{description}</span>
115110
</Stack>
116111
</Stack>
117112
</div>
@@ -120,7 +115,7 @@ export const FileUpload: FC<FileUploadProps> = ({
120115
type="file"
121116
data-testid="file-upload"
122117
ref={inputRef}
123-
className={styles.input}
118+
css={styles.input}
124119
accept={extension}
125120
onChange={(event) => {
126121
const file = event.currentTarget.files?.[0];
@@ -133,48 +128,48 @@ export const FileUpload: FC<FileUploadProps> = ({
133128
);
134129
};
135130

136-
const useStyles = makeStyles((theme) => ({
137-
root: {
138-
display: "flex",
139-
alignItems: "center",
140-
justifyContent: "center",
141-
borderRadius: theme.shape.borderRadius,
142-
border: `2px dashed ${theme.palette.divider}`,
143-
padding: theme.spacing(6),
144-
cursor: "pointer",
145-
146-
"&:hover": {
147-
backgroundColor: theme.palette.background.paper,
148-
},
149-
},
131+
const styles = {
132+
root: (theme) => css`
133+
display: flex;
134+
align-items: center;
135+
justify-content: center;
136+
border-radius: ${theme.shape.borderRadius};
137+
border: 2px dashed ${theme.palette.divider};
138+
padding: ${theme.spacing(6)};
139+
cursor: pointer;
140+
141+
&:hover {
142+
background-color: ${theme.palette.background.paper};
143+
}
144+
`,
150145

151146
disabled: {
152147
pointerEvents: "none",
153148
opacity: 0.75,
154149
},
155150

156-
icon: {
151+
icon: (theme) => ({
157152
fontSize: theme.spacing(8),
158-
},
153+
}),
159154

160-
title: {
155+
title: (theme) => ({
161156
fontSize: theme.spacing(2),
162-
},
157+
}),
163158

164-
description: {
159+
description: (theme) => ({
165160
color: theme.palette.text.secondary,
166161
textAlign: "center",
167162
maxWidth: theme.spacing(50),
168-
},
163+
}),
169164

170165
input: {
171166
display: "none",
172167
},
173168

174-
file: {
169+
file: (theme) => ({
175170
borderRadius: theme.shape.borderRadius,
176171
border: `1px solid ${theme.palette.divider}`,
177172
padding: theme.spacing(2),
178173
background: theme.palette.background.paper,
179-
},
180-
}));
174+
}),
175+
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)