UNPKG

@wordpress/edit-post

Version:
82 lines (68 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _components = require("@wordpress/components"); var _i18n = require("@wordpress/i18n"); var _data = require("@wordpress/data"); var _store = require("../../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ const SettingsHeader = ({ sidebarName }) => { const { openGeneralSidebar } = (0, _data.useDispatch)(_store.store); const openDocumentSettings = () => openGeneralSidebar('edit-post/document'); const openBlockSettings = () => openGeneralSidebar('edit-post/block'); const { documentLabel, isTemplateMode } = (0, _data.useSelect)(select => { var _postType$labels$sing, _postType$labels; const currentPostType = select('core/editor').getCurrentPostType(); const postType = select('core').getPostType(currentPostType); return { documentLabel: // Disable reason: Post type labels object is shaped like this. // eslint-disable-next-line camelcase (_postType$labels$sing = postType === null || postType === void 0 ? void 0 : (_postType$labels = postType.labels) === null || _postType$labels === void 0 ? void 0 : _postType$labels.singular_name) !== null && _postType$labels$sing !== void 0 ? _postType$labels$sing : // translators: Default label for the Document sidebar tab, not selected. (0, _i18n.__)('Document'), isTemplateMode: select(_store.store).isEditingTemplate() }; }, []); const [documentAriaLabel, documentActiveClass] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. %s: Document label. [(0, _i18n.sprintf)((0, _i18n.__)('%s (selected)'), documentLabel), 'is-active'] : [documentLabel, '']; const [blockAriaLabel, blockActiveClass] = sidebarName === 'edit-post/block' ? // translators: ARIA label for the Block Settings Sidebar tab, selected. [(0, _i18n.__)('Block (selected)'), 'is-active'] : // translators: ARIA label for the Block Settings Sidebar tab, not selected. [(0, _i18n.__)('Block'), '']; const [templateAriaLabel, templateActiveClass] = sidebarName === 'edit-post/document' ? [(0, _i18n.__)('Template (selected)'), 'is-active'] : [(0, _i18n.__)('Template'), '']; /* Use a list so screen readers will announce how many tabs there are. */ return (0, _element.createElement)("ul", null, !isTemplateMode && (0, _element.createElement)("li", null, (0, _element.createElement)(_components.Button, { onClick: openDocumentSettings, className: `edit-post-sidebar__panel-tab ${documentActiveClass}`, "aria-label": documentAriaLabel, "data-label": documentLabel }, documentLabel)), isTemplateMode && (0, _element.createElement)("li", null, (0, _element.createElement)(_components.Button, { onClick: openDocumentSettings, className: `edit-post-sidebar__panel-tab ${templateActiveClass}`, "aria-label": templateAriaLabel, "data-label": (0, _i18n.__)('Template') }, (0, _i18n.__)('Template'))), (0, _element.createElement)("li", null, (0, _element.createElement)(_components.Button, { onClick: openBlockSettings, className: `edit-post-sidebar__panel-tab ${blockActiveClass}`, "aria-label": blockAriaLabel // translators: Data label for the Block Settings Sidebar tab. , "data-label": (0, _i18n.__)('Block') }, // translators: Text label for the Block Settings Sidebar tab. (0, _i18n.__)('Block')))); }; var _default = SettingsHeader; exports.default = _default; //# sourceMappingURL=index.js.map