import React, { Context, useContext } from 'react' import useTheme from '../use-theme' import FlyoutMenu from './flyout-menu' import FlyoutMenuGroup from './flyout-menu-group' import FlyoutMenuFooter from './flyout-menu-footer' import FlyoutAction from './flyout-action' interface Props { context: Context icon?: React.ReactNode className?: string } const defaultProps = { className: '' } type ItemProps = { label: string active: boolean icon?: React.ReactNode onToggle?: (newPanel: string | undefined) => void onBreadcrumbClick: () => void promos: [JSX.Element] } type NativeAttrs = Omit, keyof Props> export type FlyoutProps = Props & typeof defaultProps & NativeAttrs const Flyout: React.FC> = ({ children, context, icon, className, ...props }) => { const theme = useTheme() const ctx: any = useContext(context) const open = ctx.openPanel.get const hasOpenPanel = open !== null && open !== 'root' return (
    {React.Children.map( children as [React.ReactElement], (child: React.ReactElement) => { return React.cloneElement(child, { active: open === child.props.label ? true : undefined, onToggle: ctx.toggleNavItem, icon: icon // onBreadcrumbClick: () => ctx.openPanel.set('root') }) } )}
) } type MemoPageComponent

= React.NamedExoticComponent

& { Action: typeof FlyoutAction Menu: typeof FlyoutMenu MenuGroup: typeof FlyoutMenuGroup MenuFooter: typeof FlyoutMenuFooter } type ComponentProps = Partial & Omit & NativeAttrs Flyout.defaultProps = defaultProps export default React.memo(Flyout) as MemoPageComponent