UNPKG

@payfit/unity-components

Version:

104 lines (103 loc) • 3.38 kB
import { Select as e } from "../../select/Select.js"; import { SelectOption as t } from "../../select/parts/SelectOption.js"; import { ClientSidePagination as n } from "../../client-side-pagination/ClientSidePagination.js"; import { forwardRef as r, useState as i } from "react"; import { uyTv as a } from "@payfit/unity-themes"; import { jsx as o, jsxs as s } from "react/jsx-runtime"; import { useTranslation as c } from "react-i18next"; import { useId as l } from "react-aria/useId"; //#region src/core/components/table/parts/TablePagination.tsx var u = a({ base: [ "uy:bg-surface-neutral-low", "uy:sticky uy:bottom-0", "uy:grid uy:grid-cols-3 uy:items-center", "uy:ps-200 uy:py-100 uy:pe-100" ] }), d = [ { value: "10", label: "10" }, { value: "50", label: "50" }, { value: "100", label: "100" }, { value: "200", label: "200" } ], f = r((r, a) => { let { pageCount: f, rowCount: p, currentPage: m, rowsPerPage: h, defaultPage: g, pageSizeOptions: _ = d, defaultPageSize: v = h, onPageChange: y, onNextPress: b, onPreviousPress: x, onPageSizeChange: S, onPageHover: C, itemLabel: w, ...T } = r, E = l(), { t: D } = c("unity"), [O, k] = i(v), A = { pageCount: f, defaultPage: g, currentPage: m, onPageChange: y, onNextPress: b, onPreviousPress: x, onPageHover: C }, j = Math.max(((m ?? g ?? 1) - 1) * h + 1, 1), M = Math.min(j + h - 1, p), N = w ?? ((e) => D((e) => e.unity.component.table.pagination.item, { count: e })), P = N(p), F = N(Number(O)); return /* @__PURE__ */ s("div", { "data-dd-privacy": "allow", ...T, ref: a, className: u(), "data-unity-slot": "table-pagination", children: [ /* @__PURE__ */ o("div", { className: "uy:justify-self-start", children: /* @__PURE__ */ o("span", { id: `table-pagination-${E}-label`, className: "uy:typography-body uy:text-content-neutral", children: D((e) => f === 0 ? e.unity.component.table.pagination.label.empty : e.unity.component.table.pagination.label.range, { startRow: j, endRow: M, totalRows: p, itemLabel: P }) }) }), /* @__PURE__ */ o("div", { className: "uy:justify-self-center", children: f > 1 && /* @__PURE__ */ o(n, { ...A, "aria-labelledby": `table-pagination-${E}-label` }) }), /* @__PURE__ */ o("div", { className: "uy:justify-self-end", children: /* @__PURE__ */ s("form", { className: "uy:flex uy:gap-100 uy:items-center", children: [/* @__PURE__ */ o("label", { className: "uy:shrink-0", id: `table-pagination-${E}-pagesize-label`, htmlFor: `table-pagination-${E}-pagesize-select`, children: D((e) => e.unity.component.table.pagination.pageSizeControlLabel, { itemLabel: F }) }), /* @__PURE__ */ o("div", { className: "uy:grow-0 uy:w-1000", children: /* @__PURE__ */ o(e, { id: `table-pagination-${E}-pagesize-select`, items: _, placeholder: "", value: `${O}`, onChange: (e) => { let t = parseInt(e, 10); S?.(t), k(t); }, "aria-labelledby": `table-pagination-${E}-pagesize-label`, children: (e) => /* @__PURE__ */ o(t, { id: e.value, children: e.label }) }) })] }) }) ] }); }); f.displayName = "TablePagination"; //#endregion export { f as TablePagination, u as tablePagination };