-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fully compatible with workaround interview
- Loading branch information
Showing
11 changed files
with
140 additions
and
6,815 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
yarn-error.log | ||
dist |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @flow | ||
|
||
import type { FileQuestion } from "../../material-survey-format.js.flow" | ||
import React, { useState } from "react" | ||
import QuestionContainer from "../QuestionContainer" | ||
import styled from "styled-components" | ||
import QuestionText from "../QuestionText" | ||
import useQuestionAnswer from "../../hooks/use-question-answer" | ||
import Dropzone from "react-dropzone/dist/es" | ||
|
||
const Box = styled.div` | ||
&& { | ||
border: 2px dashed #ccc; | ||
font-family: Roboto, sans-serif; | ||
text-align: center; | ||
padding-top: 20px; | ||
padding-bottom: 20px; | ||
cursor: pointer; | ||
} | ||
` | ||
|
||
export default ({ | ||
question, | ||
onChangeAnswer, | ||
onFileUpload | ||
}: { | ||
question: FileQuestion, | ||
onChangeAnswer: Function, | ||
onFileUpload: File => Promise<string> | ||
}) => { | ||
const [{ answer, error }, changeAnswer] = useQuestionAnswer( | ||
question, | ||
onChangeAnswer | ||
) | ||
const [uploading, changeUploadingState] = useState(false) | ||
return ( | ||
<QuestionContainer question={question} answered={answer !== undefined}> | ||
<Dropzone | ||
onDrop={async (file: File) => { | ||
const fileUrl = await onFileUpload(file) | ||
changeAnswer(fileUrl) | ||
}} | ||
> | ||
{({ getRootProps, getInputProps, isDragActive }) => ( | ||
<Box {...getRootProps()}> | ||
<input {...getInputProps()} /> | ||
{isDragActive ? ( | ||
<p>Drop file here...</p> | ||
) : ( | ||
<div> | ||
{answer ? ( | ||
<p>File successfully uploaded! Click to replace.</p> | ||
) : ( | ||
<p>Drag and drop a file here, or click to select file.</p> | ||
)} | ||
</div> | ||
)} | ||
</Box> | ||
)} | ||
</Dropzone> | ||
</QuestionContainer> | ||
) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @flow | ||
|
||
import React from "react" | ||
|
||
import { storiesOf } from "@storybook/react" | ||
import { action } from "@storybook/addon-actions" | ||
|
||
import FileQuestion from "./" | ||
|
||
storiesOf("FileQuestion", module).add("Basic", () => ( | ||
<FileQuestion | ||
onChangeAnswer={action("onChangeAnswer")} | ||
onFileUpload={async () => "http://url.com"} | ||
question={{ | ||
name: "file-example", | ||
title: "Upload your resume below", | ||
type: "file" | ||
}} | ||
/> | ||
)) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.