@allxsmith/bestax-bulma 5.4.1 → 5.4.2

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
@@ -759,6 +759,11 @@ function DefaultAvatarIcon() {
759
759
  }
760
760
  const Avatar = ({ className, src, alt, name, initials, icon, size, shape = 'circle', color, as, href, target, rel, imageProps, style, ...props }) => {
761
761
  const [erroredSrc, setErroredSrc] = useState(undefined);
762
+ const [prevSrc, setPrevSrc] = useState(src);
763
+ if (src !== prevSrc) {
764
+ setPrevSrc(src);
765
+ setErroredSrc(undefined);
766
+ }
762
767
  const imgRef = useRef(null);
763
768
  const { bulmaHelperClasses, rest } = useBulmaClasses(props);
764
769
  const showImage = !!src && src !== erroredSrc;
@@ -801,10 +806,23 @@ const Avatar = ({ className, src, alt, name, initials, icon, size, shape = 'circ
801
806
  return (jsxs(Tag, { className: combinedClasses, style: { ...sizeStyle, ...style }, ...linkProps, ...a11yProps, ...rest, children: [showImage && (jsx("img", { ...imageProps, ref: imgRef, src: src, alt: alt || name || '', onError: e => {
802
807
  imageProps?.onError?.(e);
803
808
  setErroredSrc(src);
804
- } })), showInitials && (jsx("span", { className: initialsClass, children: resolvedInitials })), showIcon && icon, showDefaultIcon && jsx(DefaultAvatarIcon, {})] }));
809
+ } }, src)), showInitials && (jsx("span", { className: initialsClass, children: resolvedInitials })), showIcon && icon, showDefaultIcon && jsx(DefaultAvatarIcon, {})] }));
805
810
  };
806
811
  Avatar.displayName = 'Avatar';
807
812
 
813
+ function flattenChildren(children, keyPrefix = '') {
814
+ return React.Children.toArray(children).flatMap(child => {
815
+ if (!React.isValidElement(child))
816
+ return [];
817
+ if (child.type === React.Fragment) {
818
+ return flattenChildren(child.props.children, keyPrefix + child.key);
819
+ }
820
+ const el = child;
821
+ return [
822
+ keyPrefix ? React.cloneElement(el, { key: keyPrefix + el.key }) : el,
823
+ ];
824
+ });
825
+ }
808
826
  const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false, style, children, ...props }) => {
809
827
  const { bulmaHelperClasses, rest } = useBulmaClasses({ ...props });
810
828
  const isPresetSpacing = typeof spacing === 'string';
@@ -817,7 +835,7 @@ const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false,
817
835
  : undefined;
818
836
  const surplusClass = usePrefixedClassNames('is-surplus');
819
837
  const combinedClasses = classNames(avatarsClasses, bulmaHelperClasses, className);
820
- const childArray = React.Children.toArray(children).filter(React.isValidElement);
838
+ const childArray = flattenChildren(children);
821
839
  const maxCount = typeof max === 'number' && Number.isInteger(max) && max >= 0
822
840
  ? max
823
841
  : undefined;