@wordpress/block-editor
Version:
92 lines (91 loc) • 3.31 kB
JavaScript
// packages/block-editor/src/components/inspector-controls-tabs/index.js
import {
Icon,
Tooltip,
privateApis as componentsPrivateApis
} from "@wordpress/components";
import { useEffect, useState } from "@wordpress/element";
import { store as preferencesStore } from "@wordpress/preferences";
import { useSelect } from "@wordpress/data";
import { TAB_SETTINGS, TAB_STYLES, TAB_LIST_VIEW, TAB_CONTENT } from "./utils";
import SettingsTab from "./settings-tab";
import StylesTab from "./styles-tab";
import ContentTab from "./content-tab";
import InspectorControls from "../inspector-controls";
import useIsListViewTabDisabled from "./use-is-list-view-tab-disabled";
import { unlock } from "../../lock-unlock";
import { jsx, jsxs } from "react/jsx-runtime";
var { Tabs } = unlock(componentsPrivateApis);
function InspectorControlsTabs({
blockName,
clientId,
hasBlockStyles,
tabs,
isSectionBlock,
contentClientIds
}) {
const showIconLabels = useSelect((select) => {
return select(preferencesStore).get("core", "showIconLabels");
}, []);
const initialTabName = !useIsListViewTabDisabled(blockName) ? TAB_LIST_VIEW.name : void 0;
const [selectedTabId, setSelectedTabId] = useState(
initialTabName ?? tabs[0]?.name
);
useEffect(() => {
if (initialTabName) {
return;
}
if (tabs?.length && selectedTabId) {
const activeTab = tabs.find(
(tab) => tab.name === selectedTabId
);
if (!activeTab) {
setSelectedTabId(tabs[0].name);
}
}
}, [tabs, selectedTabId, initialTabName]);
return /* @__PURE__ */ jsx("div", { className: "block-editor-block-inspector__tabs", children: /* @__PURE__ */ jsxs(
Tabs,
{
defaultTabId: initialTabName,
selectedTabId,
onSelect: setSelectedTabId,
children: [
/* @__PURE__ */ jsx(Tabs.TabList, { children: tabs.map(
(tab) => showIconLabels ? /* @__PURE__ */ jsx(Tabs.Tab, { tabId: tab.name, children: tab.title }, tab.name) : /* @__PURE__ */ jsx(Tooltip, { text: tab.title, children: /* @__PURE__ */ jsx(
Tabs.Tab,
{
tabId: tab.name,
"aria-label": tab.title,
children: /* @__PURE__ */ jsx(Icon, { icon: tab.icon })
}
) }, tab.name)
) }),
/* @__PURE__ */ jsx(Tabs.TabPanel, { tabId: TAB_SETTINGS.name, focusable: false, children: /* @__PURE__ */ jsx(SettingsTab, { showAdvancedControls: !!blockName }) }),
/* @__PURE__ */ jsx(Tabs.TabPanel, { tabId: TAB_STYLES.name, focusable: false, children: /* @__PURE__ */ jsx(
StylesTab,
{
blockName,
clientId,
hasBlockStyles,
isSectionBlock,
contentClientIds
}
) }),
/* @__PURE__ */ jsx(Tabs.TabPanel, { tabId: TAB_CONTENT.name, focusable: false, children: /* @__PURE__ */ jsx(
ContentTab,
{
rootClientId: clientId,
contentClientIds
}
) }),
/* @__PURE__ */ jsx(Tabs.TabPanel, { tabId: TAB_LIST_VIEW.name, focusable: false, children: /* @__PURE__ */ jsx(InspectorControls.Slot, { group: "list" }) })
]
},
clientId
) });
}
export {
InspectorControlsTabs as default
};
//# sourceMappingURL=index.js.map