@allxsmith/bestax-bulma 5.16.11 → 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
@@ -1673,6 +1673,75 @@ const Breadcrumb = ({ className, alignment, separator, size, children, ...props
1673
1673
  return (jsxRuntime.jsx("nav", { className: breadcrumbClasses, "aria-label": "breadcrumbs", ...rest, children: jsxRuntime.jsx("ul", { children: children }) }));
1674
1674
  };
1675
1675
 
1676
+ /**
1677
+ * The runtime mirror of `AnchorOnlyAttributes`, keyed so the two cannot drift.
1678
+ *
1679
+ * `Record<keyof …, true>` is what links them: the day React adds an anchor
1680
+ * attribute, every component deriving its props from `as` accepts it and this
1681
+ * object stops compiling until it is named here. A plain array beside a derived
1682
+ * type drifts in the one direction that matters — the type accepts the new
1683
+ * attribute and the filter lets it leak onto a `<div>`.
1684
+ */
1685
+ const ANCHOR_ONLY_ATTRS = {
1686
+ href: true,
1687
+ target: true,
1688
+ download: true,
1689
+ hrefLang: true,
1690
+ ping: true,
1691
+ referrerPolicy: true,
1692
+ media: true,
1693
+ type: true,
1694
+ };
1695
+ /**
1696
+ * `props` without the keys named in `strip`.
1697
+ *
1698
+ * The SET is per component and deliberately not shared, because the right
1699
+ * answer differs and the differences are principled: how open the component's
1700
+ * `as` is, and which of these attributes its own tags legitimately take. What
1701
+ * IS shared is the derived source of truth above and this function. Each caller
1702
+ * declares its delta next to the set it passes, which is the only place that
1703
+ * stays true when a component's `as` changes.
1704
+ */
1705
+ function omitAttrs(props, strip) {
1706
+ const out = {};
1707
+ // `Reflect.ownKeys`, not `Object.entries`: the latter drops symbol-keyed props.
1708
+ // React enumerates props with `for...in`, which never reports a symbol, so
1709
+ // nothing renders differently either way. It is not the same change for all
1710
+ // three callers: Menu filtered by rest-destructure and kept them already,
1711
+ // while Dropdown and Level filtered through `Object.entries` and did not, so
1712
+ // this restores one and widens two. Symbols are the only shape where those
1713
+ // two disagreed, and keeping them is the side a spread is on.
1714
+ for (const key of Reflect.ownKeys(props)) {
1715
+ // Enumerability, for the same reason in the other direction: `Reflect.ownKeys`
1716
+ // also reports NON-enumerable own props, which every filter this replaced left
1717
+ // behind. Copying one out would both add a prop the old code dropped and make
1718
+ // it enumerable on the way, so widening the key source must not widen this.
1719
+ if (!Object.prototype.propertyIsEnumerable.call(props, key))
1720
+ continue;
1721
+ const value = props[key];
1722
+ // `hasOwnProperty`, not `key in strip`: `in` walks the prototype chain, so a
1723
+ // prop named `toString`, `valueOf`, `constructor` or `hasOwnProperty` was
1724
+ // stripped although no caller named it — and anything written to
1725
+ // `Object.prototype` would start deleting props that share its keys.
1726
+ if (typeof key === 'symbol' ||
1727
+ !Object.prototype.hasOwnProperty.call(strip, key)) {
1728
+ // `defineProperty`, not `out[key] = value`: assignment consults the
1729
+ // prototype chain for a setter, and `__proto__` has one. A prop named
1730
+ // `__proto__` would be swallowed by it — dropped from the result AND
1731
+ // replacing the result's prototype with its value. A spread and a rest
1732
+ // destructure both DEFINE, which is what makes them immune, so this has
1733
+ // to define too.
1734
+ Object.defineProperty(out, key, {
1735
+ value,
1736
+ writable: true,
1737
+ enumerable: true,
1738
+ configurable: true,
1739
+ });
1740
+ }
1741
+ }
1742
+ return out;
1743
+ }
1744
+
1676
1745
  /**
1677
1746
  * Merges helper-emitted inline styles (e.g., `bulmaHelperStyles` from
1678
1747
  * `useBulmaClasses`) with a user-supplied `style` prop.
@@ -1749,6 +1818,34 @@ const CardComponent = ({ className, children, textColor, color, bgColor, hasShad
1749
1818
  hasCompoundComponents(children) &&
1750
1819
  children, hasFooter && (jsxRuntime.jsx("footer", { className: prefixedClassNames(classPrefix, 'card-footer'), children: Array.isArray(footer) ? (footer.map((item, idx) => (jsxRuntime.jsx("span", { className: prefixedClassNames(classPrefix, 'card-footer-item'), children: item }, idx)))) : (jsxRuntime.jsx("span", { className: prefixedClassNames(classPrefix, 'card-footer-item'), children: footer })) }))] }));
1751
1820
  };
1821
+ /**
1822
+ * The set withheld from a non-anchor `Card.FooterItem` (`span`/`button`): the
1823
+ * derived anchor-only attributes, minus `type` (also valid on a `<button>` as
1824
+ * `submit`/`button`/`reset`, so stripping it there would remove a working
1825
+ * attribute — the same trade `DropdownItem`'s own `STRIP_FROM_NON_ANCHOR`
1826
+ * accepts, in `./Dropdown.tsx`), plus `rel` (React declares it on
1827
+ * `HTMLAttributes` for every element, so the derived set alone would not
1828
+ * withhold it — the same addition `Level.Item` makes).
1829
+ */
1830
+ const STRIP_FROM_NON_ANCHOR$2 = (() => {
1831
+ const { type: _type, ...rest } = ANCHOR_ONLY_ATTRS;
1832
+ return { ...rest, rel: true };
1833
+ })();
1834
+ /**
1835
+ * The set withheld from a non-button `Card.FooterItem` (`span`/`a`), keyed so
1836
+ * it stops compiling until a button attribute React adds is named here.
1837
+ */
1838
+ const STRIP_FROM_NON_BUTTON = {
1839
+ disabled: true,
1840
+ form: true,
1841
+ formAction: true,
1842
+ formEncType: true,
1843
+ formMethod: true,
1844
+ formNoValidate: true,
1845
+ formTarget: true,
1846
+ name: true,
1847
+ value: true,
1848
+ };
1752
1849
  /**
1753
1850
  * Card header compound component. Wraps children in a `.card-header` element.
1754
1851
  *
@@ -1779,13 +1876,14 @@ const CardHeader = ({ className, children, centered, color, bgColor, textColor,
1779
1876
  * @param {CardHeaderTitleProps} props - Props for the CardHeaderTitle component.
1780
1877
  * @returns {JSX.Element} The rendered card header title.
1781
1878
  */
1782
- const CardHeaderTitle = ({ className, children, centered, color, bgColor, textColor, ...props }) => {
1879
+ const CardHeaderTitle = ({ as = 'div', className, children, centered, color, bgColor, textColor, ...props }) => {
1783
1880
  const { bulmaHelperClasses, rest } = useBulmaClasses({
1784
1881
  color: textColor ?? color,
1785
1882
  backgroundColor: bgColor,
1786
1883
  ...props,
1787
1884
  });
1788
- return (jsxRuntime.jsx("div", { className: classNames(usePrefixedClassNames('card-header-title', {
1885
+ const Tag = as;
1886
+ return (jsxRuntime.jsx(Tag, { className: classNames(usePrefixedClassNames('card-header-title', {
1789
1887
  'is-centered': centered,
1790
1888
  }), bulmaHelperClasses, className), ...rest, children: children }));
1791
1889
  };
@@ -1856,13 +1954,40 @@ const CardFooter = ({ className, children, color, bgColor, textColor, ...props }
1856
1954
  * @param {CardFooterItemProps} props - Props for the CardFooterItem component.
1857
1955
  * @returns {JSX.Element} The rendered card footer item.
1858
1956
  */
1859
- const CardFooterItem = ({ className, children, color, bgColor, textColor, ...props }) => {
1957
+ const CardFooterItem = ({ as = 'span', className, children, color, bgColor, textColor, ...props }) => {
1860
1958
  const { bulmaHelperClasses, rest } = useBulmaClasses({
1861
1959
  color: textColor ?? color,
1862
1960
  backgroundColor: bgColor,
1863
1961
  ...props,
1864
1962
  });
1865
- return (jsxRuntime.jsx("span", { className: classNames(usePrefixedClassNames('card-footer-item'), bulmaHelperClasses, className), ...rest, children: children }));
1963
+ const itemClasses = classNames(usePrefixedClassNames('card-footer-item'), bulmaHelperClasses, className);
1964
+ // The anchor's own attributes reach an `<a>` and nothing else, and the button's a
1965
+ // `<button>` — `STRIP_FROM_NON_ANCHOR` above names the anchor set and why `type`
1966
+ // stays while `rel` is added, and `STRIP_FROM_NON_BUTTON` the button set.
1967
+ if (as === 'a') {
1968
+ return (jsxRuntime.jsx("a", { className: itemClasses, ...omitAttrs(rest, STRIP_FROM_NON_BUTTON), children: children }));
1969
+ }
1970
+ const forwarded = omitAttrs(rest, STRIP_FROM_NON_ANCHOR$2);
1971
+ if (as === 'button') {
1972
+ const forwardedType = forwarded.type;
1973
+ return (jsxRuntime.jsx("button", { className: itemClasses, ...forwarded,
1974
+ // A footer item button must not submit an enclosing form by default —
1975
+ // `<button>` defaults to `type="submit"`, and a Save/Cancel action row
1976
+ // sitting in a form is the common case this `as` exists for.
1977
+ //
1978
+ // A MISSING `type` is not the only way that default arrives: `type` is
1979
+ // typed here as the `<a>` MIME string (`STRIP_FROM_NON_ANCHOR` above
1980
+ // says why it is not withheld), so `as="button" type="text/html"`
1981
+ // compiles, and HTML's INVALID-value default for a button's `type` is
1982
+ // submit too. So anything that is not one of the three native button
1983
+ // types falls back to `button` rather than being forwarded.
1984
+ type: forwardedType === 'submit' ||
1985
+ forwardedType === 'reset' ||
1986
+ forwardedType === 'button'
1987
+ ? forwardedType
1988
+ : 'button', children: children }));
1989
+ }
1990
+ return (jsxRuntime.jsx("span", { className: itemClasses, ...omitAttrs(forwarded, STRIP_FROM_NON_BUTTON), children: children }));
1866
1991
  };
1867
1992
  // Attach nested Title and Icon components to CardHeader
1868
1993
  const CardHeaderCompound = withSubComponents(CardHeader, {
@@ -1878,75 +2003,6 @@ const Card = withSubComponents(CardComponent, {
1878
2003
  FooterItem: CardFooterItem,
1879
2004
  }, 'Card');
1880
2005
 
1881
- /**
1882
- * The runtime mirror of `AnchorOnlyAttributes`, keyed so the two cannot drift.
1883
- *
1884
- * `Record<keyof …, true>` is what links them: the day React adds an anchor
1885
- * attribute, every component deriving its props from `as` accepts it and this
1886
- * object stops compiling until it is named here. A plain array beside a derived
1887
- * type drifts in the one direction that matters — the type accepts the new
1888
- * attribute and the filter lets it leak onto a `<div>`.
1889
- */
1890
- const ANCHOR_ONLY_ATTRS = {
1891
- href: true,
1892
- target: true,
1893
- download: true,
1894
- hrefLang: true,
1895
- ping: true,
1896
- referrerPolicy: true,
1897
- media: true,
1898
- type: true,
1899
- };
1900
- /**
1901
- * `props` without the keys named in `strip`.
1902
- *
1903
- * The SET is per component and deliberately not shared, because the right
1904
- * answer differs and the differences are principled: how open the component's
1905
- * `as` is, and which of these attributes its own tags legitimately take. What
1906
- * IS shared is the derived source of truth above and this function. Each caller
1907
- * declares its delta next to the set it passes, which is the only place that
1908
- * stays true when a component's `as` changes.
1909
- */
1910
- function omitAttrs(props, strip) {
1911
- const out = {};
1912
- // `Reflect.ownKeys`, not `Object.entries`: the latter drops symbol-keyed props.
1913
- // React enumerates props with `for...in`, which never reports a symbol, so
1914
- // nothing renders differently either way. It is not the same change for all
1915
- // three callers: Menu filtered by rest-destructure and kept them already,
1916
- // while Dropdown and Level filtered through `Object.entries` and did not, so
1917
- // this restores one and widens two. Symbols are the only shape where those
1918
- // two disagreed, and keeping them is the side a spread is on.
1919
- for (const key of Reflect.ownKeys(props)) {
1920
- // Enumerability, for the same reason in the other direction: `Reflect.ownKeys`
1921
- // also reports NON-enumerable own props, which every filter this replaced left
1922
- // behind. Copying one out would both add a prop the old code dropped and make
1923
- // it enumerable on the way, so widening the key source must not widen this.
1924
- if (!Object.prototype.propertyIsEnumerable.call(props, key))
1925
- continue;
1926
- const value = props[key];
1927
- // `hasOwnProperty`, not `key in strip`: `in` walks the prototype chain, so a
1928
- // prop named `toString`, `valueOf`, `constructor` or `hasOwnProperty` was
1929
- // stripped although no caller named it — and anything written to
1930
- // `Object.prototype` would start deleting props that share its keys.
1931
- if (typeof key === 'symbol' ||
1932
- !Object.prototype.hasOwnProperty.call(strip, key)) {
1933
- // `defineProperty`, not `out[key] = value`: assignment consults the
1934
- // prototype chain for a setter, and `__proto__` has one. A prop named
1935
- // `__proto__` would be swallowed by it — dropped from the result AND
1936
- // replacing the result's prototype with its value. A spread and a rest
1937
- // destructure both DEFINE, which is what makes them immune, so this has
1938
- // to define too.
1939
- Object.defineProperty(out, key, {
1940
- value,
1941
- writable: true,
1942
- enumerable: true,
1943
- configurable: true,
1944
- });
1945
- }
1946
- }
1947
- return out;
1948
- }
1949
-
1950
2006
  /**
1951
2007
  * Checks if code is running in a browser environment.
1952
2008
  * @deprecated Dropdown's internal SSR guard, exported by accident; it will
@@ -3150,6 +3206,38 @@ const warnDeprecatedColorProp = (component, value, hint) => {
3150
3206
  `a visual effect. It will be removed in the next major version. ${hint}`);
3151
3207
  };
3152
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
+ }
3153
3241
  /**
3154
3242
  * "Previous" navigation button.
3155
3243
  *
@@ -3157,9 +3245,9 @@ const warnDeprecatedColorProp = (component, value, hint) => {
3157
3245
  * @param {PaginationPreviousNextProps} props - Props for the PaginationPrevious component.
3158
3246
  * @returns {JSX.Element} The rendered previous button.
3159
3247
  */
3160
- const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-previous'), className, {
3248
+ const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-previous', {
3161
3249
  'is-disabled': disabled,
3162
- }), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
3250
+ }), className), "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, ...props, onClick: disabled
3163
3251
  ? e => {
3164
3252
  e.preventDefault();
3165
3253
  e.stopPropagation();
@@ -3172,9 +3260,7 @@ const PaginationPrevious = ({ className, disabled, children, ...props }) => (jsx
3172
3260
  * @param {PaginationPreviousNextProps} props - Props for the PaginationNext component.
3173
3261
  * @returns {JSX.Element} The rendered next button.
3174
3262
  */
3175
- const PaginationNext = ({ className, disabled, children, ...props }) => (jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-next'), className, {
3176
- 'is-disabled': disabled,
3177
- }), "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
3178
3264
  ? e => {
3179
3265
  e.preventDefault();
3180
3266
  e.stopPropagation();
@@ -3188,7 +3274,8 @@ const PaginationNext = ({ className, disabled, children, ...props }) => (jsxRunt
3188
3274
  * @returns {JSX.Element} The rendered pagination.
3189
3275
  * @see {@link https://bulma.io/documentation/components/pagination/ | Bulma Pagination documentation}
3190
3276
  */
3191
- 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);
3192
3279
  warnDeprecatedColorProp('Pagination', color, 'Use the textColor / bgColor helper props instead.');
3193
3280
  const { bulmaHelperClasses, rest } = useBulmaClasses({
3194
3281
  color: textColor,
@@ -3203,7 +3290,43 @@ const PaginationComponent = ({ color, textColor, bgColor, size, align, rounded,
3203
3290
  'is-rounded': rounded,
3204
3291
  });
3205
3292
  const paginationClasses = classNames(bulmaClasses, bulmaHelperClasses, className);
3206
- return (jsxRuntime.jsx("nav", { className: paginationClasses, role: "navigation", "aria-label": "pagination", ...rest, children: children }));
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 }));
3207
3330
  };
3208
3331
  /**
3209
3332
  * Container for page links and ellipsis.
@@ -3243,10 +3366,10 @@ const PaginationLink = ({ className, textColor, bgColor, active, disabled, onCli
3243
3366
  onClick(e);
3244
3367
  }
3245
3368
  };
3246
- return (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-link'), bulmaHelperClasses, className, {
3369
+ return (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: classNames(usePrefixedClassNames('pagination-link', {
3247
3370
  'is-current': active,
3248
3371
  'is-disabled': disabled,
3249
- }), "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 }) }));
3250
3373
  };
3251
3374
  /**
3252
3375
  * Ellipsis separator.