-
Notifications
You must be signed in to change notification settings - Fork 3
/
UploaderHeader.tsx
84 lines (81 loc) · 1.97 KB
/
UploaderHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
Box,
IconButton,
Stack,
Typography,
TypographyProps
} from "@mui/material";
import DeleteIcon from "@mui/icons-material/Delete";
import React from "react";
import { UploaderHeaderProps } from "./UploaderHeader.types";
/**
* Common header for all uploaders. Renders the title, subtext, and delete button if necessary.
* @param param0
* @returns
*/
export default function UploaderHeader({
disabled = false,
title,
titleVariant = "body",
subText,
required,
showDelete,
onDelete
}: UploaderHeaderProps) {
// title variant styling
let titleTypographyProps: TypographyProps = {};
if (titleVariant === "title") {
titleTypographyProps = {
fontSize: "20px",
fontWeight: 600
};
} else if (titleVariant === "subtitle") {
titleTypographyProps = {
fontSize: "14px",
fontWeight: 500
};
} else if (titleVariant === "body") {
titleTypographyProps = {
variant: "body1"
};
}
titleTypographyProps.sx = {
color: theme =>
disabled ? theme.palette.text.disabled : theme.palette.text.primary
};
return (
<Stack
gap={2}
flexDirection="row"
justifyContent="space-between"
alignItems="center"
mb={0.5}
minHeight="40px"
>
<Box>
<Typography {...titleTypographyProps}>
{title}
{required ? (
<Typography
color={theme => theme.palette.error.main}
component="span"
lineHeight="inherit"
sx={{
marginLeft: "4px",
verticalAlign: "text-top"
}}
>
*
</Typography>
) : null}
</Typography>
<Typography variant="caption">{subText}</Typography>
</Box>
{showDelete && !disabled ? (
<IconButton aria-label="DeleteIcon" onClick={onDelete} size="small">
<DeleteIcon color="error" fontSize="small" />
</IconButton>
) : null}
</Stack>
);
}