feat(custom-dropzone): customize react-dropzone
This commit is contained in:
39
src/components/custom-dropzone.js
Normal file
39
src/components/custom-dropzone.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import React, { useCallback } from "react";
|
||||||
|
import { useDropzone } from "react-dropzone";
|
||||||
|
import styled from "@emotion/styled";
|
||||||
|
import { Text } from ".";
|
||||||
|
|
||||||
|
const Container = styled.div`
|
||||||
|
border: 1px solid var(--color-dark);
|
||||||
|
margin-bottom: var(--spacing-y-sm);
|
||||||
|
padding: var(--spacing-y-lg) var(--spacing-x-sm);
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: 0;
|
||||||
|
box-shadow: 0 0 0 2px var(--color-dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus:not(:focus-visible) {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default function CustomDropzone({ name, files, setFiles, ...other }) {
|
||||||
|
const onDrop = useCallback(acceptedFiles => {
|
||||||
|
setFiles(acceptedFiles[0]);
|
||||||
|
}, []);
|
||||||
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
|
||||||
|
return (
|
||||||
|
<Container {...getRootProps()} {...other}>
|
||||||
|
<input name={name} {...getInputProps()} />
|
||||||
|
{isDragActive ? (
|
||||||
|
<Text noMargin>Drop the images here</Text>
|
||||||
|
) : (
|
||||||
|
<Text noMargin>
|
||||||
|
Drop your images here, or click to select the files
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
export { default as Button } from "./button";
|
export { default as Button } from "./button";
|
||||||
export { default as Card } from "./card";
|
export { default as Card } from "./card";
|
||||||
export { default as Content } from "./content";
|
export { default as Content } from "./content";
|
||||||
|
export { default as CustomDropzone } from "./custom-dropzone";
|
||||||
export { default as CustomGallery } from "./custom-gallery";
|
export { default as CustomGallery } from "./custom-gallery";
|
||||||
export { default as CustomSlick } from "./custom-slick";
|
export { default as CustomSlick } from "./custom-slick";
|
||||||
export { default as Footer } from "./footer";
|
export { default as Footer } from "./footer";
|
||||||
@@ -20,7 +21,7 @@ export { default as NavLink } from "./nav-link";
|
|||||||
export { default as Nav } from "./nav";
|
export { default as Nav } from "./nav";
|
||||||
export { default as ReviewSummary } from "./review-summary";
|
export { default as ReviewSummary } from "./review-summary";
|
||||||
export { default as Section } from "./section";
|
export { default as Section } from "./section";
|
||||||
export { default as Select } from './select';
|
export { default as Select } from "./select";
|
||||||
export { default as Table } from "./table";
|
export { default as Table } from "./table";
|
||||||
export { default as Text } from "./text";
|
export { default as Text } from "./text";
|
||||||
export { default as Tile } from "./tile";
|
export { default as Tile } from "./tile";
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { graphql } from "gatsby";
|
import { graphql } from "gatsby";
|
||||||
import { Marker } from "google-maps-react";
|
import { Marker } from "google-maps-react";
|
||||||
import { useDropzone } from "react-dropzone";
|
|
||||||
import Layout from "../layout";
|
import Layout from "../layout";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
CustomDropzone,
|
||||||
Grid,
|
Grid,
|
||||||
Header,
|
Header,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -33,12 +33,9 @@ const encode = data => {
|
|||||||
|
|
||||||
export default function Index({ data }) {
|
export default function Index({ data }) {
|
||||||
const [submitted, setSubmitted] = useState();
|
const [submitted, setSubmitted] = useState();
|
||||||
|
const [uploadFiles, setUploadFiles] = useState();
|
||||||
const [files, setFiles] = useState({});
|
const [files, setFiles] = useState({});
|
||||||
|
|
||||||
const onDrop = useCallback(acceptedFiles => {
|
|
||||||
setFiles(acceptedFiles[0]);
|
|
||||||
}, []);
|
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
|
|
||||||
const handleSubmit = e => {
|
const handleSubmit = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const body = encode({
|
const body = encode({
|
||||||
@@ -196,6 +193,7 @@ export default function Index({ data }) {
|
|||||||
id="contact-start"
|
id="contact-start"
|
||||||
name="start"
|
name="start"
|
||||||
options={[
|
options={[
|
||||||
|
{ value: "", label: "" },
|
||||||
{ value: "urgently", label: "Urgently" },
|
{ value: "urgently", label: "Urgently" },
|
||||||
{ value: "1week", label: "Within 1 week" },
|
{ value: "1week", label: "Within 1 week" },
|
||||||
{ value: "2weeks", label: "Within 2 weeks" },
|
{ value: "2weeks", label: "Within 2 weeks" },
|
||||||
@@ -211,6 +209,7 @@ export default function Index({ data }) {
|
|||||||
id="contact-stage"
|
id="contact-stage"
|
||||||
name="stage"
|
name="stage"
|
||||||
options={[
|
options={[
|
||||||
|
{ value: "", label: "" },
|
||||||
{ value: "ready", label: "I'm ready to hire" },
|
{ value: "ready", label: "I'm ready to hire" },
|
||||||
{
|
{
|
||||||
value: "budgeting",
|
value: "budgeting",
|
||||||
@@ -229,6 +228,7 @@ export default function Index({ data }) {
|
|||||||
id="contact-status"
|
id="contact-status"
|
||||||
name="status"
|
name="status"
|
||||||
options={[
|
options={[
|
||||||
|
{ value: "", label: "" },
|
||||||
{ value: "owner", label: "I own the property" },
|
{ value: "owner", label: "I own the property" },
|
||||||
{ value: "landlord", label: "I am the landlord" },
|
{ value: "landlord", label: "I am the landlord" },
|
||||||
{ value: "tenant", label: "I am a tenant" },
|
{ value: "tenant", label: "I am a tenant" },
|
||||||
@@ -239,17 +239,21 @@ export default function Index({ data }) {
|
|||||||
Describe what needs to be done
|
Describe what needs to be done
|
||||||
</Label>
|
</Label>
|
||||||
<InputText id="contact-message" name="message" textArea />
|
<InputText id="contact-message" name="message" textArea />
|
||||||
<div {...getRootProps()}>
|
<Button
|
||||||
<input name="files" {...getInputProps()} />
|
style={{ display: uploadFiles ? "none" : "inline-block" }}
|
||||||
{isDragActive ? (
|
onClick={() => setUploadFiles(true)}
|
||||||
<Text>Drop the images here</Text>
|
>
|
||||||
) : (
|
Upload images
|
||||||
<Text>
|
</Button>
|
||||||
Drop your images here, or click to select the files
|
<CustomDropzone
|
||||||
</Text>
|
style={{ display: uploadFiles ? "block" : "none" }}
|
||||||
)}
|
name="files"
|
||||||
</div>
|
files={files}
|
||||||
<Button type="submit">Submit</Button>
|
setFiles={setFiles}
|
||||||
|
/>
|
||||||
|
<Button type="submit" float="right">
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user