@trellixio/roaster-coffee
Version:
Beans' product component library
93 lines (87 loc) • 4.39 kB
JavaScript
;
var React = require('react');
var Button = require('../Button/Button.js');
var index$1 = require('./components/Checkbox/index.js');
var TableBody = require('./components/TableBody.js');
var TableCell = require('./components/TableCell.js');
var TableHead = require('./components/TableHead.js');
var TableHeadCell = require('./components/TableHeadCell.js');
var TablePagination = require('./components/TablePagination.js');
var TableProvider = require('./components/TableProvider/TableProvider.js');
var TableRow = require('./components/TableRow.js');
var hooks = require('./utils/table/hooks.js');
require('./utils/table/context.js');
var types = require('./utils/table/types.js');
var index = require('../../utils/classNames/index.js');
require('@floating-ui/react');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const TableBase = React__namespace.forwardRef((props, ref) => {
const { children, showPagination, selectActions, browsable = false } = props;
const { bulkSelectState, itemCount, selectedItemsCount, selectable } = hooks.useTableValue();
const handleSelectionChange = hooks.useTableSelectionChange();
const handleSelectAllItems = React__namespace.useCallback(() => {
handleSelectionChange(selectedItemsCount === types.SELECT_ALL_ITEMS ? types.SelectionType.Page : types.SelectionType.All);
}, [handleSelectionChange, selectedItemsCount]);
const handleTogglePage = React__namespace.useCallback(() => {
handleSelectionChange(types.SelectionType.Page);
}, [bulkSelectState, handleSelectionChange]);
const bodyMarkup = /* @__PURE__ */ React__namespace.createElement("div", { className: "table-container" }, /* @__PURE__ */ React__namespace.createElement("table", { ref, className: index.classNames("datatable", { selectable, browsable }) }, children));
return /* @__PURE__ */ React__namespace.createElement("section", { className: "table-section" }, /* @__PURE__ */ React__namespace.createElement("form", null, bulkSelectState && /* @__PURE__ */ React__namespace.createElement("div", { className: "table-actions visible" }, /* @__PURE__ */ React__namespace.createElement("div", { className: "items-group justify", style: { alignItems: "center" } }, /* @__PURE__ */ React__namespace.createElement("div", { className: "items-group" }, /* @__PURE__ */ React__namespace.createElement(
index$1.Checkbox,
{
labelClassName: "items-group",
onChange: () => handleTogglePage(),
className: selectedItemsCount !== types.SELECT_ALL_ITEMS && selectedItemsCount < itemCount ? "neutral" : "",
checked: true,
label: /* @__PURE__ */ React__namespace.createElement("p", { "data-role": "input-value" }, `${selectedItemsCount} ${selectedItemsCount === types.SELECT_ALL_ITEMS || selectedItemsCount > 1 ? "items" : "item"} selected`)
}
), selectActions), /* @__PURE__ */ React__namespace.createElement("div", { className: "action" }, /* @__PURE__ */ React__namespace.createElement(Button.Button, { variant: "inline", onClick: () => handleSelectAllItems() }, "Select all items")))), bodyMarkup, showPagination && /* @__PURE__ */ React__namespace.createElement(
TablePagination.TablePagination,
{
hasNext: props.hasNextPage,
hasPrevious: props.hasPreviousPage,
onNext: props.onNextPage,
onPrevious: props.onPreviousPage,
nextButtonProps: props.nextPageButtonProps,
previousButtonProps: props.previousPageButtonProps,
className: props.paginationClassName
}
)));
});
function Table({
children,
selectable = false,
itemCount,
selectedItemsCount = 0,
onSelectionChange,
...tableBaseProps
}) {
return /* @__PURE__ */ React__namespace.createElement(
TableProvider.TableProvider,
{
selectable,
itemCount,
selectedItemsCount,
onSelectionChange
},
/* @__PURE__ */ React__namespace.createElement(TableBase, { ...tableBaseProps }, children)
);
}
Table.displayName = "Table";
Table.Head = TableHead.TableHead;
Table.Body = TableBody.TableBody;
Table.Row = TableRow.TableRow;
Table.HeadCell = TableHeadCell.TableHeadCell;
Table.Cell = TableCell.TableCell;
exports.Table = Table;
//# sourceMappingURL=Table.js.map