import { useState } from "react"; import { BiCaretDown } from "react-icons/bi"; import { VuiOptionsList } from "../optionsList/OptionsList"; import { VuiPopover } from "../popover/Popover"; import { VuiIcon } from "../icon/Icon"; import { VuiButtonSecondary } from "../button/ButtonSecondary"; import { Row } from "./types"; export type Action = { label: string; isDisabled?: (row: T) => boolean; onClick?: (row: T) => void; href?: (row: T) => string | undefined; testId?: string; }; export type Props = { row: any; actions: Action[]; onToggle: (isSelected: boolean) => void; testId?: string; }; export const VuiTableRowActions = ({ row, actions, onToggle, testId }: Props) => { const [isOpen, setIsOpen] = useState(false); // Filter out disabled actions. const actionOptions = actions.reduce((acc, action) => { const { label, isDisabled, onClick, href, testId } = action; if (!isDisabled?.(row)) { acc.push({ label, onClick, href: href?.(row), value: row, testId }); } return acc; }, [] as any); if (!actionOptions.length) { return null; } const content = ( { setIsOpen(!isOpen); onToggle(!isOpen); }} button={ } data-testid={testId} /> } > { setIsOpen(false); onToggle(false); }} options={actionOptions} size="m" /> ); return
{content}
; };