@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
32 lines • 2.11 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { useMediaDevice } from '../../hooks/useMediaDevice/useMediaDevice';
import { useStyles } from '../../hooks/useStyles/useStyles';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent';
// helpers
import { buildstepsNumber } from './helpers/getMaxCountersNumber';
import { PaginationStandAlone } from './paginationStandAlone';
const PAGINATION_STYLES = 'PAGINATION_STYLES';
const PaginationComponent = React.forwardRef(({ variant, currentStep, maxStepsNumber, maxCountersNumber, ctv, ...props }, ref) => {
const styles = useStyles(PAGINATION_STYLES, variant, ctv);
const device = 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 = buildstepsNumber(limitCurrentStep, maxStepsNumber, paginationCountersNumber, maxCountersNumber);
const stepActive = stepsNumber.indexOf(limitCurrentStep + 1);
const leftDisabled = limitCurrentStep === 0;
const rightDisabled = limitCurrentStep === maxStepsNumber - 1;
return (_jsx(PaginationStandAlone, { ref: ref, leftDisabled: leftDisabled, rightDisabled: rightDisabled, stepActive: stepActive, stepsNumber: stepsNumber, styles: styles, ...props }));
});
PaginationComponent.displayName = 'PaginationComponent';
const PaginationBoundary = (props, ref) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(PaginationStandAlone, { ...props, ref: ref }) }), children: _jsx(PaginationComponent, { ...props, ref: ref }) }));
const Pagination = React.forwardRef(PaginationBoundary);
export { Pagination };
//# sourceMappingURL=pagination.js.map