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