@allxsmith/bestax-bulma 5.13.0 → 5.14.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
@@ -2786,8 +2786,37 @@ function getIconClasses(library, name, variant, features) {
2786
2786
  const Icon = ({ className, textColor, bgColor, name, library, variant, features, libraryFeatures, // Deprecated but maintained for backward compatibility
2787
2787
  size, ariaLabel = 'icon', style, icon, // Capture and exclude the deprecated 'icon' prop from DOM
2788
2788
  color: _color, // Exclude 'color' prop if passed directly
2789
- containerClassName, ...restProps }) => {
2790
- // Handle deprecated 'icon' prop - parse it to extract the actual name
2789
+ containerClassName, children, ...restProps }) => {
2790
+ // Get the default icon library from context, fallback to 'fa' if not set
2791
+ const defaultLibrary = useIconLibrary();
2792
+ /**
2793
+ * Generates Bulma helper classes and separates out remaining props.
2794
+ * Note: variant, features, and libraryFeatures are excluded from props spread
2795
+ */
2796
+ const { bulmaHelperClasses, rest } = useBulmaClasses({
2797
+ color: textColor,
2798
+ backgroundColor: bgColor,
2799
+ ...restProps,
2800
+ });
2801
+ // Hoisted unconditionally to respect rules-of-hooks; the branches below
2802
+ // pick which result to consume.
2803
+ const defaultIconClasses = usePrefixedClassNames('icon', {
2804
+ [`is-${size}`]: size,
2805
+ });
2806
+ const sizeModifierClass = usePrefixedClassNames(size ? `is-${size}` : undefined);
2807
+ const bulmaClasses = containerClassName
2808
+ ? containerClassName
2809
+ : defaultIconClasses;
2810
+ const iconContainerClasses = classNames(bulmaClasses, containerClassName && size ? sizeModifierClass : undefined, bulmaHelperClasses, className);
2811
+ if (children !== undefined) {
2812
+ // `IconChildrenProps`: render the caller's node (an inline SVG, a `react-icons`
2813
+ // component, …) in place of a class-based glyph. Library/variant/features don't apply.
2814
+ return (jsx("span", { className: iconContainerClasses, "aria-label": ariaLabel, style: style, ...rest, children: children }));
2815
+ }
2816
+ // `name` is guaranteed once `children` is absent (`IconProps` is a discriminated union of
2817
+ // the two, and `IconChildrenProps['children']` excludes `undefined` so `children={undefined}`
2818
+ // can't slip past into this branch) — the cast only matters for legacy callers that bypass
2819
+ // the type and rely solely on the deprecated `icon` prop below.
2791
2820
  let finalName = name;
2792
2821
  if (!name && icon) {
2793
2822
  // If icon prop is provided instead of name, try to parse it
@@ -2806,31 +2835,16 @@ containerClassName, ...restProps }) => {
2806
2835
  }
2807
2836
  }
2808
2837
  }
2809
- // Get the default icon library from context, fallback to 'fa' if not set
2810
- const defaultLibrary = useIconLibrary();
2811
2838
  const finalLibrary = library || defaultLibrary || 'fa';
2812
2839
  // Normalize a redundant leading library prefix (e.g. "fa-check" -> "check" when the
2813
2840
  // library is 'fa'), so `name` behaves identically with or without the prefix.
2814
2841
  finalName = stripRedundantLibraryPrefix(finalName, finalLibrary);
2815
- /**
2816
- * Generates Bulma helper classes and separates out remaining props.
2817
- * Note: variant, features, and libraryFeatures are excluded from props spread
2818
- */
2819
- const { bulmaHelperClasses, rest } = useBulmaClasses({
2820
- color: textColor,
2821
- backgroundColor: bgColor,
2822
- ...restProps,
2823
- });
2824
- // Hoisted unconditionally to respect rules-of-hooks; the ternaries below
2825
- // pick which result to consume.
2826
- const defaultIconClasses = usePrefixedClassNames('icon', {
2827
- [`is-${size}`]: size,
2828
- });
2829
- const sizeModifierClass = usePrefixedClassNames(size ? `is-${size}` : undefined);
2830
- const bulmaClasses = containerClassName
2831
- ? containerClassName
2832
- : defaultIconClasses;
2833
- const iconContainerClasses = classNames(bulmaClasses, containerClassName && size ? sizeModifierClass : undefined, bulmaHelperClasses, className);
2842
+ if (!finalName) {
2843
+ // No glyph to name. Unreachable through the public type, but a plain-JS caller (or one
2844
+ // that casts) can land here, and building a class off an absent name produced a bogus
2845
+ // `fa-undefined` glyph. Render the bare container instead, matching the `children` branch.
2846
+ return (jsx("span", { className: iconContainerClasses, "aria-label": ariaLabel, style: style, ...rest }));
2847
+ }
2834
2848
  // Backward compatibility: if libraryFeatures is provided, parse it for variant and features
