-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Modal, add story (#18083)
* Components: Modal, Add story This update adds a story for the Modal component. The story showcases an updated and enhanced example from the Modal README. It also includes a series of knobs to better demonstrate the Modal props. * Fix useState hook rendering in Modal story * Update example in Modal/README.md to use useState and Fragment * Render modal as closed by default * Refactor Fragment usage * Update README.md
- Loading branch information
Showing
2 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<Button isDefault onClick={ openModal }> | ||
Open Modal | ||
</Button> | ||
{ isOpen && ( | ||
<Modal { ...props } onRequestClose={ closeModal }> | ||
<Button isDefault onClick={ closeModal }> | ||
Close Modal | ||
</Button> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
}; | ||
|
||
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 ? <Dashicon icon={ icon } /> : null; | ||
|
||
const modalProps = { | ||
icon: iconComponent, | ||
focusOnMount, | ||
isDismissible, | ||
shouldCloseOnEsc, | ||
shouldCloseOnClickOutside, | ||
title, | ||
}; | ||
|
||
return <ModalExample { ...modalProps } />; | ||
}; |