/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/e2e-tests/plugins/plugins-api/sidebar.js
91 строка
2 KB
Riad Benguella
Editor: Unify PluginSidebarMoreMenuItem (#60853)
18 апр 2024, 17:48
Не верифицирован
18 апр 2024, 17:48
8923a83
Код
Авторство
О чём код?
( function () { const Button = wp.components.Button; const PanelBody = wp.components.PanelBody; const PanelRow = wp.components.PanelRow; const editorStore = wp.editor.store; const useDispatch = wp.data.useDispatch; const useSelect = wp.data.useSelect; const PlainText = wp.blockEditor.PlainText; const Fragment = wp.element.Fragment; const el = wp.element.createElement; const __ = wp.i18n.__; const registerPlugin = wp.plugins.registerPlugin; const PluginSidebar = wp.editor.PluginSidebar; const PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem; function SidebarContents() { const postTitle = useSelect( ( select ) => select( editorStore ).getEditedPostAttribute( 'title' ) ); const editPost = useDispatch( editorStore ).editPost; function resetTitle() { editPost( { title: '' } ); } function updateTitle( title ) { editPost( { title } ); } return el( PanelBody, { className: 'sidebar-title-plugin-panel' }, el( PanelRow, {}, el( 'label', { htmlFor: 'title-plain-text', }, __( 'Title:' ) ), el( PlainText, { id: 'title-plain-text', onChange: updateTitle, placeholder: __( '(no title)' ), value: postTitle, } ) ), el( PanelRow, {}, el( Button, { variant: 'primary', onClick: resetTitle, }, __( 'Reset' ) ) ) ); } function MySidebarPlugin() { return el( Fragment, {}, el( PluginSidebar, { name: 'title-sidebar', title: __( 'Plugin title' ), }, el( SidebarContents, {} ) ), el( PluginSidebarMoreMenuItem, { target: 'title-sidebar', }, __( 'Plugin more menu title' ) ) ); } registerPlugin( 'my-sidebar-plugin', { icon: 'text', render: MySidebarPlugin, } ); } )();