Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update React component PropTypes #776

Merged
merged 3 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/react/Dashboard.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,7 +13,7 @@ class Dashboard extends React.Component {
componentDidMount () {
const uppy = this.props.uppy
const options = Object.assign(
{},
{ id: 'react:Dashboard' },
this.props,
{ target: this.container }
)
Expand All @@ -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
}
Expand Down
18 changes: 6 additions & 12 deletions src/react/DashboardModal.js
Original file line number Diff line number Diff line change
@@ -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').dashboard

const h = React.createElement

Expand All @@ -14,7 +14,7 @@ class DashboardModal extends React.Component {
componentDidMount () {
const uppy = this.props.uppy
const options = Object.assign(
{},
{ id: 'react:DashboardModal' },
this.props,
{
onRequestCloseModal: this.props.onRequestClose
Expand Down Expand Up @@ -57,20 +57,14 @@ 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
}
closeModalOnClickOutside: PropTypes.bool,
disablePageScrollWhenModalOpen: PropTypes.bool
}, basePropTypes)

DashboardModal.defaultProps = {
}
Expand Down
9 changes: 4 additions & 5 deletions src/react/DragDrop.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,7 +13,7 @@ class DragDrop extends React.Component {
componentDidMount () {
const uppy = this.props.uppy
const options = Object.assign(
{},
{ id: 'react:DragDrop' },
this.props,
{ target: this.container }
)
Expand All @@ -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 = {
}
Expand Down
9 changes: 5 additions & 4 deletions src/react/ProgressBar.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,7 +13,7 @@ class ProgressBar extends React.Component {
componentDidMount () {
const uppy = this.props.uppy
const options = Object.assign(
{},
{ id: 'react:ProgressBar' },
this.props,
{ target: this.container }
)
Expand All @@ -40,8 +40,9 @@ class ProgressBar extends React.Component {
}

ProgressBar.propTypes = {
uppy: PropTypes.instanceOf(UppyCore).isRequired,
fixed: PropTypes.bool
uppy: uppyPropType,
fixed: PropTypes.bool,
hideAfterFinish: PropTypes.bool
}
ProgressBar.defaultProps = {
}
Expand Down
8 changes: 5 additions & 3 deletions src/react/StatusBar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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

Expand All @@ -14,7 +14,7 @@ class StatusBar extends React.Component {
componentDidMount () {
const uppy = this.props.uppy
const options = Object.assign(
{},
{ id: 'react:StatusBar' },
this.props,
{ target: this.container }
)
Expand All @@ -41,7 +41,9 @@ class StatusBar extends React.Component {
}

StatusBar.propTypes = {
uppy: PropTypes.instanceOf(UppyCore).isRequired
uppy: uppyPropType,
hideAfterFinish: PropTypes.bool,
showProgressDetails: PropTypes.bool
}
StatusBar.defaultProps = {
}
Expand Down
4 changes: 2 additions & 2 deletions src/react/Wrapper.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -35,7 +35,7 @@ class UppyWrapper extends React.Component {
}

UppyWrapper.propTypes = {
uppy: PropTypes.instanceOf(UppyCore).isRequired,
uppy: uppyPropType,
plugin: PropTypes.string.isRequired
}

Expand Down
47 changes: 47 additions & 0 deletions src/react/propTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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,
plugins,
width: PropTypes.number,
height: PropTypes.number,
showProgressDetails: PropTypes.bool,
hideUploadButton: PropTypes.bool,
hideProgressAfterFinish: PropTypes.bool,
note: PropTypes.string,
metaFields,
proudlyDisplayPoweredByUppy: PropTypes.bool,
disableStatusBar: PropTypes.bool,
disableInformer: PropTypes.bool,
disableThumbnailGenerator: PropTypes.bool,
locale
}

module.exports = {
uppy,
locale,
dashboard
}