diff --git a/src/react/Dashboard.js b/src/react/Dashboard.js index 68194a48f..00eb12124 100644 --- a/src/react/Dashboard.js +++ b/src/react/Dashboard.js @@ -1,7 +1,6 @@ const React = require('react') -const PropTypes = require('prop-types') -const UppyCore = require('../core/Core').Uppy const DashboardPlugin = require('../plugins/Dashboard') +const basePropTypes = require('./propTypes').dashboard const h = React.createElement @@ -39,18 +38,8 @@ class Dashboard extends React.Component { } } -Dashboard.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired, - plugins: PropTypes.arrayOf(PropTypes.string), - inline: PropTypes.bool, - width: PropTypes.number, - height: PropTypes.number, - semiTransparent: PropTypes.bool, - showProgressDetails: PropTypes.bool, - hideUploadButton: PropTypes.bool, - note: PropTypes.string, - locale: PropTypes.object -} +Dashboard.propTypes = basePropTypes + Dashboard.defaultProps = { inline: true } diff --git a/src/react/DashboardModal.js b/src/react/DashboardModal.js index 3be4c6aba..65c82821c 100644 --- a/src/react/DashboardModal.js +++ b/src/react/DashboardModal.js @@ -1,7 +1,7 @@ const React = require('react') const PropTypes = require('prop-types') -const UppyCore = require('../core/Core').Uppy const DashboardPlugin = require('../plugins/Dashboard') +const basePropTypes = require('./propTypes') const h = React.createElement @@ -57,20 +57,12 @@ class DashboardModal extends React.Component { } } -DashboardModal.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired, +DashboardModal.propTypes = Object.assign({ // Only check this prop type in the browser. target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any, open: PropTypes.bool, - onRequestClose: PropTypes.func, - plugins: PropTypes.arrayOf(PropTypes.string), - width: PropTypes.number, - height: PropTypes.number, - showProgressDetails: PropTypes.bool, - hideUploadButton: PropTypes.bool, - note: PropTypes.string, - locale: PropTypes.object -} + onRequestClose: PropTypes.func +}, basePropTypes) DashboardModal.defaultProps = { } diff --git a/src/react/DragDrop.js b/src/react/DragDrop.js index 9e1c0cb62..7b409f49f 100644 --- a/src/react/DragDrop.js +++ b/src/react/DragDrop.js @@ -1,7 +1,6 @@ const React = require('react') -const PropTypes = require('prop-types') -const UppyCore = require('../core').Uppy const DragDropPlugin = require('../plugins/DragDrop') +const propTypes = require('./propTypes') const h = React.createElement @@ -41,8 +40,8 @@ class DragDrop extends React.Component { } DragDrop.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired, - locale: PropTypes.object + uppy: propTypes.uppy, + locale: propTypes.locale } DragDrop.defaultProps = { } diff --git a/src/react/ProgressBar.js b/src/react/ProgressBar.js index 5829df319..58772604f 100644 --- a/src/react/ProgressBar.js +++ b/src/react/ProgressBar.js @@ -1,7 +1,7 @@ const React = require('react') const PropTypes = require('prop-types') -const UppyCore = require('../core').Uppy const ProgressBarPlugin = require('../plugins/ProgressBar') +const uppyPropType = require('./propTypes').uppy const h = React.createElement @@ -40,7 +40,7 @@ class ProgressBar extends React.Component { } ProgressBar.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired, + uppy: uppyPropType, fixed: PropTypes.bool } ProgressBar.defaultProps = { diff --git a/src/react/StatusBar.js b/src/react/StatusBar.js index 346171188..269bbd49f 100644 --- a/src/react/StatusBar.js +++ b/src/react/StatusBar.js @@ -1,7 +1,6 @@ const React = require('react') -const PropTypes = require('prop-types') -const UppyCore = require('../core').Uppy const StatusBarPlugin = require('../plugins/StatusBar') +const uppyPropType = require('./propTypes').uppy const h = React.createElement @@ -41,7 +40,7 @@ class StatusBar extends React.Component { } StatusBar.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired + uppy: uppyPropType } StatusBar.defaultProps = { } diff --git a/src/react/Wrapper.js b/src/react/Wrapper.js index 48f3c759c..39b490626 100644 --- a/src/react/Wrapper.js +++ b/src/react/Wrapper.js @@ -1,6 +1,6 @@ const React = require('react') const PropTypes = require('prop-types') -const UppyCore = require('../core').Uppy +const uppyPropType = require('./propTypes').uppy const h = React.createElement @@ -35,7 +35,7 @@ class UppyWrapper extends React.Component { } UppyWrapper.propTypes = { - uppy: PropTypes.instanceOf(UppyCore).isRequired, + uppy: uppyPropType, plugin: PropTypes.string.isRequired } diff --git a/src/react/propTypes.js b/src/react/propTypes.js new file mode 100644 index 000000000..bc6411ab0 --- /dev/null +++ b/src/react/propTypes.js @@ -0,0 +1,41 @@ +const PropTypes = require('prop-types') +const UppyCore = require('../core').Uppy + +// The `uppy` prop receives the Uppy core instance. +const uppy = PropTypes.instanceOf(UppyCore).isRequired + +// A list of plugins to mount inside this component. +const plugins = PropTypes.arrayOf(PropTypes.string) + +// Language strings for this component. +const locale = PropTypes.shape({ + strings: PropTypes.object, + pluralize: PropTypes.func +}) + +// List of meta fields for the editor in the Dashboard. +const metaField = PropTypes.shape({ + id: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + placeholder: PropTypes.string +}) +const metaFields = PropTypes.arrayOf(metaField) + +// Common props for dashboardy components (Dashboard and DashboardModal). +const dashboard = { + uppy, + inline: PropTypes.bool, + width: PropTypes.number, + height: PropTypes.number, + showProgressDetails: PropTypes.bool, + hideUploadButton: PropTypes.bool, + note: PropTypes.string, + plugins, + locale, + metaFields +} + +module.exports = { + uppy, + dashboard +}