import React, { useMemo } from 'react'; import classnames from 'classnames'; import flatten from 'lodash.flatten'; import { CompositionsMenuSlot } from '@teambit/compositions'; import styles from './compositions-menu-bar.module.scss'; interface CompositionsMenuBarProps extends React.HTMLAttributes { menuBarWidgets?: CompositionsMenuSlot; } export function CompositionsMenuBar({ className, menuBarWidgets, children, ...rest }: CompositionsMenuBarProps) { const widgetsStart = useMemo( () => flatten(menuBarWidgets?.values()) .filter(({ location }) => location === 'start') .map(({ content }, idx) => {content}), [menuBarWidgets] ); const widgetsEnd = useMemo( () => flatten(menuBarWidgets?.values()) .filter(({ location }) => location === 'end') .map(({ content }, idx) => {content}), [menuBarWidgets] ); if (!widgetsStart.length && !widgetsEnd.length) return null; return (
{!!(widgetsStart?.length || children) && (
{widgetsStart} {children}
)}
{!!widgetsEnd?.length &&
{widgetsEnd}
}
); }