react/drag-drop: add a type test and document shared props (#2003)

* Update react-dragdrop.md

DragDrop component only accept `uppy` and `locale` props according to the type declared.
```
import { Uppy, Locale } from './CommonTypes';

export interface DragDropProps {
  uppy: Uppy;
  locale?: Locale;
}

/**
 * React component that renders an area in which files can be dropped to be
 * uploaded.
 */
declare const DragDrop: React.ComponentType<DragDropProps>;
export default DragDrop;```

* drag-drop: accept a number for width/height

* docs: add back dragdrop props

* docs: use the same option style as previously [skip ci]

Co-authored-by: Renée Kooi <renee@kooi.me>
This commit is contained in:
Andy Chong 2020-02-24 22:13:01 +08:00 committed by GitHub
parent 926cf8ee6d
commit 59bfaf0d20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View file

@ -7,8 +7,8 @@ declare module DragDrop {
target?: Uppy.PluginTarget
inputName?: string
allowMultipleFiles?: boolean
width?: string
height?: string
width?: string | number
height?: string | number
note?: string
locale?: DragDropLocale
}

View file

@ -18,3 +18,23 @@ function TestComponent() {
// inline option should be removed from proptypes because it is always overridden
// by the component
expectError(<components.Dashboard inline />)
{
const el = (
<components.DragDrop
width={200}
height={200}
note="Images up to 200×200px"
uppy={uppy}
locale={{
strings: {
// Text to show on the droppable area.
// `%{browse}` is replaced with a link that opens the system file selection dialog.
dropHereOr: "Drop here or %{browse}",
// Used as the label for the link that opens the system file selection dialog.
browse: "browse"
}
}}
/>
)
}

View file

@ -67,9 +67,21 @@ class MyComponent extends React.Component {
The `<DragDrop />` component supports all [DragDrop](/docs/drag-drop/) options as props.
```js
// assuming `this.uppy` contains an Uppy instance:
<DragDrop
width="100%"
height="100%"
note="Images up to 200×200px"
uppy={this.uppy}
locale={{
strings: {
// Text to show on the droppable area.
// `%{browse}` is replaced with a link that opens the system file selection dialog.
dropHereOr: "Drop here or %{browse}",
// Used as the label for the link that opens the system file selection dialog.
browse: "browse",
},
}}
/>
```