flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
92 lines (88 loc) • 4.24 kB
JavaScript
'use client';
;
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var get = require('../../helpers/get.cjs');
var resolveProps = require('../../helpers/resolve-props.cjs');
var resolveTheme = require('../../helpers/resolve-theme.cjs');
var tailwindMerge = require('../../helpers/tailwind-merge.cjs');
var chevronLeftIcon = require('../../icons/chevron-left-icon.cjs');
var chevronRightIcon = require('../../icons/chevron-right-icon.cjs');
var provider = require('../../theme/provider.cjs');
var helpers = require('./helpers.cjs');
var PaginationButton = require('./PaginationButton.cjs');
var theme = require('./theme.cjs');
const Pagination = React.forwardRef((props, ref) => {
const provider$1 = provider.useThemeProvider();
const theme$1 = resolveTheme.useResolveTheme(
[theme.paginationTheme, provider$1.theme?.pagination, props.theme],
[get.get(provider$1.clearTheme, "pagination"), props.clearTheme],
[get.get(provider$1.applyTheme, "pagination"), props.applyTheme]
);
const {
className,
currentPage,
layout = "pagination",
nextLabel = "Next",
onPageChange,
previousLabel = "Previous",
renderPaginationButton = (props2) => /* @__PURE__ */ jsxRuntime.jsx(PaginationButton.PaginationButton, { ...props2 }),
showIcons: showIcon = false,
totalPages,
...restProps
} = resolveProps.resolveProps(props, provider$1.props?.pagination);
const lastPage = Math.min(Math.max(layout === "pagination" ? currentPage + 2 : currentPage + 4, 5), totalPages);
const firstPage = Math.max(1, lastPage - 4);
function goToNextPage() {
onPageChange(Math.min(currentPage + 1, totalPages));
}
function goToPreviousPage() {
onPageChange(Math.max(currentPage - 1, 1));
}
return /* @__PURE__ */ jsxRuntime.jsxs("nav", { ref, className: tailwindMerge.twMerge(theme$1.base, className), ...restProps, children: [
layout === "table" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: theme$1.layout.table.base, children: [
"Showing ",
/* @__PURE__ */ jsxRuntime.jsx("span", { className: theme$1.layout.table.span, children: firstPage }),
" to\xA0",
/* @__PURE__ */ jsxRuntime.jsx("span", { className: theme$1.layout.table.span, children: lastPage }),
" of\xA0",
/* @__PURE__ */ jsxRuntime.jsx("span", { className: theme$1.layout.table.span, children: totalPages }),
" Entries"
] }),
/* @__PURE__ */ jsxRuntime.jsxs("ul", { className: theme$1.pages.base, children: [
/* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
PaginationButton.PaginationNavigation,
{
className: tailwindMerge.twMerge(theme$1.pages.previous.base, showIcon && theme$1.pages.showIcon),
onClick: goToPreviousPage,
disabled: currentPage === 1,
children: [
showIcon && /* @__PURE__ */ jsxRuntime.jsx(chevronLeftIcon.ChevronLeftIcon, { "aria-hidden": true, className: theme$1.pages.previous.icon }),
previousLabel
]
}
) }),
layout === "pagination" && helpers.range(firstPage, lastPage).map((page) => /* @__PURE__ */ jsxRuntime.jsx("li", { "aria-current": page === currentPage ? "page" : void 0, children: renderPaginationButton({
className: tailwindMerge.twMerge(theme$1.pages.selector.base, currentPage === page && theme$1.pages.selector.active),
active: page === currentPage,
onClick: () => onPageChange(page),
children: page
}) }, page)),
/* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
PaginationButton.PaginationNavigation,
{
className: tailwindMerge.twMerge(theme$1.pages.next.base, showIcon && theme$1.pages.showIcon),
onClick: goToNextPage,
disabled: currentPage === totalPages,
children: [
nextLabel,
showIcon && /* @__PURE__ */ jsxRuntime.jsx(chevronRightIcon.ChevronRightIcon, { "aria-hidden": true, className: theme$1.pages.next.icon })
]
}
) })
] })
] });
});
Pagination.displayName = "Pagination";
exports.Pagination = Pagination;
//# sourceMappingURL=Pagination.cjs.map