@allxsmith/bestax-bulma 5.17.0 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -3206,6 +3206,38 @@ const warnDeprecatedColorProp = (component, value, hint) => {
|
|
|
3206
3206
|
`a visual effect. It will be removed in the next major version. ${hint}`);
|
|
3207
3207
|
};
|
|
3208
3208
|
|
|
3209
|
+
/** A count read as a whole number from zero, or `fallback` when it's no number. */
|
|
3210
|
+
function whole(count, fallback) {
|
|
3211
|
+
return Number.isFinite(count) ? Math.max(Math.floor(count), 0) : fallback;
|
|
3212
|
+
}
|
|
3213
|
+
function range(from, to) {
|
|
3214
|
+
return Array.from({ length: Math.max(to - from + 1, 0) }, (_, i) => from + i);
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* The pages to show for `current` of `total`: the first and last
|
|
3218
|
+
* `boundaries`, `siblings` on each side of the current one, and a gap for
|
|
3219
|
+
* each run left out. A gap of a single page shows that page instead, and the
|
|
3220
|
+
* window around the current page slides inward near either end, so the row
|
|
3221
|
+
* keeps its length as the page moves.
|
|
3222
|
+
*/
|
|
3223
|
+
function pageItems(total, current, siblings, boundaries) {
|
|
3224
|
+
const windowSize = siblings * 2 + 1;
|
|
3225
|
+
// Every page fits in the room the boundary pages, the window and two gaps take.
|
|
3226
|
+
if (total <= boundaries * 2 + windowSize + 2)
|
|
3227
|
+
return range(1, total);
|
|
3228
|
+
const lowest = boundaries + 2;
|
|
3229
|
+
const highest = total - boundaries - 1;
|
|
3230
|
+
const start = Math.min(Math.max(current - siblings, lowest), highest - windowSize + 1);
|
|
3231
|
+
const end = start + windowSize - 1;
|
|
3232
|
+
const gap = (from, to, name) => to === from ? [from] : [name];
|
|
3233
|
+
return [
|
|
3234
|
+
...range(1, boundaries),
|
|
3235
|
+
...gap(boundaries + 1, start - 1, 'start-gap'),
|
|
3236
|
+
...range(start, end),
|
|
3237
|
+
...gap(end + 1, total - boundaries, 'end-gap'),
|
|
3238
|
+
...range(total - boundaries + 1, total),
|
|
3239
|
+
];
|
|
3240
|
+
}
|
|
3209
3241
|
/**
|
|
3210
3242
|
* "Previous" navigation button.
|
|
3211
3243
|
*
|
|
@@ -3213,9 +3245,9 @@ const warnDeprecatedColorProp = (component, value, hint) => {
|
|
|
3213
3245
|
* @param {PaginationPreviousNextProps} props - Props for the PaginationPrevious component.
|
|
3214
3246
|
* @returns {JSX.Element} The rendered previous button.
|
|
3215
3247
|
*/
|
|
3216
|
-
const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-previous'
|
|
3248
|
+
const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-previous', {
|
|
3217
3249
|
'is-disabled': disabled,
|
|
3218
|
-
}), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
|
|
3250
|
+
}), className), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
|
|
3219
3251
|
? e => {
|
|
3220
3252
|
e.preventDefault();
|
|
3221
3253
|
e.stopPropagation();
|
|
@@ -3228,9 +3260,7 @@ const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsx
|
|
|
3228
3260
|
* @param {PaginationPreviousNextProps} props - Props for the PaginationNext component.
|
|
3229
3261
|
* @returns {JSX.Element} The rendered next button.
|
|
3230
3262
|
*/
|
|
3231
|
-
const PaginationNext = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-next'), className,
|
|
3232
|
-
'is-disabled': disabled,
|
|
3233
|
-
}), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
|
|
3263
|
+
const PaginationNext = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-next', { 'is-disabled': disabled }), className), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
|
|
3234
3264
|
? e => {
|
|
3235
3265
|
e.preventDefault();
|
|
3236
3266
|
e.stopPropagation();
|
|
@@ -3244,7 +3274,8 @@ const PaginationNext = ({ className, disabled, children, ...props }) => (jsxRunt
|
|
|
3244
3274
|
* @returns {JSX.Element} The rendered pagination.
|
|
3245
3275
|
* @see {@link https://bulma.io/documentation/components/pagination/ | Bulma Pagination documentation}
|
|
3246
3276
|
*/
|
|
3247
|
-
const PaginationComponent = ({ color, textColor, bgColor, size, align, rounded, className, children, ...props }) => {
|
|
3277
|
+
const PaginationComponent = ({ color, textColor, bgColor, size, align, rounded, total, current, onPageChange, siblingCount = 1, boundaryCount = 1, previousLabel = 'Previous', nextLabel = 'Next', disabled, getPageHref, getPageLabel, className, children, ...props }) => {
|
|
3278
|
+
const [kept, setKept] = React.useState(1);
|
|
3248
3279
|
warnDeprecatedColorProp('Pagination', color, 'Use the textColor / bgColor helper props instead.');
|
|
3249
3280
|
const { bulmaHelperClasses, rest } = useBulmaClasses({
|
|
3250
3281
|
color: textColor,
|
|
@@ -3259,7 +3290,43 @@ const PaginationComponent = ({ color, textColor, bgColor, size, align, rounded,
|
|
|
3259
3290
|
'is-rounded': rounded,
|
|
3260
3291
|
});
|
|
3261
3292
|
const paginationClasses = classNames(bulmaClasses, bulmaHelperClasses, className);
|
|
3262
|
-
|
|
3293
|
+
// A child that renders nothing (`{show && …}` when false) is no children.
|
|
3294
|
+
const fromTotal = total !== undefined && React.Children.toArray(children).length === 0;
|
|
3295
|
+
let content = children;
|
|
3296
|
+
if (fromTotal) {
|
|
3297
|
+
const pages = Number.isFinite(total) ? Math.max(Math.floor(total), 0) : 0;
|
|
3298
|
+
// A current page that's no number reads as the first.
|
|
3299
|
+
const page = Math.min(Math.max(whole(current ?? kept, 1), 1), Math.max(pages, 1));
|
|
3300
|
+
const choose = (next) => {
|
|
3301
|
+
if (next === page)
|
|
3302
|
+
return;
|
|
3303
|
+
if (current === undefined)
|
|
3304
|
+
setKept(next);
|
|
3305
|
+
onPageChange?.(next);
|
|
3306
|
+
};
|
|
3307
|
+
/**
|
|
3308
|
+
* What a link to `target` is given, beside what it renders. With no
|
|
3309
|
+
* `getPageHref` it's a button; a link that's `off` goes nowhere.
|
|
3310
|
+
*/
|
|
3311
|
+
const linkTo = (target, off) => ({
|
|
3312
|
+
href: off || !getPageHref ? undefined : getPageHref(target),
|
|
3313
|
+
role: getPageHref ? undefined : 'button',
|
|
3314
|
+
// A link that's off is disabled too, and the parts drop its clicks.
|
|
3315
|
+
onClick: () => choose(target),
|
|
3316
|
+
onKeyDown: getPageHref
|
|
3317
|
+
? undefined
|
|
3318
|
+
: (e) => {
|
|
3319
|
+
if (off || (e.key !== 'Enter' && e.key !== ' '))
|
|
3320
|
+
return;
|
|
3321
|
+
e.preventDefault();
|
|
3322
|
+
choose(target);
|
|
3323
|
+
},
|
|
3324
|
+
});
|
|
3325
|
+
const atStart = disabled || page <= 1;
|
|
3326
|
+
const atEnd = disabled || page >= pages;
|
|
3327
|
+
content = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(PaginationPrevious, { disabled: atStart, ...linkTo(page - 1, atStart), children: previousLabel }), jsxRuntime.jsx(PaginationNext, { disabled: atEnd, ...linkTo(page + 1, atEnd), children: nextLabel }), jsxRuntime.jsx(PaginationList, { children: pageItems(pages, page, whole(siblingCount, 1), whole(boundaryCount, 1)).map(item => typeof item === 'number' ? (jsxRuntime.jsx(PaginationLink, { "aria-label": getPageLabel ? getPageLabel(item) : `Page ${item}`, active: item === page, disabled: disabled, ...linkTo(item, Boolean(disabled)), children: item }, item)) : (jsxRuntime.jsx(PaginationEllipsis, {}, item))) })] }));
|
|
3328
|
+
}
|
|
3329
|
+
return (jsxRuntime.jsx("nav", { className: paginationClasses, role: "navigation", "aria-label": "pagination", ...rest, children: content }));
|
|
3263
3330
|
};
|
|
3264
3331
|
/**
|
|
3265
3332
|
* Container for page links and ellipsis.
|
|
@@ -3299,10 +3366,10 @@ const PaginationLink = ({ className, textColor, bgColor, active, disabled, onCli
|
|
|
3299
3366
|
onClick(e);
|
|
3300
3367
|
}
|
|
3301
3368
|
};
|
|
3302
|
-
return (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-link'
|
|
3369
|
+
return (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-link', {
|
|
3303
3370
|
'is-current': active,
|
|
3304
3371
|
'is-disabled': disabled,
|
|
3305
|
-
}), "aria-current": active ? 'page' : undefined, "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, onClick: handleClick, ...rest, children: children }) }));
|
|
3372
|
+
}), bulmaHelperClasses, className), "aria-current": active ? 'page' : undefined, "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, onClick: handleClick, ...rest, children: children }) }));
|
|
3306
3373
|
};
|
|
3307
3374
|
/**
|
|
3308
3375
|
* Ellipsis separator.
|