import React from "react"; import { computed, makeObservable, action } from "mobx"; import { observer } from "mobx-react"; import { ProjectContext } from "project-editor/project/context"; import classNames from "classnames"; export interface SubNavigationItem { name: string; component: React.ReactNode; numItems: number; } interface SubNavigationProps { id: string; items: SubNavigationItem[]; } export const SubNavigation = observer( class SubNavigation extends React.Component { static contextType = ProjectContext; declare context: React.ContextType; constructor(props: any) { super(props); makeObservable(this, { selectedItem: computed, selectItem: action.bound }); } get selectedItem() { const selectedItem = this.context.navigationStore.subnavigationSelectedItems[ this.props.id ]; if ( selectedItem != undefined && this.props.items.find(item => item.name == selectedItem) ) { return selectedItem; } return this.props.items[0].name; } selectItem(name: string) { this.context.navigationStore.subnavigationSelectedItems[ this.props.id ] = name; } render() { return (
e.preventDefault()} >
{this.props.items.find( item => item.name == this.selectedItem )?.component ?? null}
); } } );