UNPKG

@payfit/unity-components

Version:

107 lines (106 loc) • 4.4 kB
import { Button as e } from "../../button/Button.js"; import { Label as t } from "../../label/Label.js"; import { useRef as n } from "react"; import { useButton as r } from "react-aria/useButton"; import { uyTv as i } from "@payfit/unity-themes"; import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime"; import { Trans as c, useTranslation as l } from "react-i18next"; import { Icon as u } from "@payfit/unity-icons"; import { useOverlay as d } from "react-aria/useOverlay"; import { useOverlayTrigger as f } from "react-aria/useOverlayTrigger"; //#region src/core/components/client-side-pagination/parts/PaginationJumpDialog.tsx var p = i({ slots: { jumpButton: "uy:sr-only uy:outline-none uy:focus:not-sr-only uy:focus:absolute uy:focus:bottom-full uy:focus:z-10 uy:focus:m-100 uy:focus:rounded-50 uy:focus:underline uy:focus:bg-transparent uy:focus:text-content-primary uy:focus:typography-action uy:focus:ring-2 uy:focus:ring-offset-2 uy:focus:ring-utility-focus-ring", jumpPopover: "uy:fixed uy:top-1/2 uy:left-1/2 uy:z-20 uy:transform uy:-translate-x-1/2 uy:-translate-y-1/2 uy:bg-surface-neutral uy:p-200 uy:rounded-200 uy:shadow-floating", jumpForm: "uy:flex uy:flex-col uy:gap-100", jumpFieldLabel: "uy:typography-body", jumpFieldWrapper: "uy:mt-50 uy:flex uy:w-full uy:items-center uy:h-500 uy:border uy:border-solid uy:rounded-100 uy:border-border-form-enabled uy:bg-surface-form-enabled uy:focus-within:outline-none uy:focus-within:ring-2 uy:focus-within:ring-utility-focus-ring uy:focus-within:ring-offset-2 uy:active:border-border-form-active", jumpInput: "uy:pl-100 uy:flex-1 uy:outline-none uy:appearance-none uy:[&::-webkit-outer-spin-button]:appearance-none uy:[&::-webkit-inner-spin-button]:appearance-none", jumpActions: "uy:flex uy:gap-150 uy:justify-end uy:mt-100" } }); function m({ pageCount: i, onJumpToPage: m, state: h }) { let { t: g } = l("unity"), _ = n(null), v = n(null), y = n(null), { triggerProps: b } = f({ type: "dialog" }, h, _), { buttonProps: x } = r({ ...b, "aria-label": g((e) => e.unity.component.pagination.jumpDialog.button.text) }, _), { overlayProps: S } = d({ isOpen: h.isOpen, onClose: h.close.bind(h), shouldCloseOnBlur: !0, isDismissable: !0 }, v), C = (e) => { e.preventDefault(); let t = parseInt(y.current?.value || "", 10); t >= 1 && t <= i && (m(t), h.close()); }, { jumpButton: w, jumpPopover: T, jumpForm: E, jumpFieldLabel: D, jumpFieldWrapper: O, jumpInput: k, jumpActions: A } = p(); return /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ o("button", { ...x, ref: _, className: w(), "aria-expanded": h.isOpen ? "true" : "false", children: /* @__PURE__ */ o(c, { ns: "unity", i18nKey: (e) => e.unity.component.pagination.jumpDialog.button.text }) }), h.isOpen && /* @__PURE__ */ o("div", { ...S, ref: v, className: T(), "aria-label": g((e) => e.unity.component.pagination.jumpDialog.overlay.label), children: /* @__PURE__ */ s("form", { onSubmit: C, className: E(), children: [ /* @__PURE__ */ o(t, { className: D(), htmlFor: `jump-to-page-${S.id}-input`, children: /* @__PURE__ */ o(c, { ns: "unity", i18nKey: (e) => e.unity.component.pagination.jumpDialog.input.label, values: { total: i } }) }), /* @__PURE__ */ s("div", { className: O(), children: [/* @__PURE__ */ o("input", { ref: y, type: "number", min: 1, max: i, className: k(), id: `jump-to-page-${S.id}-input`, autoFocus: !0, onKeyDown: (e) => { e.key === "Escape" && h.close(); } }), /* @__PURE__ */ o(u, { src: "CaretUpDownOutlined", role: "presentation", color: "content.neutral.low", className: "uy:mx-50", size: 20 })] }), /* @__PURE__ */ s("div", { className: A(), children: [/* @__PURE__ */ o(e, { variant: "ghost", onPress: h.close.bind(h), children: /* @__PURE__ */ o(c, { ns: "unity", i18nKey: (e) => e.unity.component.pagination.jumpDialog.action.cancel }) }), /* @__PURE__ */ o(e, { type: "submit", variant: "primary", children: /* @__PURE__ */ o(c, { ns: "unity", i18nKey: (e) => e.unity.component.pagination.jumpDialog.action.go }) })] }) ] }) })] }); } //#endregion export { m as PaginationJumpDialog };