Sha256: 97f58e08b7e33b7fb9338e93a8bc67e8638f07ac2e0cd2a4fc8bdd88633f6dfd
Contents?: true
Size: 1.43 KB
Versions: 4
Compression:
Stored size: 1.43 KB
Contents
import { useState } from "react"; import * as PageEditor from "../../types/PageEditor"; import { unconfiguredBlocks } from "./usePage"; function tabsList(state: PageEditor.State): PageEditor.Tab[] { const { templates, templateConfig } = state; const tabs: PageEditor.Tab[] = [ { id: "content", name: "Content", enabled: true } ]; if (templates.filter((t) => t.images).length > 0) { tabs.push({ id: "images", name: "Images", enabled: templateConfig.images }); } if (templates.filter((t) => t.files).length > 0) { tabs.push({ id: "files", name: "Files", enabled: templateConfig.files }); } tabs.push({ id: "metadata", name: "Metadata", enabled: true }); if (unconfiguredBlocks(state).length > 0) { tabs.push({ id: "unconfigured-content", name: "Unconfigured content", enabled: true }); } return tabs; } function initialTab(tabs: PageEditor.Tab[]): string { const tabExpression = /#(.*)$/; if (document.location.toString().match(tabExpression)) { const id = document.location.toString().match(tabExpression)[1]; const matchingTab = tabs.filter((t) => t.id == id)[0]; if (matchingTab) { return matchingTab.id; } } return tabs[0].id; } export default function useTabs( state: PageEditor.State ): [PageEditor.Tab[], string, (tab: string) => void] { const tabs = tabsList(state); const [tab, setTab] = useState<string>(initialTab(tabs)); return [tabs, tab, setTab]; }
Version data entries
4 entries across 4 versions & 1 rubygems