@allxsmith/bestax-bulma 5.3.0 → 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
@@ -705,6 +705,213 @@ const Columns = ({ className, textColor, color: _fieldColor, bgColor, isCentered
705
705
  return (jsx("div", { className: columnsClasses, ...rest, children: children }));
706
706
  };
707
707
 
708
+ const avatarColors = [
709
+ 'primary',
710
+ 'link',
711
+ 'info',
712
+ 'success',
713
+ 'warning',
714
+ 'danger',
715
+ 'black',
716
+ 'dark',
717
+ 'light',
718
+ 'white',
719
+ ];
720
+ const autoAvatarColors = [
721
+ 'primary',
722
+ 'link',
723
+ 'info',
724
+ 'success',
725
+ 'warning',
726
+ 'danger',
727
+ ];
728
+ const avatarSizes = [
729
+ '16x16',
730
+ '24x24',
731
+ '32x32',
732
+ '48x48',
733
+ '64x64',
734
+ '96x96',
735
+ '128x128',
736
+ ];
737
+ function getInitialsFromName(name) {
738
+ const words = name.trim().split(/\s+/).filter(Boolean);
739
+ if (words.length === 0)
740
+ return '';
741
+ if (words.length === 1) {
742
+ return Array.from(words[0]).slice(0, 2).join('').toUpperCase();
743
+ }
744
+ const first = Array.from(words[0])[0];
745
+ const last = Array.from(words[words.length - 1])[0];
746
+ return (first + last).toUpperCase();
747
+ }
748
+ function getAutoColor(name) {
749
+ let hash = 0;
750
+ for (let i = 0; i < name.length; i++) {
751
+ hash = (hash << 5) - hash + name.charCodeAt(i);
752
+ hash |= 0;
753
+ }
754
+ const index = Math.abs(hash) % autoAvatarColors.length;
755
+ return autoAvatarColors[index];
756
+ }
757
+ function DefaultAvatarIcon() {
758
+ return (jsx("svg", { viewBox: "0 0 24 24", width: "60%", height: "60%", "aria-hidden": "true", children: jsx("path", { fill: "currentColor", d: "M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-4.42 0-9 2.24-9 5v2a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1v-2c0-2.76-4.58-5-9-5Z" }) }));
759
+ }
760
+ const Avatar = ({ className, src, alt, name, initials, icon, size, shape = 'circle', color, as, href, target, rel, imageProps, style, ...props }) => {
761
+ const [erroredSrc, setErroredSrc] = useState(undefined);
762
+ const [prevSrc, setPrevSrc] = useState(src);
763
+ if (src !== prevSrc) {
764
+ setPrevSrc(src);
765
+ setErroredSrc(undefined);
766
+ }
767
+ const imgRef = useRef(null);
768
+ const { bulmaHelperClasses, rest } = useBulmaClasses(props);
769
+ const showImage = !!src && src !== erroredSrc;
770
+ useEffect(() => {
771
+ const img = imgRef.current;
772
+ if (img && img.complete && img.naturalWidth === 0) {
773
+ setErroredSrc(src);
774
+ }
775
+ }, [src]);
776
+ const resolvedInitials = initials
777
+ ? initials.toUpperCase()
778
+ : name
779
+ ? getInitialsFromName(name)
780
+ : '';
781
+ const showInitials = !showImage && !!resolvedInitials;
782
+ const showIcon = !showImage && !showInitials && !!icon;
783
+ const showDefaultIcon = !showImage && !showInitials && !showIcon;
784
+ const resolvedColor = color ?? (name ? getAutoColor(name) : undefined);
785
+ const isPresetSize = typeof size === 'string' && avatarSizes.includes(size);
786
+ const sizeStyle = typeof size === 'number'
787
+ ? { width: size, height: size, fontSize: size / 2.5 }
788
+ : undefined;
789
+ const avatarClasses = usePrefixedClassNames('avatar', {
790
+ [`is-${size}`]: isPresetSize,
791
+ [`is-${shape}`]: shape,
792
+ [`is-${resolvedColor}`]: resolvedColor && !showImage && avatarColors.includes(resolvedColor),
793
+ });
794
+ const combinedClasses = classNames(avatarClasses, bulmaHelperClasses, className);
795
+ const initialsClass = usePrefixedClassNames('avatar-initials');
796
+ const Tag = as ?? (href ? 'a' : 'figure');
797
+ const isInteractive = Tag === 'a' || Tag === 'button';
798
+ const isLinkLike = Tag === 'a' || typeof Tag !== 'string';
799
+ const linkProps = isLinkLike ? { href, target, rel } : {};
800
+ const a11yProps = showImage
801
+ ? {}
802
+ : {
803
+ ...(isInteractive ? {} : { role: 'img' }),
804
+ 'aria-label': alt || name || 'Avatar',
805
+ };
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 => {
807
+ imageProps?.onError?.(e);
808
+ setErroredSrc(src);
809
+ } }, src)), showInitials && (jsx("span", { className: initialsClass, children: resolvedInitials })), showIcon && icon, showDefaultIcon && jsx(DefaultAvatarIcon, {})] }));
810
+ };
811
+ Avatar.displayName = 'Avatar';
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
+ }
826
+ const Avatars = ({ className, max, size, shape, spacing = 'md', spaced = false, style, children, ...props }) => {
827
+ const { bulmaHelperClasses, rest } = useBulmaClasses({ ...props });
828
+ const isPresetSpacing = typeof spacing === 'string';
829
+ const avatarsClasses = usePrefixedClassNames('avatars', {
830
+ [`is-spacing-${spacing}`]: isPresetSpacing,
831
+ 'is-spaced': spaced,
832
+ });
833
+ const spacingStyle = typeof spacing === 'number'
834
+ ? { '--bulma-avatars-spacing': `${spacing}px` }
835
+ : undefined;
836
+ const surplusClass = usePrefixedClassNames('is-surplus');
837
+ const combinedClasses = classNames(avatarsClasses, bulmaHelperClasses, className);
838
+ const childArray = flattenChildren(children);
839
+ const maxCount = typeof max === 'number' && Number.isInteger(max) && max >= 0
840
+ ? max
841
+ : undefined;
842
+ const overshoot = maxCount !== undefined ? childArray.length - maxCount : 0;
843
+ const clamp = maxCount !== undefined && overshoot >= 2;
844
+ const visibleChildren = clamp ? childArray.slice(0, maxCount) : childArray;
845
+ const overflowCount = clamp ? overshoot : 0;
846
+ return (jsxs("div", { className: combinedClasses, style: { ...spacingStyle, ...style }, ...rest, children: [visibleChildren.map(child => React.cloneElement(child, {
847
+ ...(size !== undefined ? { size } : {}),
848
+ ...(shape !== undefined ? { shape } : {}),
849
+ })), overflowCount > 0 && (jsx(Avatar, { initials: `+${overflowCount}`, alt: `${overflowCount} more`, size: size, shape: shape, className: surplusClass }))] }));
850
+ };
851
+ Avatars.displayName = 'Avatars';
852
+ Avatars.Avatar = Avatar;
853
+
854
+ const badgeColors = [
855
+ 'primary',
856
+ 'link',
857
+ 'info',
858
+ 'success',
859
+ 'warning',
860
+ 'danger',
861
+ 'black',
862
+ 'dark',
863
+ 'light',
864
+ 'white',
865
+ ];
866
+ const Badge = ({ className, badgeClassName, content, max = 99, dot = false, showZero = false, color = 'danger', position = 'top-right', overlap = 'square', pulse = false, invisible = false, children, ...props }) => {
867
+ const { bulmaHelperClasses, rest } = useBulmaClasses(props);
868
+ const hasChildren = children != null && children !== false;
869
+ const isZero = typeof content === 'number' && content === 0;
870
+ const hasContent = content != null &&
871
+ content !== false &&
872
+ content !== true &&
873
+ content !== '' &&
874
+ (!isZero || showZero);
875
+ const shouldRender = dot || hasContent || invisible;
876
+ const sanitizedMax = Number.isInteger(max) && max >= 0 ? max : 99;
877
+ const displayValue = useMemo(() => {
878
+ if (dot || !hasContent)
879
+ return undefined;
880
+ if (typeof content === 'number') {
881
+ return content > sanitizedMax ? `${sanitizedMax}+` : String(content);
882
+ }
883
+ return content;
884
+ }, [dot, hasContent, content, sanitizedMax]);
885
+ const ariaLabel = typeof displayValue === 'string' || typeof displayValue === 'number'
886
+ ? String(displayValue)
887
+ : undefined;
888
+ const wrapperClass = usePrefixedClassNames('badge-wrapper');
889
+ const badgeClasses = usePrefixedClassNames('badge', {
890
+ [`is-${color}`]: !!color && badgeColors.includes(color),
891
+ [`is-${position}`]: !!position && hasChildren,
892
+ [`is-overlap-${overlap}`]: !!overlap && hasChildren,
893
+ 'is-standalone': !hasChildren,
894
+ 'is-dot': dot,
895
+ 'is-pulse': pulse,
896
+ 'is-invisible': invisible,
897
+ });
898
+ const pillClass = hasChildren
899
+ ? classNames(badgeClasses, badgeClassName)
900
+ : classNames(badgeClasses, badgeClassName, bulmaHelperClasses, className);
901
+ const a11yProps = dot
902
+ ? { 'aria-hidden': true }
903
+ : {
904
+ role: 'status',
905
+ ...(ariaLabel !== undefined ? { 'aria-label': ariaLabel } : {}),
906
+ };
907
+ const indicator = shouldRender ? (jsx("span", { className: pillClass, ...a11yProps, ...(hasChildren ? {} : rest), children: !dot && displayValue })) : null;
908
+ if (!hasChildren) {
909
+ return indicator;
910
+ }
911
+ return (jsxs("span", { className: classNames(wrapperClass, bulmaHelperClasses, className), ...rest, children: [children, indicator] }));
912
+ };
913
+ Badge.displayName = 'Badge';
914
+
708
915
  const validBreadcrumbAlignments = ['centered', 'right'];
