-
Notifications
You must be signed in to change notification settings - Fork 306
/
1b1.tsx
106 lines (104 loc) · 3.53 KB
/
1b1.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as React from 'react'
import ArrowBack from '@material-ui/icons/ArrowBack'
import { useDragAndDrop } from '../../utils/hooks/useDragAndDrop'
import { geti18nString } from '../../utils/i18n'
import { makeStyles, Paper, Button, Typography, Theme } from '@material-ui/core'
import { styled } from '@material-ui/styles'
import WelcomeContainer from './WelcomeContainer'
const RestoreBox = styled('div')(({ theme }) => ({
color: theme.palette.text.hint,
border: `2px dashed ${theme.palette.divider}`,
whiteSpace: 'pre-line',
minHeight: 160 - theme.spacing(8),
maxWidth: 300,
borderRadius: theme.shape.borderRadius,
display: 'inline-flex',
flexDirection: 'column',
justifyContent: 'center',
textAlign: 'center',
cursor: 'pointer',
padding: theme.spacing(4),
transition: '0.4s',
}))
interface Props {
back(): void
restore(file: File): void
}
const useStyles = makeStyles(theme => ({
nav: {
paddingTop: theme.spacing(1),
paddingLeft: theme.spacing(1),
},
navButton: {
color: theme.palette.text.hint,
},
navButtonIcon: {
marginRight: theme.spacing(1),
},
main: {
padding: '2rem 2rem 1rem 2rem',
textAlign: 'center',
'& > *': {
marginBottom: theme.spacing(3),
},
},
button: {
minWidth: 180,
},
file: {
display: 'none',
},
restoreBox: {
width: '100%',
color: 'gray',
transition: '0.4s',
'&[data-active=true]': {
color: 'black',
},
},
}))
export default function Welcome({ back, restore }: Props) {
const classes = useStyles()
const ref = React.useRef<HTMLInputElement>(null)
const { dragEvents, fileReceiver, fileRef, dragStatus } = useDragAndDrop()
return (
<WelcomeContainer {...dragEvents}>
<nav className={classes.nav}>
<Button onClick={back} disableFocusRipple disableRipple className={classes.navButton}>
<ArrowBack className={classes.navButtonIcon} />
{geti18nString('back')}
</Button>
</nav>
<main className={classes.main}>
<Typography variant="h5">{geti18nString('welcome_1b_title')}</Typography>
<form>
<input
className={classes.file}
type="file"
accept="application/json"
ref={ref}
onChange={fileReceiver}
/>
<RestoreBox
className={classes.restoreBox}
data-active={dragStatus === 'drag-enter'}
onClick={() => ref.current && ref.current.click()}>
{dragStatus === 'drag-enter'
? geti18nString('welcome_1b_dragging')
: fileRef.current
? geti18nString('welcome_1b_file_selected', fileRef.current.name)
: geti18nString('welcome_1b_no_file_selected')}
</RestoreBox>
</form>
<Button
onClick={() => restore(fileRef.current!)}
disabled={!fileRef.current}
variant="contained"
color="primary"
className={classes.button}>
{geti18nString('restore')}
</Button>
</main>
</WelcomeContainer>
)
}