mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-25 19:23:55 +00:00
* Add @uppy/remote-sources preset/plugin * yarn.lock * Update packages/@uppy/remote-sources/README.md Co-authored-by: Merlijn Vos <merlijn@soverin.net> * Use div.uppy-Root for all plugins mounted in DOM; set dir in UIPlugin * remote uppy-Root from all UI plugins, as it will be set in UIPlugin automatically * Remove uppy-Root from file-input * Revert "Update packages/@uppy/remote-sources/README.md" This reverts commit3fd00028f7. * Revert "yarn.lock" This reverts commit04dd8c73de. * Revert "Add @uppy/remote-sources preset/plugin" This reverts commitac1f5df6b3. * Update packages/@uppy/core/src/UIPlugin.js Co-authored-by: Merlijn Vos <merlijn@soverin.net> * Update packages/@uppy/drag-drop/src/DragDrop.jsx Co-authored-by: Merlijn Vos <merlijn@soverin.net> * Update packages/@uppy/core/src/UIPlugin.js Co-authored-by: Renée Kooi <renee@kooi.me> * Revert "Update packages/@uppy/core/src/UIPlugin.js" This reverts commitf91af00d6b. * @uppy/react: add .uppy-Contrainer class name to wrapper div * @uppy/svelte: add .uppy-Contrainer class name to wrapper div Co-authored-by: Merlijn Vos <merlijn@soverin.net> Co-authored-by: Renée Kooi <renee@kooi.me>
89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
const React = require('react')
|
|
const PropTypes = require('prop-types')
|
|
const DashboardPlugin = require('@uppy/dashboard')
|
|
const basePropTypes = require('./propTypes').dashboard
|
|
const getHTMLProps = require('./getHTMLProps')
|
|
const nonHtmlPropsHaveChanged = require('./nonHtmlPropsHaveChanged')
|
|
|
|
const h = React.createElement
|
|
|
|
/**
|
|
* React Component that renders a Dashboard for an Uppy instance in a Modal
|
|
* dialog. Visibility of the Modal is toggled using the `open` prop.
|
|
*/
|
|
|
|
class DashboardModal extends React.Component {
|
|
componentDidMount () {
|
|
this.installPlugin()
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
if (prevProps.uppy !== this.props.uppy) {
|
|
this.uninstallPlugin(prevProps)
|
|
this.installPlugin()
|
|
} else if (nonHtmlPropsHaveChanged(this, prevProps)) {
|
|
const options = { ...this.props, onRequestCloseModal: this.props.onRequestClose }
|
|
delete options.uppy
|
|
this.plugin.setOptions(options)
|
|
}
|
|
if (prevProps.open && !this.props.open) {
|
|
this.plugin.closeModal()
|
|
} else if (!prevProps.open && this.props.open) {
|
|
this.plugin.openModal()
|
|
}
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
this.uninstallPlugin()
|
|
}
|
|
|
|
installPlugin () {
|
|
const { uppy } = this.props
|
|
const options = {
|
|
id: 'react:DashboardModal',
|
|
...this.props,
|
|
onRequestCloseModal: this.props.onRequestClose,
|
|
}
|
|
|
|
if (!options.target) {
|
|
options.target = this.container
|
|
}
|
|
|
|
delete options.uppy
|
|
uppy.use(DashboardPlugin, options)
|
|
|
|
this.plugin = uppy.getPlugin(options.id)
|
|
if (this.props.open) {
|
|
this.plugin.openModal()
|
|
}
|
|
}
|
|
|
|
uninstallPlugin (props = this.props) {
|
|
const { uppy } = props
|
|
|
|
uppy.removePlugin(this.plugin)
|
|
}
|
|
|
|
render () {
|
|
// TODO: stop exposing `validProps` as a public property and rename it to `htmlProps`
|
|
this.validProps = getHTMLProps(this.props)
|
|
return h('div', {
|
|
className: 'uppy-Container',
|
|
ref: (container) => {
|
|
this.container = container
|
|
},
|
|
...this.validProps,
|
|
})
|
|
}
|
|
}
|
|
|
|
DashboardModal.propTypes = {
|
|
target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any,
|
|
open: PropTypes.bool,
|
|
onRequestClose: PropTypes.func,
|
|
closeModalOnClickOutside: PropTypes.bool,
|
|
disablePageScrollWhenModalOpen: PropTypes.bool,
|
|
...basePropTypes,
|
|
}
|
|
|
|
module.exports = DashboardModal
|