index.js
58 lines
| 1 | import { Button, Modal, PanelBody } from '@wordpress/components'; |
| 2 | import { useState } from '@wordpress/element'; |
| 3 | import { LibraryProvider } from './components/library-provider'; |
| 4 | import LibraryLayout from './components/library-layout'; |
| 5 | import { addFilter } from '@wordpress/hooks'; |
| 6 | import { __ } from '@wordpress/i18n'; |
| 7 | import './editor.scss'; |
| 8 | |
| 9 | function PatternLibrary( content, { activePanel } ) { |
| 10 | const [ isOpen, setIsOpen ] = useState( false ); |
| 11 | |
| 12 | if ( activePanel ) { |
| 13 | return content; |
| 14 | } |
| 15 | |
| 16 | return ( |
| 17 | <> |
| 18 | <PanelBody> |
| 19 | <h2 className="gblocks-editor-sidebar__panel-title"> |
| 20 | { __( 'Pattern Library', 'generateblocks' ) } |
| 21 | </h2> |
| 22 | |
| 23 | <Button |
| 24 | className="gblocks-pattern-library-button" |
| 25 | variant="secondary" |
| 26 | onClick={ () => setIsOpen( true ) } |
| 27 | isPressed={ isOpen } |
| 28 | > |
| 29 | { __( 'Open Pattern Library', 'generateblocks' ) } |
| 30 | </Button> |
| 31 | </PanelBody> |
| 32 | |
| 33 | { content } |
| 34 | |
| 35 | { !! isOpen && ( |
| 36 | <Modal |
| 37 | className="gblocks-pattern-library-modal" |
| 38 | isFullScreen |
| 39 | onRequestClose={ () => setIsOpen( false ) } |
| 40 | > |
| 41 | <LibraryProvider> |
| 42 | <LibraryLayout |
| 43 | closeModal={ () => setIsOpen( false ) } |
| 44 | readOnly={ false } |
| 45 | /> |
| 46 | </LibraryProvider> |
| 47 | </Modal> |
| 48 | ) } |
| 49 | </> |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | addFilter( |
| 54 | 'generateblocks.editor.sidebar', |
| 55 | 'generateblocks/pattern-library', |
| 56 | PatternLibrary |
| 57 | ); |
| 58 |