2835
2849
  let finalVariant = variant;
2836
2850
  let finalFeatures = features;
@@ -2949,8 +2963,9 @@ const PanelTabs = ({ className, children, ...props }) => (jsx("p", { className:
2949
2963
  */
2950
2964
  const PanelBlock = ({ className, active, children, ...props }) => (jsx("a", { className: classNames(usePrefixedClassNames('panel-block', { 'is-active': active }), className), ...props, children: children }));
2951
2965
  /**
2952
- * Icon wrapper with panel styling (renders as `<span class="panel-icon"><i/></span>`).
2953
- * Accepts all Icon props (`name`, `variant`, `features`, etc.)
2966
+ * Icon wrapper with panel styling (renders as `<span class="panel-icon">`, containing an
2967
+ * `<i/>` when a `name` is given, or the custom node passed as `children`).
2968
+ * Accepts all Icon props (`name`, `variant`, `features`, etc.), or `children` for a custom node.
2954
2969
  *
2955
2970
  * @function
2956
2971
  * @param {PanelIconProps} props - Props for the PanelIcon component.
@@ -5125,6 +5140,16 @@ const Figure = withSubComponents(FigureComponent, {
5125
5140
  Caption: FigureCaption,
5126
5141
  }, 'Figure');
5127
5142
 
5143
+ /**
5144
+ * Distinguishes an `IconProps` object from a plain custom node (an inline SVG, a `react-icons`
5145
+ * component, …) passed to a slot that accepts either.
5146
+ */
5147
+ function isIconProps$1(value) {
5148
+ return (typeof value === 'object' &&
5149
+ value !== null &&
5150
+ !React.isValidElement(value) &&
5151
+ ('name' in value || 'children' in value));
5152
+ }
5128
5153
  /**
5129
5154
  * The `IconText` component provides a Bulma-styled horizontal arrangement of one or more `Icon` components and optional text.
5130
5155
  *
@@ -5144,7 +5169,9 @@ const IconTextComponent = ({ className, textColor, color, bgColor, iconProps, ch
5144
5169
  });
5145
5170
  const bulmaClasses = usePrefixedClassNames('icon-text');
5146
5171
  const iconTextClasses = classNames(bulmaClasses, bulmaHelperClasses, className);
5147
- return (jsx("span", { className: iconTextClasses, ...rest, children: items ? (items.map((item, index) => (jsxs(React.Fragment, { children: [jsx(Icon, { ...item.iconProps }), item.text && jsx("span", { children: item.text })] }, index)))) : (jsxs(Fragment, { children: [iconProps && jsx(Icon, { ...iconProps }), children && jsx("span", { children: children })] })) }));
5172
+ return (jsx("span", { className: iconTextClasses, ...rest, children: items ? (items.map((item, index) => (jsxs(React.Fragment, { children: [item.iconProps &&
5173
+ (isIconProps$1(item.iconProps) ? (jsx(Icon, { ...item.iconProps })) : (jsx(Icon, { children: item.iconProps }))), item.text && jsx("span", { children: item.text })] }, index)))) : (jsxs(Fragment, { children: [iconProps &&
5174
+ (isIconProps$1(iconProps) ? (jsx(Icon, { ...iconProps })) : (jsx(Icon, { children: iconProps }))), children && jsx("span", { children: children })] })) }));
5148
5175
  };
5149
5176
  const IconText = withSubComponents(IconTextComponent, { Icon }, 'IconText');
5150
5177
 
@@ -6055,6 +6082,16 @@ const Checkbox = forwardRef(({ color, size, className, children, textColor, disa
6055
6082
  });
6056
6083
  Checkbox.displayName = 'Checkbox';
6057
6084
 
6085
+ /**
6086
+ * Distinguishes an `IconProps` object from a plain custom node (an inline SVG, a `react-icons`
6087
+ * component, …) passed to a slot that accepts either.
6088
+ */
6089
+ function isIconProps(value) {
6090
+ return (typeof value === 'object' &&
6091
+ value !== null &&
6092
+ !React.isValidElement(value) &&
6093
+ ('name' in value || 'children' in value));
6094
+ }
6058
6095
  const allowedColors = [...validColors, 'inherit', 'current'];
6059
6096
  /**
6060
6097
  * The `Control` component is a Bulma-styled wrapper for form controls (`Input`, `Select`, `TextArea`, etc.), supporting icons (left/right), loading state, expansion, size, and Bulma helper props for layout and color.
@@ -6086,15 +6123,19 @@ const Control = React.forwardRef(({ as = 'div', hasIconsLeft, hasIconsRight, isL
6086
6123
  backgroundColor: safeBgColor,
6087
6124
  ...restProps,
6088
6125
  });
6089
- // Prepare icon props for the shortcut
6090
- const leftIconProps = iconLeft ||
6126
+ // Prepare icon props for the shortcut. A truthiness test (not `!== undefined`)
6127
+ // so a falsy node from the idiomatic `iconLeft={cond && <Node/>}` / `iconLeft={maybe ?? null}`
6128
+ // pattern counts as "no icon" — otherwise `false`/`null` would reserve the icon column and
6129
+ // mount an empty `.icon` span. A falsy `iconLeft` also correctly falls through to the
6130
+ // `iconLeftName` shortcut, matching the pre-node behavior.
6131
+ const leftIconValue = iconLeft ||
6091
6132
  (iconLeftName
6092
6133
  ? {
6093
6134
  name: iconLeftName,
6094
6135
  size: iconLeftSize,
6095
6136
  }
6096
6137
  : undefined);
6097
- const rightIconProps = iconRight ||
6138
+ const rightIconValue = iconRight ||
6098
6139
  (iconRightName
6099
6140
  ? {
6100
6141
  name: iconRightName,
@@ -6102,15 +6143,17 @@ const Control = React.forwardRef(({ as = 'div', hasIconsLeft, hasIconsRight, isL
6102
6143
  }
6103
6144
  : undefined);
6104
6145
  const mainClass = usePrefixedClassNames('control', {
6105
- 'has-icons-left': hasIconsLeft || !!leftIconProps,
6106
- 'has-icons-right': hasIconsRight || !!rightIconProps,
6146
+ 'has-icons-left': hasIconsLeft || !!leftIconValue,
6147
+ 'has-icons-right': hasIconsRight || !!rightIconValue,
6107
6148
  'is-loading': isLoading,
6108
6149
  'is-expanded': isExpanded,
6109
6150
  [`is-${size}`]: !!size,
6110
6151
  });
6111
6152
  const controlClass = classNames(mainClass, bulmaHelperClasses, className);
6112
6153
  // --- FIX: Spread both restProps (for data-testid, etc) AND rest (from useBulmaClasses) ---
6113
- return (jsx(ControlProvider, { value: true, children: jsxs(Component, { className: controlClass, ref: ref, ...restProps, ...rest, children: [children, leftIconProps && leftIconProps.name && (jsx(Icon, { ...leftIconProps, className: prefixedClassNames(classPrefix, 'is-left') })), rightIconProps && rightIconProps.name && (jsx(Icon, { ...rightIconProps, className: prefixedClassNames(classPrefix, 'is-right') }))] }) }));
6154
+ return (jsx(ControlProvider, { value: true, children: jsxs(Component, { className: controlClass, ref: ref, ...restProps, ...rest, children: [children, leftIconValue &&
6155
+ (isIconProps(leftIconValue) ? (jsx(Icon, { ...leftIconValue, className: prefixedClassNames(classPrefix, 'is-left') })) : (jsx(Icon, { className: prefixedClassNames(classPrefix, 'is-left'), children: leftIconValue }))), rightIconValue &&
6156
+ (isIconProps(rightIconValue) ? (jsx(Icon, { ...rightIconValue, className: prefixedClassNames(classPrefix, 'is-right') })) : (jsx(Icon, { className: prefixedClassNames(classPrefix, 'is-right'), children: rightIconValue })))] }) }));
6114
6157
  });
6115
6158
  Control.displayName = 'Control';
6116
6159