This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect, useReducer, useRef } from 'react' | |
// mock upload func | |
const api = { | |
uploadFile({ timeout = 550 }) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve() | |
}, timeout) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import useApp from './useApp' | |
import './styles.css' | |
const Input = (props) => ( | |
<input | |
type="file" | |
accept="image/*" | |
name="img-loader-input" | |
multiple |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
padding: 12px; | |
background: #171c1f; | |
color: #fff; | |
margin: 0; | |
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | |
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | |
sans-serif; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
const FileUploader = ({ children, triggerInput, inputRef, onChange }) => { | |
let hiddenInputStyle = {} | |
// If user passes in children, display children and hide input. | |
if (children) { | |
hiddenInputStyle = { | |
position: 'absolute', | |
top: '-9999px', | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const triggerInput = (e) => { | |
e.persist() | |
inputRef.current.click() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return { | |
...state, | |
onSubmit, | |
onChange, | |
triggerInput, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import idleSrc from './images/jade_input_bg.jpg' | |
const FileUploaderScreen = (props) => ( | |
<div className="uploader-input"> | |
<div | |
style={{ backgroundImage: `url("${idleSrc}")` }} | |
className="uploader-overlay" | |
/> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.form { | |
max-width: 400px; | |
margin: auto; | |
} | |
.uploader { | |
display: flex; | |
justify-content: center; | |
flex-direction: column; | |
width: 100%; | |
box-sizing: border-box; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import useApp from './useApp' | |
import FileUploader from './FileUploader' | |
import FileUploaderScreen from './FileUploaderScreen' | |
import './styles.css' | |
const App = ({ children }) => { | |
const inputRef = React.createRef() | |
const { | |
files, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialState = { | |
files: [], | |
pending: [], | |
next: null, | |
uploading: false, | |
uploaded: {}, | |
status: IDLE, | |
} |
OlderNewer