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