709
916
  const validBreadcrumbSeparators = [
710
917
  'arrow',
@@ -8204,5 +8411,5 @@ const Section = ({ size, className, children, color, bgColor, textColor, ...prop
8204
8411
  return (jsx("section", { className: sectionClasses, ...rest, children: children }));
8205
8412
  };
8206
8413
 
8207
- export { Autocomplete, Block, Box, Breadcrumb, Button, Buttons, CardWithSubComponents as Card, Carousel, CarouselItem, Cell, Checkbox, Checkboxes, Code, Collapse, Column, Columns, ConfigProvider, Container, Content, Control, DateInput, DateInputBase, DateTimeInput, DateTimeInputBase, Delete, Dialog, DialogContainer, Divider, Dropdown, DropdownDivider, DropdownItem, Emphasis, Field, FieldBody, FieldLabel, Figure, File, Footer, Grid, Hero, HeroBody, HeroFoot, HeroHead, Icon, IconText, Image, Input, InputBase, Level, LevelItem, LevelLeft, LevelRight, Link, LinkButton, ListItem, Loading, Media, MediaContent, MediaLeft, MediaRight, Menu, MenuItem, MenuLabel, MenuList, MessageWithSubComponents as Message, Modal, Navbar, NavbarBrand, NavbarBurger, NavbarDivider, NavbarDropdown, NavbarDropdownMenu, NavbarEnd, NavbarItem, NavbarLink, NavbarMenu, NavbarStart, Notification, NotificationContainer, Numberinput, OrderedList, Pagination, PaginationEllipsis, PaginationLink, PaginationList, PaginationNext, PaginationPrevious, Panel, PanelBlock, PanelButtonBlock, PanelCheckboxBlock, PanelHeading, PanelIcon, PanelInputBlock, PanelTabs, Paragraph, Pre, Progress, Radio, Radios, Rate, Reveal, Section, Select, SelectBase, Sidebar, Skeleton, Slider, Span, Step, Steps, Strong, SubTitle, Switch, Tab, TabContentItem, TabItem, TabList, Table, Tabs, TabsContent, Tag, Taginput, Tags, Tbody, Td, TextArea, TextAreaBase, Tfoot, Th, Thead, Theme, TimeInput, TimeInputBase, Title, Toast, ToastContainer, Tooltip, Tr, UnorderedList, __test_exports__, checkboxColors, checkboxSizes, classNames, createPrefixedClassNames, dialog, isBrowser$1 as isBrowser, notification, prefixedClassNames, radioColors, radioSizes, switchColors, switchSizes, toast, useBulmaClasses, useClassPrefix, useColorClasses, useConfig, useFlexboxClasses, useIconLibrary, useInsideControl, useInsideField, useOtherClasses, usePrefixedClass, usePrefixedClassNames, useSpacingClasses, useTypographyClasses, useVisibilityClasses, validAlignContents, validAlignItems, validAlignSelfs, validAlignments$1 as validAlignments, validColorShades, validColors, validDisplays, validFlexDirections, validFlexGrowShrink, validFlexWraps, validFontFamilies, validJustifyContents, validSizes$1 as validSizes, validTableColors, validTextSizes, validTextTransforms, validTextWeights, validViewports, validVisibilities };
8414
+ export { Autocomplete, Avatar, Avatars, Badge, Block, Box, Breadcrumb, Button, Buttons, CardWithSubComponents as Card, Carousel, CarouselItem, Cell, Checkbox, Checkboxes, Code, Collapse, Column, Columns, ConfigProvider, Container, Content, Control, DateInput, DateInputBase, DateTimeInput, DateTimeInputBase, Delete, Dialog, DialogContainer, Divider, Dropdown, DropdownDivider, DropdownItem, Emphasis, Field, FieldBody, FieldLabel, Figure, File, Footer, Grid, Hero, HeroBody, HeroFoot, HeroHead, Icon, IconText, Image, Input, InputBase, Level, LevelItem, LevelLeft, LevelRight, Link, LinkButton, ListItem, Loading, Media, MediaContent, MediaLeft, MediaRight, Menu, MenuItem, MenuLabel, MenuList, MessageWithSubComponents as Message, Modal, Navbar, NavbarBrand, NavbarBurger, NavbarDivider, NavbarDropdown, NavbarDropdownMenu, NavbarEnd, NavbarItem, NavbarLink, NavbarMenu, NavbarStart, Notification, NotificationContainer, Numberinput, OrderedList, Pagination, PaginationEllipsis, PaginationLink, PaginationList, PaginationNext, PaginationPrevious, Panel, PanelBlock, PanelButtonBlock, PanelCheckboxBlock, PanelHeading, PanelIcon, PanelInputBlock, PanelTabs, Paragraph, Pre, Progress, Radio, Radios, Rate, Reveal, Section, Select, SelectBase, Sidebar, Skeleton, Slider, Span, Step, Steps, Strong, SubTitle, Switch, Tab, TabContentItem, TabItem, TabList, Table, Tabs, TabsContent, Tag, Taginput, Tags, Tbody, Td, TextArea, TextAreaBase, Tfoot, Th, Thead, Theme, TimeInput, TimeInputBase, Title, Toast, ToastContainer, Tooltip, Tr, UnorderedList, __test_exports__, checkboxColors, checkboxSizes, classNames, createPrefixedClassNames, dialog, isBrowser$1 as isBrowser, notification, prefixedClassNames, radioColors, radioSizes, switchColors, switchSizes, toast, useBulmaClasses, useClassPrefix, useColorClasses, useConfig, useFlexboxClasses, useIconLibrary, useInsideControl, useInsideField, useOtherClasses, usePrefixedClass, usePrefixedClassNames, useSpacingClasses, useTypographyClasses, useVisibilityClasses, validAlignContents, validAlignItems, validAlignSelfs, validAlignments$1 as validAlignments, validColorShades, validColors, validDisplays, validFlexDirections, validFlexGrowShrink, validFlexWraps, validFontFamilies, validJustifyContents, validSizes$1 as validSizes, validTableColors, validTextSizes, validTextTransforms, validTextWeights, validViewports, validVisibilities };
8208
8415
  //# sourceMappingURL=index.esm.js.map