Skip to content

Commit

Permalink
docs: add doka integration
Browse files Browse the repository at this point in the history
- use flat badge for test status and gitpod
- show sidebar on docs site
- add favicon to docs site
  • Loading branch information
rolandjitsu committed Nov 8, 2020
1 parent bb42b94 commit c4cdc2a
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
@@ -0,0 +1 @@
open_collective: react-dropzone
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -3,11 +3,11 @@
# react-dropzone

[![npm](https://img.shields.io/npm/v/react-dropzone.svg?style=flat-square)](https://www.npmjs.com/package/react-dropzone)
![Build Status](https://github.com/react-dropzone/react-dropzone/workflows/Test/badge.svg)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/react-dropzone/react-dropzone/Test?label=tests&style=flat-square)](https://github.com/react-dropzone/react-dropzone/actions?query=workflow%3ATest)
[![codecov](https://img.shields.io/codecov/c/gh/react-dropzone/react-dropzone/master.svg?style=flat-square)](https://codecov.io/gh/react-dropzone/react-dropzone)
[![Open Collective](https://img.shields.io/opencollective/backers/react-dropzone.svg?style=flat-square)](#backers)
[![Open Collective](https://img.shields.io/opencollective/sponsors/react-dropzone.svg?style=flat-square)](#sponsors)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)

Simple React hook to create a HTML5-compliant drag'n'drop zone for files.

Expand Down Expand Up @@ -292,6 +292,11 @@ function mockData(files) {

More examples for this can be found in `react-dropzone`s own [test suites](https://github.com/react-dropzone/react-dropzone/blob/master/src/index.spec.js).

## Need image editing?

React Dropzone integrates perfectly with [Doka Image Editor](https://pqina.nl/doka/?ref=react-dropzone), creating a modern image editing experience. Doka supports crop aspect ratios, resizing, rotating, cropping, annotating, filtering, and much more.

Checkout the [integration example](https://react-dropzone.js.org/#!/Doka).

## Support

Expand Down
140 changes: 140 additions & 0 deletions examples/doka/README.md
@@ -0,0 +1,140 @@
If you'd like to integrate the dropzone with the [doka](https://pqina.nl/doka/?ref=react-dropzone) image editor, you just need to pass either of the selected images to the `create()` method exported by doka:

```jsx harmony
import React, {useEffect, useState} from 'react';
import {useDropzone} from 'react-dropzone';

import {create} from 'doka';

const thumbsContainer = {
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
marginTop: 16,
padding: 20
};

const thumb = {
position: "relative",
display: "inline-flex",
borderRadius: 2,
border: "1px solid #eaeaea",
marginBottom: 8,
marginRight: 8,
width: 100,
height: 100,
padding: 4,
boxSizing: "border-box"
};

const thumbInner = {
display: "flex",
minWidth: 0,
overflow: "hidden"
};

const img = {
display: "block",
width: "auto",
height: "100%"
};

const thumbButton = {
position: "absolute",
right: 10,
bottom: 10,
background: "rgba(0,0,0,.8)",
color: "#fff",
border: 0,
borderRadius: ".325em",
cursor: "pointer"
};

const editImage = (image, done) => {
const imageFile = image.doka ? image.doka.file : image;
const imageState = image.doka ? image.doka.data : {};
create({
// recreate previous state
...imageState,

// load original image file
src: imageFile,
outputData: true,

onconfirm: ({ file, data }) => {
Object.assign(file, {
doka: { file: imageFile, data }
});
done(file);
}
});
};

function Doka(props) {
const [files, setFiles] = useState([]);
const { getRootProps, getInputProps } = useDropzone({
accept: "image/*",
onDrop: (acceptedFiles) => {
setFiles(
acceptedFiles.map((file) =>
Object.assign(file, {
preview: URL.createObjectURL(file)
})
)
);
}
});

const thumbs = files.map((file, index) => (
<div style={thumb} key={file.name}>
<div style={thumbInner}>
<img src={file.preview} style={img} alt="" />
</div>
<button
style={thumbButton}
onClick={() =>
editImage(file, (output) => {
const updatedFiles = [...files];

// replace original image with new image
updatedFiles[index] = output;

// revoke preview URL for old image
if (file.preview) URL.revokeObjectURL(file.preview);

// set new preview URL
Object.assign(output, {
preview: URL.createObjectURL(output)
});

// update view
setFiles(updatedFiles);
})
}
>
edit
</button>
</div>
));

useEffect(
() => () => {
// Make sure to revoke the data uris to avoid memory leaks
files.forEach((file) => URL.revokeObjectURL(file.preview));
},
[files]
);

return (
<section className="container">
<div {...getRootProps({ className: "dropzone" })}>
<input {...getInputProps()} />
<p>Drag 'n' drop some files here, or click to select files</p>
</div>
<aside style={thumbsContainer}>{thumbs}</aside>
</section>
);
}

<Doka />
```
22 changes: 19 additions & 3 deletions styleguide.config.js
Expand Up @@ -6,18 +6,25 @@ const { createConfig, babel, css, devServer } = require('webpack-blocks')
module.exports = {
title: 'react-dropzone',
styleguideDir: path.join(__dirname, 'styleguide'),
template: {
favicon: 'https://github.com/react-dropzone/react-dropzone/raw/master/logo/logo.png'
},
webpackConfig: createConfig([babel(), css(), devServer({
disableHostCheck: true,
host: '0.0.0.0',
})]),
exampleMode: 'expand',
usageMode: 'expand',
showSidebar: false,
showSidebar: true,
serverPort: 8080,
moduleAliases: {
'react-dropzone': path.resolve(__dirname, './src')
'react-dropzone': path.resolve(__dirname, './src'),
'doka': path.resolve(__dirname, './vendor/doka/doka.esm.min.js')
},
require: [path.join(__dirname, 'examples/theme.css')],
require: [
path.join(__dirname, 'examples/theme.css'),
path.join(__dirname, 'vendor/doka/doka.min.css'),
],
sections: [
{
name: '',
Expand Down Expand Up @@ -69,6 +76,15 @@ module.exports = {
content: 'examples/plugins/README.md'
}
]
},
{
name: 'Integrations',
sections: [
{
name: 'Doka',
content: 'examples/doka/README.md'
}
]
}
]
}
10 changes: 10 additions & 0 deletions vendor/doka/doka.esm.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions vendor/doka/doka.min.css

Large diffs are not rendered by default.

0 comments on commit c4cdc2a

Please sign in to comment.