@carbon/react
Version:
React components for the Carbon Design System
99 lines (97 loc) • 4.69 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_usePrefix = require("../../internal/usePrefix.js");
const require_Text = require("../Text/Text.js");
const require_index = require("../Button/index.js");
const require_TableActionList = require("./TableActionList.js");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/components/DataTable/TableBatchActions.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const translationIds = {
"carbon.table.batch.cancel": "carbon.table.batch.cancel",
"carbon.table.batch.items.selected": "carbon.table.batch.items.selected",
"carbon.table.batch.item.selected": "carbon.table.batch.item.selected",
"carbon.table.batch.selectAll": "carbon.table.batch.selectAll"
};
const defaultTranslations = {
[translationIds["carbon.table.batch.cancel"]]: "Cancel",
[translationIds["carbon.table.batch.items.selected"]]: "items selected",
[translationIds["carbon.table.batch.item.selected"]]: "item selected",
[translationIds["carbon.table.batch.selectAll"]]: "Select all"
};
const defaultTranslateWithId = (messageId, args = {
totalSelected: 0,
totalCount: 0
}) => {
const { totalSelected, totalCount } = args;
switch (messageId) {
case translationIds["carbon.table.batch.cancel"]: return defaultTranslations[messageId];
case translationIds["carbon.table.batch.selectAll"]: return `${defaultTranslations[messageId]} (${totalCount})`;
case translationIds["carbon.table.batch.items.selected"]:
case translationIds["carbon.table.batch.item.selected"]: return `${totalSelected} ${defaultTranslations[messageId]}`;
}
};
const TableBatchActions = ({ className, children, shouldShowBatchActions, totalSelected, totalCount, onCancel, onSelectAll, translateWithId: t = defaultTranslateWithId, ...rest }) => {
const [isScrolling, setIsScrolling] = react.default.useState(false);
const prefix = require_usePrefix.usePrefix();
const batchActionsClasses = (0, classnames.default)({
[`${prefix}--batch-actions`]: true,
[`${prefix}--batch-actions--active`]: shouldShowBatchActions
}, className);
const batchSummaryClasses = (0, classnames.default)(`${prefix}--batch-summary`, { [`${prefix}--batch-summary__scroll`]: isScrolling });
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
onScroll: () => {
setIsScrolling(!isScrolling);
},
"aria-hidden": !shouldShowBatchActions,
className: batchActionsClasses,
...rest,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: batchSummaryClasses,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: `${prefix}--batch-summary__para`,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, { children: totalSelected > 1 || totalSelected === 0 ? t("carbon.table.batch.items.selected", { totalSelected }) : t("carbon.table.batch.item.selected", { totalSelected }) })
}), onSelectAll && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: `${prefix}--batch-summary__divider`,
children: "|"
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_index.default, {
onClick: onSelectAll,
tabIndex: shouldShowBatchActions ? 0 : -1,
children: t("carbon.table.batch.selectAll", { totalCount })
})] })]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_TableActionList.default, { children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_index.default, {
className: `${prefix}--batch-summary__cancel`,
tabIndex: shouldShowBatchActions ? 0 : -1,
onClick: onCancel,
children: t("carbon.table.batch.cancel")
})] })]
});
};
TableBatchActions.propTypes = {
children: prop_types.default.node,
className: prop_types.default.string,
onCancel: prop_types.default.func.isRequired,
onSelectAll: prop_types.default.func,
shouldShowBatchActions: prop_types.default.bool,
totalCount: prop_types.default.number,
totalSelected: prop_types.default.number.isRequired,
translateWithId: prop_types.default.func
};
//#endregion
exports.default = TableBatchActions;