diff --git a/packages/components/src/modal/README.md b/packages/components/src/modal/README.md index 4a2aed1aab4238..88003b46261666 100644 --- a/packages/components/src/modal/README.md +++ b/packages/components/src/modal/README.md @@ -120,24 +120,28 @@ The following example shows you how to properly implement a modal. For the modal ```jsx import { Button, Modal } from '@wordpress/components'; -import { withState } from '@wordpress/compose'; - -const MyModal = withState( { - isOpen: false, -} )( ( { isOpen, setState } ) => ( -
- - { isOpen && ( - setState( { isOpen: false } ) }> - - - ) } -
-) ); +import { useState } from '@wordpress/compose'; + +const MyModal = () => { + const [ isOpen, setOpen ] = useState( false ); + const openModal = () => setOpen( true ); + const closeModal = () => setOpen( false ); + + return ( + <> + + { isOpen && ( + + + + ) } + + ) +} ``` ### Props diff --git a/packages/components/src/modal/stories/index.js b/packages/components/src/modal/stories/index.js new file mode 100644 index 00000000000000..28c01674b0a26d --- /dev/null +++ b/packages/components/src/modal/stories/index.js @@ -0,0 +1,64 @@ +/** + * External dependencies + */ +import { boolean, text } from '@storybook/addon-knobs'; + +/** + * Internal dependencies + */ +import Button from '../../button'; +import Dashicon from '../../dashicon'; +import Modal from '../'; + +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; + +export default { title: 'Modal', component: Modal }; + +const ModalExample = ( props ) => { + const [ isOpen, setOpen ] = useState( false ); + const openModal = () => setOpen( true ); + const closeModal = () => setOpen( false ); + + return ( + <> + + { isOpen && ( + + + + ) } + + ); +}; + +export const _default = () => { + const title = text( 'title', 'Title' ); + const icon = text( 'icon', '' ); + const isDismissible = boolean( 'isDismissible', true ); + const focusOnMount = boolean( 'focusOnMount', true ); + const shouldCloseOnEsc = boolean( 'shouldCloseOnEsc', true ); + const shouldCloseOnClickOutside = boolean( + 'shouldCloseOnClickOutside', + true + ); + + const iconComponent = icon ? : null; + + const modalProps = { + icon: iconComponent, + focusOnMount, + isDismissible, + shouldCloseOnEsc, + shouldCloseOnClickOutside, + title, + }; + + return ; +};