Last active
June 16, 2019 17:57
-
-
Save jsmanifest/b820f9c101ae399b59b3dc9049e3b6ec to your computer and use it in GitHub Desktop.
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', | |
} | |
} | |
return ( | |
<div className="cursor-pointer" onClick={triggerInput}> | |
<input | |
style={hiddenInputStyle} | |
ref={inputRef} | |
type="file" | |
accept="image/*" | |
multiple | |
onChange={onChange} | |
/> | |
<div className="uploader">{children}</div> | |
</div> | |
) | |
} | |
export default FileUploader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment