uppy/examples/react-example/App.js
Renée Kooi b7415fe859
react: Allow overriding <DashboardModal /> target prop
This was always mounting the dashboard DOM element into the current
React container element, but that's not always the right thing to do,
for example if the container element is a small element with `overflow:
hidden` or some `position: relative` style.

This patch allows you to do `target={document.body}` and the like, so
you can mount the dashboard element anywhere.
2018-04-09 12:06:13 +02:00

99 lines
2.3 KiB
JavaScript

/* eslint-disable */
const React = require('react')
const Uppy = require('uppy/lib/core')
const Tus = require('uppy/lib/plugins/Tus')
const GoogleDrive = require('uppy/lib/plugins/GoogleDrive')
const { Dashboard, DashboardModal, DragDrop, ProgressBar } = require('uppy/lib/react')
module.exports = class App extends React.Component {
constructor (props) {
super(props)
this.state = {
showInlineDashboard: false,
open: false
}
this.handleModalClick = this.handleModalClick.bind(this)
}
componentWillMount () {
this.uppy = new Uppy({ autoProceed: false })
.use(Tus, { endpoint: 'https://master.tus.io/files/' })
.use(GoogleDrive, { host: 'https://server.uppy.io' })
.run()
this.uppy2 = new Uppy({ autoProceed: false })
.use(Tus, { endpoint: 'https://master.tus.io/files/' })
.run()
}
componentWillUnmount () {
this.uppy.close()
this.uppy2.close()
}
handleModalClick () {
this.setState({
open: !this.state.open
})
}
render () {
const { showInlineDashboard } = this.state
return (
<div>
<h1>React Examples</h1>
<h2>Inline Dashboard</h2>
<label>
<input
type="checkbox"
checked={showInlineDashboard}
onChange={(event) => {
this.setState({
showInlineDashboard: event.target.checked
})
}}
/>
Show Dashboard
</label>
{showInlineDashboard && (
<Dashboard
uppy={this.uppy}
plugins={['GoogleDrive']}
/>
)}
<h2>Modal Dashboard</h2>
<div>
<button onClick={this.handleModalClick}>
{this.state.open ? 'Close dashboard' : 'Open dashboard'}
</button>
<DashboardModal
uppy={this.uppy2}
open={this.state.open}
target={document.body}
onRequestClose={() => this.setState({ open: false })}
/>
</div>
<h2>Drag Drop Area</h2>
<DragDrop
uppy={this.uppy}
locale={{
strings: {
chooseFile: 'Boop a file',
orDragDrop: 'or yoink it here'
}
}}
/>
<h2>Progress Bar</h2>
<ProgressBar
uppy={this.uppy}
/>
</div>
)
}
}