/** * WordPress dependencies */ import { useViewportMatch } from '@wordpress/compose'; import { Navigator, __experimentalItemGroup as ItemGroup, __experimentalItem as Item, __experimentalHStack as HStack, __experimentalText as Text, __experimentalTruncate as Truncate, FlexItem, Card, CardHeader, CardBody, privateApis as componentsPrivateApis, } from '@wordpress/components'; import { useMemo, useState } from '@wordpress/element'; import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; import { isRTL, __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { unlock } from '../../lock-unlock'; const { Tabs } = unlock( componentsPrivateApis ); const PREFERENCES_MENU = 'preferences-menu'; export type PreferencesModalTabsProps = { sections: { name: string; tabLabel: string; content: React.ReactNode }[]; }; export default function PreferencesModalTabs( { sections, }: PreferencesModalTabsProps ) { const isLargeViewport = useViewportMatch( 'medium' ); // This is also used to sync the two different rendered components // between small and large viewports. const [ activeMenu, setActiveMenu ] = useState( PREFERENCES_MENU ); /** * Create helper objects from `sections` for easier data handling. * `tabs` is used for creating the `Tabs` and `sectionsContentMap` * is used for easier access to active tab's content. */ const { tabs, sectionsContentMap } = useMemo( () => { let mappedTabs: { tabs: { name: string; title: string }[]; sectionsContentMap: Record< string, React.ReactNode >; } = { tabs: [], sectionsContentMap: {}, }; if ( sections.length ) { mappedTabs = sections.reduce< typeof mappedTabs >( ( accumulator, { name, tabLabel: title, content } ) => { accumulator.tabs.push( { name, title } ); accumulator.sectionsContentMap[ name ] = content; return accumulator; }, { tabs: [], sectionsContentMap: {} } ); } return mappedTabs; }, [ sections ] ); let modalContent; // We render different components based on the viewport size. if ( isLargeViewport ) { modalContent = (