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

Add documentation for FormFileUpload props #14661

Merged
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
52 changes: 52 additions & 0 deletions packages/components/src/form-file-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,55 @@ const MyFormFileUpload = () => (
</FormFileUpload>
);
```

## Props

The component accepts the following props. Props not included in this set will be passed to the `IconButton` component.

### accept

A string passed to `input` element that tells the browser which file types can be upload to the upload by the user use. e.g: `image/*,video/*`.
More information about this string is available in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers.

- Type: `String`
- Required: No


### children

Children are passed as children of `IconButton`.

- Type: `Boolean`
- Required: No

### icon

The icon to render. Supported values are: Dashicons (specified as strings), functions, WPComponent instances and `null`.

- Type: `String|Function|WPComponent|null`
- Required: No
- Default: `null`


### multiple

Whether to allow multiple selection of files or not.

- Type: `Boolean`
- Required: No
- Default: `false`

### onChange

Callback function passed directly to the `input` file element.

- Type: `Function`
- Required: Yes

### render

Optional callback function used to render the UI. If passed the component does not render any UI and calls this function to render it.
This function receives an object with the property `openFileDialog`. The property is a function that when called opens the browser window to upload files.

- Type: `Function`
- Required: No
10 changes: 9 additions & 1 deletion packages/components/src/form-file-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ class FormFileUpload extends Component {
}

render() {
const { children, multiple = false, accept, onChange, icon = 'upload', render, ...props } = this.props;
const {
accept,
children,
icon = 'upload',
multiple = false,
onChange,
render,
...props
} = this.props;

const ui = render ?
render( { openFileDialog: this.openFileDialog } ) : (
Expand Down