@allxsmith/bestax-bulma 5.4.1 → 5.5.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
@@ -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;
@@ -789,23 +794,46 @@ const Avatar = ({ className, src, alt, name, initials, icon, size, shape = 'circ
789
794
  const combinedClasses = classNames(avatarClasses, bulmaHelperClasses, className);
790
795
  const initialsClass = usePrefixedClassNames('avatar-initials');
791
796
  const Tag = as ?? (href ? 'a' : 'figure');
792
- const isInteractive = Tag === 'a' || Tag === 'button';
797
+ const isInteractive = Tag === 'a' ||
798
+ Tag === 'button' ||
799
+ (typeof Tag !== 'string' && href != null);
793
800
  const isLinkLike = Tag === 'a' || typeof Tag !== 'string';
794
801
  const linkProps = isLinkLike ? { href, target, rel } : {};
802
+ const accessibleName = alt ?? name;
803
+ const isDecorative = alt === '' && !isInteractive;
795
804
  const a11yProps = showImage
796
- ? {}
797
- : {
798
- ...(isInteractive ? {} : { role: 'img' }),
799
- 'aria-label': alt || name || 'Avatar',
800
- };
801
- 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 => {
805
+ ? isInteractive && !accessibleName
806
+ ?
807
+ { 'aria-label': name || 'Avatar' }
808
+ : {}
809
+ : isDecorative
810
+ ? { 'aria-hidden': true }
811
+ : {
812
+ ...(isInteractive ? {} : { role: 'img' }),
813
+ 'aria-label': accessibleName || name || 'Avatar',
814
+ };
815
+ const buttonTypeProps = Tag === 'button' ? { type: 'button' } : {};
816
+ return (jsxs(Tag, { className: combinedClasses, style: { ...sizeStyle, ...style }, ...buttonTypeProps, ...linkProps, ...a11yProps, ...rest, children: [showImage && (jsx("img", { ...imageProps, ref: imgRef, src: src, alt: accessibleName ?? '', onError: e => {
802
817
  imageProps?.onError?.(e);
803
818
  setErroredSrc(src);
804
- } })), showInitials && (jsx("span", { className: initialsClass, children: resolvedInitials })), showIcon && icon, showDefaultIcon && jsx(DefaultAvatarIcon, {})] }));
819
+ } }, src)), showInitials && (jsx("span", { className: initialsClass, children: resolvedInitials })), showIcon && icon, showDefaultIcon && jsx(DefaultAvatarIcon, {})] }));
805
820
  };
806
821
  Avatar.displayName = 'Avatar';
807
822
 
808
- const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false, style, children, ...props }) => {
823
+ function flattenChildren(children, keyPrefix = '') {
824
+ return React.Children.toArray(children).flatMap(child => {
825
+ if (!React.isValidElement(child))
826
+ return [];
827
+ if (child.type === React.Fragment) {
828
+ return flattenChildren(child.props.children, keyPrefix + child.key);
829
+ }
830
+ const el = child;
831
+ return [
832
+ keyPrefix ? React.cloneElement(el, { key: keyPrefix + el.key }) : el,
833
+ ];
834
+ });
835
+ }
836
+ const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false, surplusLabel, style, children, ...props }) => {
809
837
  const { bulmaHelperClasses, rest } = useBulmaClasses({ ...props });
810
838
  const isPresetSpacing = typeof spacing === 'string';
811
839
  const avatarsClasses = usePrefixedClassNames('avatars', {
@@ -817,7 +845,7 @@ const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false,
817
845
  : undefined;
818
846
  const surplusClass = usePrefixedClassNames('is-surplus');
819
847
  const combinedClasses = classNames(avatarsClasses, bulmaHelperClasses, className);
820
- const childArray = React.Children.toArray(children).filter(React.isValidElement);
848
+ const childArray = flattenChildren(children);
821
849
  const maxCount = typeof max === 'number' && Number.isInteger(max) && max >= 0
822
850
  ? max
823
851
  : undefined;
@@ -828,7 +856,7 @@ const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false,
828
856
  return (jsxs("div", { className: combinedClasses, style: { ...spacingStyle, ...style }, ...rest, children: [visibleChildren.map(child => React.cloneElement(child, {
829
857
  ...(size !== undefined ? { size } : {}),
830
858
  ...(shape !== undefined ? { shape } : {}),
831
- })), overflowCount > 0 && (jsx(Avatar, { initials: `+${overflowCount}`, alt: `${overflowCount} more`, size: size, shape: shape, className: surplusClass }))] }));
859
+ })), overflowCount > 0 && (jsx(Avatar, { initials: `+${overflowCount}`, alt: surplusLabel?.(overflowCount) || `${overflowCount} more`, size: size, shape: shape, className: surplusClass }))] }));
832
860
  };
833
861
  Avatars.displayName = 'Avatars';
834
862
  Avatars.Avatar = Avatar;
@@ -854,7 +882,8 @@ const Badge = ({ className, badgeClassName, content, max = 99, dot = false, show
854
882
  content !== true &&
855
883
  content !== '' &&
856
884
  (!isZero || showZero);
857
- const shouldRender = dot || hasContent || invisible;
885
+ const zeroPlaceholder = isZero && !showZero && !dot && !invisible;
886
+ const shouldRender = dot || hasContent || invisible || zeroPlaceholder;
858
887
  const sanitizedMax = Number.isInteger(max) && max >= 0 ? max : 99;
859
888
  const displayValue = useMemo(() => {
860
889
  if (dot || !hasContent)
@@ -876,6 +905,7 @@ const Badge = ({ className, badgeClassName, content, max = 99, dot = false, show
876
905
  'is-dot': dot,
877
906
  'is-pulse': pulse,
878
907
  'is-invisible': invisible,
908
+ 'is-zero': zeroPlaceholder,
879
909
  });
880
910
  const pillClass = hasChildren
881
911
  ? classNames(badgeClasses, badgeClassName)