import { ErrorOutlineIcon, IconButton } from "@firecms/ui"; import { ErrorTooltip } from "../../ErrorTooltip"; import { useCallback, useEffect, useRef } from "react"; export interface EntityTableCellActionsProps { showError: false | Error | undefined; disabled: boolean; showExpandIcon: boolean | undefined; selected: boolean | undefined; openPopup?: (cellRect: DOMRect | undefined) => void; children?: React.ReactNode; } export function EntityTableCellActions({ showError, disabled, showExpandIcon, selected, openPopup, children }: EntityTableCellActionsProps) { const ref = useRef(null); const doOpenPopup = useCallback(() => { if (openPopup) { const cellRect = ref && ref?.current?.getBoundingClientRect(); openPopup(cellRect); } }, []); const iconRef = useRef(); useEffect(() => { if (iconRef.current && selected) { iconRef.current.focus({ preventScroll: true }); } }, [selected]); return <> {(showError || (!disabled && showExpandIcon)) &&
{selected && children} {selected && !disabled && showExpandIcon && } {showError && }
} ; }