Skip to content

Commit

Permalink
FormFileUpload: Add Storybook stories (#38734)
Browse files Browse the repository at this point in the history
* FormFileUpload: Add Storybook stories

* Improve example in readme
  • Loading branch information
mirka authored Feb 14, 2022
1 parent 62cf9f7 commit 42c9108
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/components/src/form-file-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FormFileUpload } from '@wordpress/components';
const MyFormFileUpload = () => (
<FormFileUpload
accept="image/*"
onChange={ () => console.log( 'new image' ) }
onChange={ ( event ) => console.log( event.target.files ) }
>
Upload
</FormFileUpload>
Expand Down
51 changes: 51 additions & 0 deletions packages/components/src/form-file-upload/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* WordPress dependencies
*/
import { upload as uploadIcon } from '@wordpress/icons';

/**
* Internal dependencies
*/
import FormFileUpload from '../';

export default {
title: 'Components/FormFileUpload',
component: FormFileUpload,
};

export const Default = FormFileUpload.bind( {} );
Default.args = {
accept: '',
children: 'Select file',
multiple: false,
};

export const RestrictFileTypes = FormFileUpload.bind( {} );
RestrictFileTypes.args = {
...Default.args,
accept: 'image/*',
children: 'Select image',
multiple: false,
};

export const AllowMultipleFiles = FormFileUpload.bind( {} );
AllowMultipleFiles.args = {
...Default.args,
children: 'Select files',
multiple: true,
};

export const WithIcon = FormFileUpload.bind( {} );
WithIcon.args = {
...Default.args,
children: 'Upload',
icon: uploadIcon,
};

export const WithCustomRender = FormFileUpload.bind( {} );
WithCustomRender.args = {
...Default.args,
render: ( { openFileDialog } ) => (
<button onClick={ openFileDialog }>Custom Upload Button</button>
),
};

0 comments on commit 42c9108

Please sign in to comment.