UNPKG

@payfit/unity-components

Version:

99 lines (98 loc) 3.71 kB
import { Button as e } from "../../button/Button.js"; import { ActionBarButton as t } from "../../action-bar/parts/ActionBarButton.js"; import { ActionBarIconButton as n } from "../../action-bar/parts/ActionBarIconButton.js"; import { ActionBar as r } from "../../action-bar/ActionBar.js"; import { ActionBarRoot as i } from "../../action-bar/parts/ActionBarRoot.js"; import { getPaginationTable as a } from "../DataTablePagination.js"; import { useCallback as o, useRef as s, useState as c } from "react"; import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime"; import { FormattedMessage as f, useIntl as p } from "react-intl"; import { useHotkeys as m } from "react-hotkeys-hook"; //#region src/components/data-table/parts/DataTableBulkActions.tsx function h({ selectionCount: t, onClearSelection: n, renderSelectionText: r, hasKeyshortcuts: i, keyShortcuts: a }) { return /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ d("div", { className: "uy:typography-body uy:whitespace-nowrap! uy:sr-only uy:md:not-sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true", children: [r ? r(t) : /* @__PURE__ */ u(f, { id: "unity:component:action-bar:selection-count-text", defaultMessage: "{selectionCount, plural, =0 {no items} one {item} other {items}} selected", values: { selectionCount: t } }), i && /* @__PURE__ */ u("span", { className: "uy:sr-only", children: /* @__PURE__ */ u(f, { id: "unity:component:action-bar:key-shortcuts-text", defaultMessage: "Use {keyShortcuts} to focus the action bar", values: { keyShortcuts: a } }) })] }), /* @__PURE__ */ u(e, { color: "inverted", variant: "ghost", onPress: n, children: /* @__PURE__ */ u(f, { id: "unity:component:action-bar:clear-selection-button", defaultMessage: "Clear selection" }) })] }); } var g = (e) => e.type === "icon-button"; function _({ table: e, actions: l, renderSelectionText: d }) { let f = s(null), _ = s(null), [v, y] = c(!1), b = p(); m("f6", () => { if ((e.getIsAllPageRowsSelected() || e.getIsSomePageRowsSelected()) && f.current) { let e = f.current.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])"); _.current = document.activeElement, e.length > 0 && (e[0].focus(), y(!0)); } }, { enableOnFormTags: !0 }), m("esc", () => { v && _.current && (_.current.focus(), y(!1)); }, { enableOnFormTags: !0 }); let x = e.getIsAllPageRowsSelected() || e.getIsSomePageRowsSelected(), S = e.getSelectedRowModel().rows.length, C = a(e) !== void 0, w = o(() => { e.resetRowSelection(); }, [e]); return /* @__PURE__ */ u(i, { isVisible: x, offsetBottom: C ? "$600" : 0, children: /* @__PURE__ */ u(r, { ref: f, actions: l, prefixContent: /* @__PURE__ */ u(h, { selectionCount: S, onClearSelection: w, renderSelectionText: d, hasKeyshortcuts: !0, keyShortcuts: "f6" }), onFocus: () => { y(!0); }, onBlur: () => { y(!1); }, "aria-keyshortcuts": "f6", "aria-label": b.formatMessage({ id: "unity:component:action-bar:toolbar-label", defaultMessage: "Bulk actions toolbar" }), children: (e) => g(e) ? /* @__PURE__ */ u(n, { icon: e.meta.icon, label: e.label, variant: e.variant, onPress: e.meta.onPress, isDisabled: e.meta.isDisabled, isLoading: e.meta.isLoading }, e.id) : /* @__PURE__ */ u(t, { variant: e.variant, onPress: e.meta?.onPress, prefixIcon: e.meta?.prefixIcon, isDisabled: e.meta?.isDisabled, isLoading: e.meta?.isLoading, children: e.label }, e.id) }) }); } _.displayName = "DataTableBulkActions"; //#endregion export { _ as DataTableBulkActions };