Ver Fonte

More propTypes.

Renée Kooi há 7 anos atrás
pai
commit
8829aeca6e

+ 3 - 14
src/react/Dashboard.js

@@ -1,7 +1,6 @@
 const React = require('react')
 const React = require('react')
-const PropTypes = require('prop-types')
-const UppyCore = require('../core/Core').Uppy
 const DashboardPlugin = require('../plugins/Dashboard')
 const DashboardPlugin = require('../plugins/Dashboard')
+const basePropTypes = require('./propTypes').dashboard
 
 
 const h = React.createElement
 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 = {
 Dashboard.defaultProps = {
   inline: true
   inline: true
 }
 }

+ 4 - 12
src/react/DashboardModal.js

@@ -1,7 +1,7 @@
 const React = require('react')
 const React = require('react')
 const PropTypes = require('prop-types')
 const PropTypes = require('prop-types')
-const UppyCore = require('../core/Core').Uppy
 const DashboardPlugin = require('../plugins/Dashboard')
 const DashboardPlugin = require('../plugins/Dashboard')
+const basePropTypes = require('./propTypes')
 
 
 const h = React.createElement
 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.
   // Only check this prop type in the browser.
   target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any,
   target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any,
   open: PropTypes.bool,
   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 = {
 DashboardModal.defaultProps = {
 }
 }

+ 3 - 4
src/react/DragDrop.js

@@ -1,7 +1,6 @@
 const React = require('react')
 const React = require('react')
-const PropTypes = require('prop-types')
-const UppyCore = require('../core').Uppy
 const DragDropPlugin = require('../plugins/DragDrop')
 const DragDropPlugin = require('../plugins/DragDrop')
+const propTypes = require('./propTypes')
 
 
 const h = React.createElement
 const h = React.createElement
 
 
@@ -41,8 +40,8 @@ class DragDrop extends React.Component {
 }
 }
 
 
 DragDrop.propTypes = {
 DragDrop.propTypes = {
-  uppy: PropTypes.instanceOf(UppyCore).isRequired,
-  locale: PropTypes.object
+  uppy: propTypes.uppy,
+  locale: propTypes.locale
 }
 }
 DragDrop.defaultProps = {
 DragDrop.defaultProps = {
 }
 }

+ 2 - 2
src/react/ProgressBar.js

@@ -1,7 +1,7 @@
 const React = require('react')
 const React = require('react')
 const PropTypes = require('prop-types')
 const PropTypes = require('prop-types')
-const UppyCore = require('../core').Uppy
 const ProgressBarPlugin = require('../plugins/ProgressBar')
 const ProgressBarPlugin = require('../plugins/ProgressBar')
+const uppyPropType = require('./propTypes').uppy
 
 
 const h = React.createElement
 const h = React.createElement
 
 
@@ -40,7 +40,7 @@ class ProgressBar extends React.Component {
 }
 }
 
 
 ProgressBar.propTypes = {
 ProgressBar.propTypes = {
-  uppy: PropTypes.instanceOf(UppyCore).isRequired,
+  uppy: uppyPropType,
   fixed: PropTypes.bool
   fixed: PropTypes.bool
 }
 }
 ProgressBar.defaultProps = {
 ProgressBar.defaultProps = {

+ 2 - 3
src/react/StatusBar.js

@@ -1,7 +1,6 @@
 const React = require('react')
 const React = require('react')
-const PropTypes = require('prop-types')
-const UppyCore = require('../core').Uppy
 const StatusBarPlugin = require('../plugins/StatusBar')
 const StatusBarPlugin = require('../plugins/StatusBar')
+const uppyPropType = require('./propTypes').uppy
 
 
 const h = React.createElement
 const h = React.createElement
 
 
@@ -41,7 +40,7 @@ class StatusBar extends React.Component {
 }
 }
 
 
 StatusBar.propTypes = {
 StatusBar.propTypes = {
-  uppy: PropTypes.instanceOf(UppyCore).isRequired
+  uppy: uppyPropType
 }
 }
 StatusBar.defaultProps = {
 StatusBar.defaultProps = {
 }
 }

+ 2 - 2
src/react/Wrapper.js

@@ -1,6 +1,6 @@
 const React = require('react')
 const React = require('react')
 const PropTypes = require('prop-types')
 const PropTypes = require('prop-types')
-const UppyCore = require('../core').Uppy
+const uppyPropType = require('./propTypes').uppy
 
 
 const h = React.createElement
 const h = React.createElement
 
 
@@ -35,7 +35,7 @@ class UppyWrapper extends React.Component {
 }
 }
 
 
 UppyWrapper.propTypes = {
 UppyWrapper.propTypes = {
-  uppy: PropTypes.instanceOf(UppyCore).isRequired,
+  uppy: uppyPropType,
   plugin: PropTypes.string.isRequired
   plugin: PropTypes.string.isRequired
 }
 }
 
 

+ 41 - 0
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
+}