Projekt

Obecné

Profil

Stáhnout (3.2 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Button, Link, Stack, Typography } from '@mui/material'
2
import { Fragment, FunctionComponent } from 'react'
3
import AttachmentIcon from '@mui/icons-material/Attachment'
4
import DeleteIcon from '@mui/icons-material/Delete'
5
import SendIcon from '@mui/icons-material/Send'
6

    
7
export interface SingleFileSelectionFormProps {
8
    filename?: string
9
    onFileSelected: (event: any) => void
10
    formik: any
11
    onClearSelectedFile: () => void
12
}
13

    
14
const SingleFileSelectionForm: FunctionComponent<
15
    SingleFileSelectionFormProps
16
> = ({ filename, onFileSelected, formik, onClearSelectedFile }) => {
17
    return (
18
        <form onSubmit={formik.handleSubmit}>
19
            {!filename ? (
20
                <Fragment>
21
                    <Stack
22
                        direction="row"
23
                        justifyContent="flex-end"
24
                        alignItems="center"
25
                    >
26
                        <Button
27
                            variant="contained"
28
                            color="primary"
29
                            component="label"
30
                            // size="small"
31
                            startIcon={<AttachmentIcon />}
32
                        >
33
                            Select File
34
                            <input
35
                                id="file"
36
                                name="file"
37
                                type="file"
38
                                hidden
39
                                onChange={onFileSelected}
40
                            />
41
                        </Button>
42
                    </Stack>
43
                </Fragment>
44
            ) : (
45
                <Fragment>
46
                    <Stack direction="row" spacing={1}>
47
                        <Typography variant="body1">Selected File: </Typography>
48
                        <Typography
49
                            sx={{
50
                                textOverflow: 'ellipsis',
51
                                overflow: 'hidden',
52
                            }}
53
                            component={Link}
54
                        >
55
                            {filename}
56
                        </Typography>
57
                    </Stack>
58
                    <Stack
59
                        direction="row"
60
                        justifyContent="flex-end"
61
                        alignItems="center"
62
                        spacing={2}
63
                        sx={{ mt: 2 }}
64
                    >
65
                        <Button
66
                            // sx={{ mb: 2, mt: 1 }}
67
                            variant="contained"
68
                            size="small"
69
                            endIcon={<DeleteIcon />}
70
                            onClick={onClearSelectedFile}
71
                        >
72
                            Remove Selection
73
                        </Button>
74
                        <Button
75
                            size="small"
76
                            type="submit"
77
                            variant="contained"
78
                            startIcon={<SendIcon />}
79
                        >
80
                            Submit
81
                        </Button>
82
                    </Stack>
83
                </Fragment>
84
            )}
85
        </form>
86
    )
87
}
88

    
89
export default SingleFileSelectionForm
(5-5/6)