import React, { ReactNode, useEffect, useRef, useState } from 'react'; import { Box, SectionHelper, SectionHelperProps, Table, } from '@wix/design-system'; import { Fade } from '../Fade'; import { Collapse } from '../Collapse'; import { observer } from 'mobx-react-lite'; import { useToolbarCollectionContext } from '../ToolbarCollectionContext'; import { TableTopNotificationState } from './TableTopNotificationState'; export interface TableTopNotificationProps extends Partial { /** * After the notification close animation finished */ onAfterClose?: () => unknown; /** * After the notification open animation finished */ onAfterOpen?: () => unknown; /** hide the notification when search is applied. * @default false */ hideOnSearch?: boolean; children?: ReactNode; } function _TableTopNotification(props: TableTopNotificationProps) { const { onClose, showCloseButton = !!onClose, onAfterClose, onAfterOpen, hideOnSearch, children, appearance = 'standard', ...rest } = props; const toolbarCollectionState = useToolbarCollectionContext(); const { collection, totalStickyContentHeight } = toolbarCollectionState; const { _topNotification: topNotification, query: { search }, } = collection; const [state] = useState( () => new TableTopNotificationState({ topNotification, getStickyContentHeight: () => toolbarCollectionState.totalStickyContentHeight, reportBI: toolbarCollectionState.reportBi, }), ); const targetRef = useRef(null); useEffect(() => state.init(), []); const { position } = state; const { data: text, show } = topNotification; let child; if (hideOnSearch && !search.isEmpty) { child = null; } else { child = ( { topNotification.clickClose(onAfterClose); onClose?.(e); }} appearance={appearance} > {text} {children} ); } return ( <> {child}
{ targetRef.current = el; }} /> ); } export const TableTopNotification = observer(_TableTopNotification); TableTopNotification.displayName = 'TableTopNotification';