import React, { ReactElement, MouseEvent, useState, useCallback } from 'react'; import css from '../../../utils/css'; import { IconName } from '../../Icon'; import { CommonProps } from '../../common'; import Button from '../../Button'; import Menu from '../../Menu'; import Dropdown from '../../Dropdown'; import assert from '../../../utils/assert'; import Divider from '../../Divider'; interface RowActionProps extends CommonProps { /** * List of actions to be shown in the action menu, it contains at least 1 actions. * */ actions: { divider?: 'top' | 'bottom'; icon?: IconName; intent?: 'text' | 'danger'; onClick?: (e: MouseEvent) => void; text: string; }[]; } const RowAction = ({ actions, id, className, style, sx = {}, 'data-test-id': dataTestId, }: RowActionProps): ReactElement => { assert(actions.length > 0, `[RowAction] Need at least 1 action to render`); const [open, setOpen] = useState(false); const closeDropdown = useCallback(() => { setOpen(false); }, [setOpen]); if (actions.length === 1 && actions[0] !== undefined) { return ( ); } const dropdownContent = (
); return (