1. import { __ } from '@wordpress/i18n';
  2. import { PluginSidebar } from '@wordpress/editor';
  3. import {
  4. PanelBody,
  5. Button,
  6. TextControl,
  7. SelectControl,
  8. } from '@wordpress/components';
  9. import { registerPlugin } from '@wordpress/plugins';
  10. import { useState } from '@wordpress/element';
  11. const PluginSidebarExample = () => {
  12. const [ text, setText ] = useState( '' );
  13. const [ select, setSelect ] = useState( 'a' );
  14. return (
  15. <PluginSidebar
  16. name="plugin-sidebar-example"
  17. title={ __( 'My PluginSidebar' ) }
  18. icon={ 'smiley' }
  19. >
  20. <PanelBody>
  21. <h2>
  22. { __( 'This is a heading for the PluginSidebar example.' ) }
  23. </h2>
  24. <p>
  25. { __(
  26. 'This is some example text for the PluginSidebar example.'
  27. ) }
  28. </p>
  29. <TextControl
  30. label={ __( 'Text Control' ) }
  31. value={ text }
  32. onChange={ ( newText ) => setText( newText ) }
  33. />
  34. <SelectControl
  35. label={ __( 'Select Control' ) }
  36. value={ select }
  37. options={ [
  38. { value: 'a', label: 'Option A' },
  39. { value: 'b', label: 'Option B' },
  40. { value: 'c', label: 'Option C' },
  41. ] }
  42. onChange={ ( newSelect ) => setSelect( newSelect ) }
  43. />
  44. <Button variant="primary">{ __( 'Primary Button' ) } </Button>
  45. </PanelBody>
  46. </PluginSidebar>
  47. );
  48. };
  49. // Register the plugin.
  50. registerPlugin( 'plugin-sidebar-example', { render: PluginSidebarExample } );

位置

PluginSidebarの例が展開されました