@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
38 lines • 2.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pagination = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const useMediaDevice_1 = require("../../hooks/useMediaDevice/useMediaDevice");
const useStyles_1 = require("../../hooks/useStyles/useStyles");
const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary");
const fallbackComponent_1 = require("../../provider/errorBoundary/fallbackComponent");
// helpers
const getMaxCountersNumber_1 = require("./helpers/getMaxCountersNumber");
const paginationStandAlone_1 = require("./paginationStandAlone");
const PAGINATION_STYLES = 'PAGINATION_STYLES';
const PaginationComponent = react_1.default.forwardRef(({ variant, currentStep, maxStepsNumber, maxCountersNumber, ctv, ...props }, ref) => {
const styles = (0, useStyles_1.useStyles)(PAGINATION_STYLES, variant, ctv);
const device = (0, useMediaDevice_1.useMediaDevice)();
const limitCurrentStep = Math.max(0, Math.min(currentStep, maxStepsNumber - 1));
let paginationCountersNumber = styles.paginationCountersNumber?.[device]?.counters ?? 5;
if (maxCountersNumber && maxCountersNumber < maxStepsNumber) {
paginationCountersNumber = maxCountersNumber;
}
else {
paginationCountersNumber = Math.min(maxStepsNumber, paginationCountersNumber);
}
const stepsNumber = (0, getMaxCountersNumber_1.buildstepsNumber)(limitCurrentStep, maxStepsNumber, paginationCountersNumber, maxCountersNumber);
const stepActive = stepsNumber.indexOf(limitCurrentStep + 1);
const leftDisabled = limitCurrentStep === 0;
const rightDisabled = limitCurrentStep === maxStepsNumber - 1;
return ((0, jsx_runtime_1.jsx)(paginationStandAlone_1.PaginationStandAlone, { ref: ref, leftDisabled: leftDisabled, rightDisabled: rightDisabled, stepActive: stepActive, stepsNumber: stepsNumber, styles: styles, ...props }));
});
PaginationComponent.displayName = 'PaginationComponent';
const PaginationBoundary = (props, ref) => ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(fallbackComponent_1.FallbackComponent, { children: (0, jsx_runtime_1.jsx)(paginationStandAlone_1.PaginationStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(PaginationComponent, { ...props, ref: ref }) }));
const Pagination = react_1.default.forwardRef(PaginationBoundary);
exports.Pagination = Pagination;
//# sourceMappingURL=pagination.js.map