Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active February 27, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorbenic/bb00f88270c87aa42099e9fb188cb2c1 to your computer and use it in GitHub Desktop.
Save igorbenic/bb00f88270c87aa42099e9fb188cb2c1 to your computer and use it in GitHub Desktop.
import { Button, Modal } from '@wordpress/components';
import { withState } from '@wordpress/compose';
const MyModal = withState( {
isOpen: false,
} )( ( { isOpen, setState } ) => (
<div>
<Button isDefault onClick={ () => setState( { isOpen: true } ) }>Open Modal</Button>
{ isOpen && (
<Modal
title="This is my modal"
onRequestClose={ () => setState( { isOpen: false } ) }>
<Button isDefault onClick={ () => setState( { isOpen: false } ) }>
My custom close button
</Button>
</Modal>
) }
</div>
) );
export function OptionsModal( { isModalActive, closeModal } ) {
if ( ! isModalActive ) {
return null;
}
return (
<Modal
className="edit-post-options-modal"
title={ <span className="edit-post-options-modal__title">{ __( 'Options' ) }</span> }
closeLabel={ __( 'Close' ) }
onRequestClose={ closeModal }
>
<Section title={ __( 'General' ) }>
<EnablePublishSidebarOption label={ __( 'Enable Pre-publish Checks' ) } />
<EnableTipsOption label={ __( 'Enable Tips' ) } />
</Section>
<Section title={ __( 'Document Panels' ) }>
<EnablePanelOption label={ __( 'Permalink' ) } panelName="post-link" />
<PostTaxonomies
taxonomyWrapper={ ( content, taxonomy ) => (
<EnablePanelOption
label={ get( taxonomy, [ 'labels', 'menu_name' ] ) }
panelName={ `taxonomy-panel-${ taxonomy.slug }` }
/>
) }
/>
<EnablePanelOption label={ __( 'Featured Image' ) } panelName="featured-image" />
<PostExcerptCheck>
<EnablePanelOption label={ __( 'Excerpt' ) } panelName="post-excerpt" />
</PostExcerptCheck>
<EnablePanelOption label={ __( 'Discussion' ) } panelName="discussion-panel" />
<PageAttributesCheck>
<EnablePanelOption label={ __( 'Page Attributes' ) } panelName="page-attributes" />
</PageAttributesCheck>
</Section>
<MetaBoxesSection title={ __( 'Advanced Panels' ) } />
</Modal>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment