fis-component 0.0.80 → 0.0.81
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/cjs/index.js +62 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/Tooltip/index.d.ts +2 -0
- package/dist/cjs/types/src/components/Tooltip/useSmartTooltipPlacement.d.ts +5 -0
- package/dist/esm/index.js +62 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/Tooltip/index.d.ts +2 -0
- package/dist/esm/types/src/components/Tooltip/useSmartTooltipPlacement.d.ts +5 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -66443,18 +66443,58 @@ const DivTooltipSC = styled.div `
|
|
|
66443
66443
|
}
|
|
66444
66444
|
`;
|
|
66445
66445
|
|
|
66446
|
-
const
|
|
66446
|
+
const useSmartTooltipPlacement = () => {
|
|
66447
|
+
const [placement, setPlacement] = React.useState("right");
|
|
66448
|
+
const calculatePlacement = React.useCallback((triggerEl) => {
|
|
66449
|
+
if (!triggerEl)
|
|
66450
|
+
return;
|
|
66451
|
+
const rect = triggerEl.getBoundingClientRect();
|
|
66452
|
+
const viewportWidth = window.innerWidth;
|
|
66453
|
+
const leftSpace = rect.left;
|
|
66454
|
+
const rightSpace = viewportWidth - rect.right;
|
|
66455
|
+
if (rightSpace > leftSpace) {
|
|
66456
|
+
setPlacement("right");
|
|
66457
|
+
}
|
|
66458
|
+
else if (leftSpace > rightSpace) {
|
|
66459
|
+
setPlacement("left");
|
|
66460
|
+
}
|
|
66461
|
+
else {
|
|
66462
|
+
setPlacement("right");
|
|
66463
|
+
}
|
|
66464
|
+
}, []);
|
|
66465
|
+
return { placement, calculatePlacement };
|
|
66466
|
+
};
|
|
66467
|
+
|
|
66468
|
+
const FISTooltip = ({ className, variant = "primary", size = "md", title: titleProp, children, smartPlacement = false, ...rest }) => {
|
|
66447
66469
|
const theme = styled.useTheme();
|
|
66470
|
+
const triggerRef = React.useRef(null);
|
|
66471
|
+
const { placement, calculatePlacement } = useSmartTooltipPlacement();
|
|
66472
|
+
React.useEffect(() => {
|
|
66473
|
+
if (!smartPlacement)
|
|
66474
|
+
return;
|
|
66475
|
+
const el = triggerRef.current;
|
|
66476
|
+
if (!el)
|
|
66477
|
+
return;
|
|
66478
|
+
const handleMouseEnter = () => calculatePlacement(el);
|
|
66479
|
+
el.addEventListener("mouseenter", handleMouseEnter);
|
|
66480
|
+
calculatePlacement(el);
|
|
66481
|
+
return () => {
|
|
66482
|
+
el.removeEventListener("mouseenter", handleMouseEnter);
|
|
66483
|
+
};
|
|
66484
|
+
}, [smartPlacement, calculatePlacement]);
|
|
66485
|
+
const tooltipPlacement = smartPlacement
|
|
66486
|
+
? placement
|
|
66487
|
+
: rest.placement || "right";
|
|
66448
66488
|
if (isTooltipTitleCustom(titleProp)) {
|
|
66449
66489
|
// Create properly structured custom title
|
|
66450
66490
|
const title = (jsxRuntime.jsxs(DivTooltipContentWrapperSC, { children: [jsxRuntime.jsxs(DivTooltipContentSC, { children: [jsxRuntime.jsx(DivTooltipLabelSC, { children: titleProp.label }), titleProp.description && (jsxRuntime.jsx(DivTooltipDescriptionSC, { children: titleProp.description }))] }), titleProp.link && (jsxRuntime.jsx(ATooltipLinkSC, { href: titleProp.linkUrl, target: "_blank", rel: "noopener noreferrer", children: titleProp.link }))] }));
|
|
66451
|
-
return (jsxRuntime.jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsxRuntime.jsx(Tooltip, { color: variant === "primary"
|
|
66452
|
-
|
|
66453
|
-
|
|
66491
|
+
return (jsxRuntime.jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsxRuntime.jsx("span", { ref: smartPlacement ? triggerRef : undefined, children: jsxRuntime.jsx(Tooltip, { color: variant === "primary"
|
|
66492
|
+
? theme["com/tooltip/size-md/theme-black/background-color"]
|
|
66493
|
+
: theme["com/tooltip/size-md/theme-white/background-color"], title: title, getTooltipContainer: () => document.body, placement: tooltipPlacement, ...rest, children: children || jsxRuntime.jsx(Button$2, { children: "RT" }) }) }) }));
|
|
66454
66494
|
}
|
|
66455
|
-
return (jsxRuntime.jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsxRuntime.jsx(Tooltip, { color: variant === "primary"
|
|
66456
|
-
|
|
66457
|
-
|
|
66495
|
+
return (jsxRuntime.jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsxRuntime.jsx("span", { ref: smartPlacement ? triggerRef : undefined, children: jsxRuntime.jsx(Tooltip, { color: variant === "primary"
|
|
66496
|
+
? theme["com/tooltip/size-md/theme-black/background-color"]
|
|
66497
|
+
: theme["com/tooltip/size-md/theme-white/background-color"], title: titleProp, getTooltipContainer: () => document.body, placement: tooltipPlacement, ...rest, children: children || jsxRuntime.jsx(Button$2, { children: "RT" }) }) }) }));
|
|
66458
66498
|
};
|
|
66459
66499
|
FISTooltip.displayName = "FISTooltip";
|
|
66460
66500
|
|
|
@@ -67475,6 +67515,14 @@ const FISBadge = ({ className, icon, label, size = "sm", color, status, type = "
|
|
|
67475
67515
|
FISBadge.displayName = "FISBadge";
|
|
67476
67516
|
|
|
67477
67517
|
const FISMenuItem = ({ title, description, iconPrefix, type = "action", size = "md", selected = false, negative = false, disable, onClickMenu, }) => {
|
|
67518
|
+
const titleRef = React.useRef(null);
|
|
67519
|
+
const [isTruncated, setIsTruncated] = React.useState(false);
|
|
67520
|
+
React.useEffect(() => {
|
|
67521
|
+
const el = titleRef.current;
|
|
67522
|
+
if (el) {
|
|
67523
|
+
setIsTruncated(el.scrollWidth > el.clientWidth);
|
|
67524
|
+
}
|
|
67525
|
+
}, [title]);
|
|
67478
67526
|
const renderSuffixIcon = () => {
|
|
67479
67527
|
switch (type) {
|
|
67480
67528
|
case "action":
|
|
@@ -67491,9 +67539,12 @@ const FISMenuItem = ({ title, description, iconPrefix, type = "action", size = "
|
|
|
67491
67539
|
negative: negative,
|
|
67492
67540
|
}), "$size": size, "$selected": selected, "$type": type, "$disable": disable, onClick: onClickMenu, children: [iconPrefix && (jsxRuntime.jsx(DivPrefixIconSC, { className: classNames({
|
|
67493
67541
|
negative: negative,
|
|
67494
|
-
}), "$size": size, "$type": type, "$selected": selected, "$disable": disable, children: iconPrefix })), jsxRuntime.jsxs(DivContentSC$2, { children: [title &&
|
|
67495
|
-
|
|
67496
|
-
|
|
67542
|
+
}), "$size": size, "$type": type, "$selected": selected, "$disable": disable, children: iconPrefix })), jsxRuntime.jsxs(DivContentSC$2, { children: [title &&
|
|
67543
|
+
(isTruncated ? (jsxRuntime.jsx(FISTooltip, { title: title, variant: "primary", smartPlacement: true, children: jsxRuntime.jsx(PTitleSC$1, { ref: titleRef, className: classNames({
|
|
67544
|
+
negative: negative,
|
|
67545
|
+
}), "$selected": selected, "$type": type, "$disable": disable, children: title }) })) : (jsxRuntime.jsx(PTitleSC$1, { ref: titleRef, className: classNames({
|
|
67546
|
+
negative: negative,
|
|
67547
|
+
}), "$selected": selected, "$type": type, "$disable": disable, children: title }))), description && (jsxRuntime.jsx(PDescriptionSC, { className: classNames({
|
|
67497
67548
|
negative: negative,
|
|
67498
67549
|
}), "$type": type, "$selected": selected, "$disable": disable, children: description }))] }), renderSuffixIcon()] }));
|
|
67499
67550
|
};
|
|
@@ -67623,7 +67674,7 @@ const FISMenuSelect = ({ placeholder, groups, size = "md", multi = false, select
|
|
|
67623
67674
|
onClickMenu?.();
|
|
67624
67675
|
}
|
|
67625
67676
|
};
|
|
67626
|
-
return (jsxRuntime.jsxs(DivContainerSC$4, { "$maxHeight": maxHeight, className: className, children: [showInput && !combobox && (jsxRuntime.jsx(DivSearchSC, { children: jsxRuntime.jsx(FISInputText, { iconPrefix: jsxRuntime.jsx(SearchIcon, {}), placeholder: placeholder, value: search, onChange: handleSearchChange }) })), (shouldShowNoResult || noResult) && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(DivIconDataSC, { children: jsxRuntime.jsx(NoResultIcon, {}) }), jsxRuntime.jsx(PTitleSC$2, { children: noResultText })] })), noData && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(DivIconDataSC, { children: jsxRuntime.jsx(NoDataIcon, {}) }), jsxRuntime.jsx(PTitleSC$2, { children: noDataText })] })), loading && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(FISProgressCircular, { size: size, variant: "indeterminate" }), jsxRuntime.jsx(PTitleSC$2, { children: loadingText })] })), !shouldShowNoResult && !noData && !loading && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuContent, { "$removeSelectedGroup": !!removeSelectedGroup, children: groupsToRender.map((group, index) => (jsxRuntime.jsxs(DivWrapperSC$4, { children: [index !== 0 && jsxRuntime.jsx(FISMenuSection, { withDivider: true }), group?.groupLabel && (jsxRuntime.jsx(FISMenuSection, { label: group?.groupLabel })), group.items.map((item, idx) => (jsxRuntime.jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => handleItemClick(item), selected: selectedValues.includes(item.value), type: "select" }, idx)))] }, index))) }), removeSelectedGroup && (jsxRuntime.jsx(FixedBottomSection, { children: jsxRuntime.jsx(DivWrapperSC$4, { children: removeSelectedGroup.items.map((item, idx) => (jsxRuntime.jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => onChangeSelected?.([]), type: "select", iconPrefix: jsxRuntime.jsx(RemoveIcon, {}), negative: true }, idx))) }) }))] }))] }));
|
|
67677
|
+
return (jsxRuntime.jsxs(DivContainerSC$4, { "$maxHeight": maxHeight, className: className, children: [showInput && !combobox && (jsxRuntime.jsx(DivSearchSC, { children: jsxRuntime.jsx(FISInputText, { iconPrefix: jsxRuntime.jsx(SearchIcon, {}), placeholder: placeholder, value: search, onChange: handleSearchChange }) })), (shouldShowNoResult || noResult) && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(DivIconDataSC, { children: jsxRuntime.jsx(NoResultIcon, {}) }), jsxRuntime.jsx(PTitleSC$2, { children: noResultText })] })), noData && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(DivIconDataSC, { children: jsxRuntime.jsx(NoDataIcon, {}) }), jsxRuntime.jsx(PTitleSC$2, { children: noDataText })] })), loading && (jsxRuntime.jsxs(DivLoaderSC, { children: [jsxRuntime.jsx(FISProgressCircular, { size: size, variant: "indeterminate" }), jsxRuntime.jsx(PTitleSC$2, { children: loadingText })] })), !shouldShowNoResult && !noData && !loading && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuContent, { "$removeSelectedGroup": !!removeSelectedGroup, children: groupsToRender.map((group, index) => (jsxRuntime.jsxs(DivWrapperSC$4, { children: [index !== 0 && jsxRuntime.jsx(FISMenuSection, { withDivider: true }), group?.groupLabel && (jsxRuntime.jsx(FISMenuSection, { label: group?.groupLabel })), group.items.map((item, idx) => (jsxRuntime.jsx(FISTooltip, { title: item.label, variant: "primary", children: jsxRuntime.jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => handleItemClick(item), selected: selectedValues.includes(item.value), type: "select" }) }, idx)))] }, index))) }), removeSelectedGroup && (jsxRuntime.jsx(FixedBottomSection, { children: jsxRuntime.jsx(DivWrapperSC$4, { children: removeSelectedGroup.items.map((item, idx) => (jsxRuntime.jsx(FISTooltip, { title: item.label, variant: "primary", children: jsxRuntime.jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => onChangeSelected?.([]), type: "select", iconPrefix: jsxRuntime.jsx(RemoveIcon, {}), negative: true }) }, idx))) }) }))] }))] }));
|
|
67627
67678
|
};
|
|
67628
67679
|
FISMenuSelect.displayName = "FISMenuSelect";
|
|
67629
67680
|
|