import { Accordion, AccordionDetails, AccordionSummary, LinearProgress, } from '@mui/material' import { styles } from './styles' import { Title } from './components/title' import type { WrapperState, WrapperUIProps } from './types' import { Options } from './components/options' import { Actions } from './components/actions' import { useWidgetSelector } from '../stores/use-widget-selector' const EMPTY_ACTIONS: NonNullable = [] const EMPTY_OPTIONS: NonNullable = [] /** * Presentational wrapper component that renders the widget accordion UI with title, actions, options menu, and loading indicator. For uncontrolled usage without automatic widget store synchronization, use this instead of WidgetWrapper. * * @example * ```tsx * ]} * onChangeCollapsed={(e, collapsed) => console.log(collapsed)} * > *
Content
*
* ``` */ export function WrapperUI({ children, id, actions = EMPTY_ACTIONS, sx, labels, options = EMPTY_OPTIONS, onChangeCollapsed, }: WrapperUIProps) { // Single consolidated subscription instead of 4 separate ones. const { title, collapsed, disabled, isFetching } = useWidgetSelector( id, (w) => { return { title: (w as WrapperState | undefined)?.title, collapsed: (w as WrapperState | undefined)?.collapsed, disabled: (w as WrapperState | undefined)?.disabled, isFetching: w?.isFetching, } }, ) return ( {isFetching && } {title} {!!actions.length && } {!!options.length && ( )} {children} ) }