import React, { ReactNode } from 'react'; import { every } from 'lodash'; import { Typography } from '@material-ui/core'; import { DARKEST_GRAY } from '../../constants/colors'; export interface LabelledGroupProps { /** Contents of the menu when opened */ children: ReactNode; /** Contents of button */ label: ReactNode; /** Additional styles to apply to the widget container. */ containerStyles?: React.CSSProperties; } /** * Renders a grey outlined box with a label in the top left of the outline/border * * But renders nothing if no children are contained within it. */ export default function LabelledGroup(props: LabelledGroupProps) { const { children, label, containerStyles } = props; // don't render anything if all the children (or no children) are null if (every(React.Children.toArray(children), (child) => child == null)) return null; return (
{/* wrapper div to prevent from inline-flex */}
{label && ( {label} )} {children}
); }