@vectara/vectara-ui 17.0.1 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,13 +17,14 @@ import { VuiPopover } from "../popover/Popover";
|
|
|
17
17
|
import { VuiIcon } from "../icon/Icon";
|
|
18
18
|
import { VuiButtonSecondary } from "../button/ButtonSecondary";
|
|
19
19
|
export const VuiTableBulkActions = ({ selectedRows, actions }) => {
|
|
20
|
+
var _a;
|
|
20
21
|
const [isOpen, setIsOpen] = useState(false);
|
|
21
22
|
let content;
|
|
22
23
|
if (actions.length === 1) {
|
|
23
|
-
content = (_jsx(VuiButtonSecondary, Object.assign({ color: "neutral", size: "m", "data-testid": actions[0].testId, onClick: () => actions[0].onClick && actions[0].onClick(selectedRows) }, { children: actions[0].label })));
|
|
24
|
+
content = (_jsx(VuiButtonSecondary, Object.assign({ color: (_a = actions[0].color) !== null && _a !== void 0 ? _a : "neutral", size: "m", "data-testid": actions[0].testId, onClick: () => actions[0].onClick && actions[0].onClick(selectedRows), icon: actions[0].icon }, { children: `${actions[0].label} (${selectedRows.length})` })));
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
content = (_jsx(VuiPopover, Object.assign({ isOpen: isOpen, setIsOpen: () => setIsOpen(!isOpen), button: _jsxs(VuiButtonSecondary, Object.assign({ color: "
|
|
27
|
+
content = (_jsx(VuiPopover, Object.assign({ isOpen: isOpen, setIsOpen: () => setIsOpen(!isOpen), button: _jsxs(VuiButtonSecondary, Object.assign({ color: "primary", size: "m", "data-testid": "bulkActionsMenuButton", icon: _jsx(VuiIcon, { children: _jsx(BiCaretDown, {}) }) }, { children: [selectedRows.length, " selected"] })) }, { children: _jsx(VuiOptionsList, { onSelectOption: () => {
|
|
27
28
|
setIsOpen(false);
|
|
28
29
|
}, options: actions.map((_a) => {
|
|
29
30
|
var { href } = _a, action = __rest(_a, ["href"]);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { ButtonColor } from "../button/types";
|
|
1
3
|
import { Row } from "./types";
|
|
2
4
|
export type Action<T> = {
|
|
3
5
|
label: string;
|
|
@@ -5,6 +7,8 @@ export type Action<T> = {
|
|
|
5
7
|
onClick?: (row: T) => void;
|
|
6
8
|
href?: (row: T) => string | undefined;
|
|
7
9
|
testId?: string;
|
|
10
|
+
color?: ButtonColor;
|
|
11
|
+
icon?: ReactElement | null;
|
|
8
12
|
};
|
|
9
13
|
export type Props<T> = {
|
|
10
14
|
row: any;
|
|
@@ -9,9 +9,9 @@ export const VuiTableRowActions = ({ row, actions, onToggle, testId }) => {
|
|
|
9
9
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
10
|
// Filter out disabled actions.
|
|
11
11
|
const actionOptions = actions.reduce((acc, action) => {
|
|
12
|
-
const { label, isDisabled, onClick, href, testId } = action;
|
|
12
|
+
const { label, isDisabled, onClick, href, testId, color, icon } = action;
|
|
13
13
|
if (!(isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(row))) {
|
|
14
|
-
acc.push({ label, onClick, href: href === null || href === void 0 ? void 0 : href(row), value: row, testId });
|
|
14
|
+
acc.push({ label, onClick, href: href === null || href === void 0 ? void 0 : href(row), value: row, testId, color, icon });
|
|
15
15
|
}
|
|
16
16
|
return acc;
|
|
17
17
|
}, []);
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "../../../lib";
|
|
15
15
|
import { VuiTable } from "../../../lib/components/table/Table";
|
|
16
16
|
import { createFakePeople, Person } from "./createFakePeople";
|
|
17
|
-
import { BiError } from "react-icons/bi";
|
|
17
|
+
import { BiError, BiTrash } from "react-icons/bi";
|
|
18
18
|
|
|
19
19
|
const ROWS_PER_PAGE = 20;
|
|
20
20
|
const people: Person[] = createFakePeople(152);
|
|
@@ -227,17 +227,23 @@ export const Table = () => {
|
|
|
227
227
|
},
|
|
228
228
|
testId: "editAction"
|
|
229
229
|
},
|
|
230
|
+
{
|
|
231
|
+
label: "Search",
|
|
232
|
+
href: (person: Person) => `https://www.google.com/search?q=${person.name}`,
|
|
233
|
+
testId: "searchAction"
|
|
234
|
+
},
|
|
230
235
|
{
|
|
231
236
|
label: "Delete",
|
|
232
237
|
onClick: (person: Person) => {
|
|
233
238
|
console.log("Delete", person);
|
|
234
239
|
},
|
|
235
|
-
testId: "deleteAction"
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
testId: "deleteAction",
|
|
241
|
+
color: "danger" as const,
|
|
242
|
+
icon: (
|
|
243
|
+
<VuiIcon color="danger">
|
|
244
|
+
<BiTrash />
|
|
245
|
+
</VuiIcon>
|
|
246
|
+
)
|
|
241
247
|
}
|
|
242
248
|
];
|
|
243
249
|
|
|
@@ -293,7 +299,13 @@ export const Table = () => {
|
|
|
293
299
|
label: "Delete",
|
|
294
300
|
onClick: (people: Person[]) => {
|
|
295
301
|
console.log("Delete", people);
|
|
296
|
-
}
|
|
302
|
+
},
|
|
303
|
+
color: "danger" as const,
|
|
304
|
+
icon: (
|
|
305
|
+
<VuiIcon color="danger">
|
|
306
|
+
<BiTrash />
|
|
307
|
+
</VuiIcon>
|
|
308
|
+
)
|
|
297
309
|
}
|
|
298
310
|
]
|
|
299
311
|
}
|