UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

30 lines (29 loc) 1.54 kB
import { jsx as _jsx } from "react/jsx-runtime"; 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"; export const VuiTableRowActions = ({ row, actions, onToggle, testId }) => { const [isOpen, setIsOpen] = useState(false); // Filter out disabled actions. const actionOptions = actions.reduce((acc, action) => { const { label, isDisabled, onClick, href, testId } = action; if (!(isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(row))) { acc.push({ label, onClick, href: href === null || href === void 0 ? void 0 : href(row), value: row, testId }); } return acc; }, []); if (!actionOptions.length) { return null; } const content = (_jsx(VuiPopover, Object.assign({ isOpen: isOpen, setIsOpen: () => { setIsOpen(!isOpen); onToggle(!isOpen); }, button: _jsx(VuiButtonSecondary, { color: "neutral", size: "xs", icon: _jsx(VuiIcon, { children: _jsx(BiCaretDown, {}) }), "data-testid": testId }) }, { children: _jsx(VuiOptionsList, { onSelectOption: () => { setIsOpen(false); onToggle(false); }, options: actionOptions, size: "m" }) }))); return _jsx("div", Object.assign({ className: "vuiTableActions" }, { children: content })); };