More propTypes.

This commit is contained in:
Renée Kooi 2018-04-23 10:05:17 +02:00
parent b84b7c0a82
commit 8829aeca6e
No known key found for this signature in database
GPG key ID: 8CDD5F0BC448F040
7 changed files with 57 additions and 37 deletions

View file

@ -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
}

View file

@ -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 = {
}

View file

@ -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 = {
}

View file

@ -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 = {

View file

@ -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 = {
}

View file

@ -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
}

41
src/react/propTypes.js Normal file
View file

@ -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
}