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
|
@@ -23,6 +23,8 @@ interface TooltipProps extends Omit<TooltipPropsAntd, "variant" | "title"> {
|
|
|
23
23
|
size?: TooltipSize;
|
|
24
24
|
/** Child elements that the tooltip wraps (optional) */
|
|
25
25
|
children?: React.ReactNode;
|
|
26
|
+
/** Enable smart placement (auto left/right) */
|
|
27
|
+
smartPlacement?: boolean;
|
|
26
28
|
}
|
|
27
29
|
declare const FISTooltip: FC<TooltipProps>;
|
|
28
30
|
export default FISTooltip;
|
package/dist/esm/index.js
CHANGED
|
@@ -66423,18 +66423,58 @@ const DivTooltipSC = styled.div `
|
|
|
66423
66423
|
}
|
|
66424
66424
|
`;
|
|
66425
66425
|
|
|
66426
|
-
const
|
|
66426
|
+
const useSmartTooltipPlacement = () => {
|
|
66427
|
+
const [placement, setPlacement] = useState("right");
|
|
66428
|
+
const calculatePlacement = useCallback((triggerEl) => {
|
|
66429
|
+
if (!triggerEl)
|
|
66430
|
+
return;
|
|
66431
|
+
const rect = triggerEl.getBoundingClientRect();
|
|
66432
|
+
const viewportWidth = window.innerWidth;
|
|
66433
|
+
const leftSpace = rect.left;
|
|
66434
|
+
const rightSpace = viewportWidth - rect.right;
|
|
66435
|
+
if (rightSpace > leftSpace) {
|
|
66436
|
+
setPlacement("right");
|
|
66437
|
+
}
|
|
66438
|
+
else if (leftSpace > rightSpace) {
|
|
66439
|
+
setPlacement("left");
|
|
66440
|
+
}
|
|
66441
|
+
else {
|
|
66442
|
+
setPlacement("right");
|
|
66443
|
+
}
|
|
66444
|
+
}, []);
|
|
66445
|
+
return { placement, calculatePlacement };
|
|
66446
|
+
};
|
|
66447
|
+
|
|
66448
|
+
const FISTooltip = ({ className, variant = "primary", size = "md", title: titleProp, children, smartPlacement = false, ...rest }) => {
|
|
66427
66449
|
const theme = useTheme$1();
|
|
66450
|
+
const triggerRef = useRef(null);
|
|
66451
|
+
const { placement, calculatePlacement } = useSmartTooltipPlacement();
|
|
66452
|
+
useEffect(() => {
|
|
66453
|
+
if (!smartPlacement)
|
|
66454
|
+
return;
|
|
66455
|
+
const el = triggerRef.current;
|
|
66456
|
+
if (!el)
|
|
66457
|
+
return;
|
|
66458
|
+
const handleMouseEnter = () => calculatePlacement(el);
|
|
66459
|
+
el.addEventListener("mouseenter", handleMouseEnter);
|
|
66460
|
+
calculatePlacement(el);
|
|
66461
|
+
return () => {
|
|
66462
|
+
el.removeEventListener("mouseenter", handleMouseEnter);
|
|
66463
|
+
};
|
|
66464
|
+
}, [smartPlacement, calculatePlacement]);
|
|
66465
|
+
const tooltipPlacement = smartPlacement
|
|
66466
|
+
? placement
|
|
66467
|
+
: rest.placement || "right";
|
|
66428
66468
|
if (isTooltipTitleCustom(titleProp)) {
|
|
66429
66469
|
// Create properly structured custom title
|
|
66430
66470
|
const title = (jsxs(DivTooltipContentWrapperSC, { children: [jsxs(DivTooltipContentSC, { children: [jsx(DivTooltipLabelSC, { children: titleProp.label }), titleProp.description && (jsx(DivTooltipDescriptionSC, { children: titleProp.description }))] }), titleProp.link && (jsx(ATooltipLinkSC, { href: titleProp.linkUrl, target: "_blank", rel: "noopener noreferrer", children: titleProp.link }))] }));
|
|
66431
|
-
return (jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsx(Tooltip, { color: variant === "primary"
|
|
66432
|
-
|
|
66433
|
-
|
|
66471
|
+
return (jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsx("span", { ref: smartPlacement ? triggerRef : undefined, children: jsx(Tooltip, { color: variant === "primary"
|
|
66472
|
+
? theme["com/tooltip/size-md/theme-black/background-color"]
|
|
66473
|
+
: theme["com/tooltip/size-md/theme-white/background-color"], title: title, getTooltipContainer: () => document.body, placement: tooltipPlacement, ...rest, children: children || jsx(Button$2, { children: "RT" }) }) }) }));
|
|
66434
66474
|
}
|
|
66435
|
-
return (jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsx(Tooltip, { color: variant === "primary"
|
|
66436
|
-
|
|
66437
|
-
|
|
66475
|
+
return (jsx(DivTooltipSC, { className: className, "$size": size, "$variant": variant, children: jsx("span", { ref: smartPlacement ? triggerRef : undefined, children: jsx(Tooltip, { color: variant === "primary"
|
|
66476
|
+
? theme["com/tooltip/size-md/theme-black/background-color"]
|
|
66477
|
+
: theme["com/tooltip/size-md/theme-white/background-color"], title: titleProp, getTooltipContainer: () => document.body, placement: tooltipPlacement, ...rest, children: children || jsx(Button$2, { children: "RT" }) }) }) }));
|
|
66438
66478
|
};
|
|
66439
66479
|
FISTooltip.displayName = "FISTooltip";
|
|
66440
66480
|
|
|
@@ -67455,6 +67495,14 @@ const FISBadge = ({ className, icon, label, size = "sm", color, status, type = "
|
|
|
67455
67495
|
FISBadge.displayName = "FISBadge";
|
|
67456
67496
|
|
|
67457
67497
|
const FISMenuItem = ({ title, description, iconPrefix, type = "action", size = "md", selected = false, negative = false, disable, onClickMenu, }) => {
|
|
67498
|
+
const titleRef = useRef(null);
|
|
67499
|
+
const [isTruncated, setIsTruncated] = useState(false);
|
|
67500
|
+
useEffect(() => {
|
|
67501
|
+
const el = titleRef.current;
|
|
67502
|
+
if (el) {
|
|
67503
|
+
setIsTruncated(el.scrollWidth > el.clientWidth);
|
|
67504
|
+
}
|
|
67505
|
+
}, [title]);
|
|
67458
67506
|
const renderSuffixIcon = () => {
|
|
67459
67507
|
switch (type) {
|
|
67460
67508
|
case "action":
|
|
@@ -67471,9 +67519,12 @@ const FISMenuItem = ({ title, description, iconPrefix, type = "action", size = "
|
|
|
67471
67519
|
negative: negative,
|
|
67472
67520
|
}), "$size": size, "$selected": selected, "$type": type, "$disable": disable, onClick: onClickMenu, children: [iconPrefix && (jsx(DivPrefixIconSC, { className: classNames({
|
|
67473
67521
|
negative: negative,
|
|
67474
|
-
}), "$size": size, "$type": type, "$selected": selected, "$disable": disable, children: iconPrefix })), jsxs(DivContentSC$2, { children: [title &&
|
|
67475
|
-
|
|
67476
|
-
|
|
67522
|
+
}), "$size": size, "$type": type, "$selected": selected, "$disable": disable, children: iconPrefix })), jsxs(DivContentSC$2, { children: [title &&
|
|
67523
|
+
(isTruncated ? (jsx(FISTooltip, { title: title, variant: "primary", smartPlacement: true, children: jsx(PTitleSC$1, { ref: titleRef, className: classNames({
|
|
67524
|
+
negative: negative,
|
|
67525
|
+
}), "$selected": selected, "$type": type, "$disable": disable, children: title }) })) : (jsx(PTitleSC$1, { ref: titleRef, className: classNames({
|
|
67526
|
+
negative: negative,
|
|
67527
|
+
}), "$selected": selected, "$type": type, "$disable": disable, children: title }))), description && (jsx(PDescriptionSC, { className: classNames({
|
|
67477
67528
|
negative: negative,
|
|
67478
67529
|
}), "$type": type, "$selected": selected, "$disable": disable, children: description }))] }), renderSuffixIcon()] }));
|
|
67479
67530
|
};
|
|
@@ -67603,7 +67654,7 @@ const FISMenuSelect = ({ placeholder, groups, size = "md", multi = false, select
|
|
|
67603
67654
|
onClickMenu?.();
|
|
67604
67655
|
}
|
|
67605
67656
|
};
|
|
67606
|
-
return (jsxs(DivContainerSC$4, { "$maxHeight": maxHeight, className: className, children: [showInput && !combobox && (jsx(DivSearchSC, { children: jsx(FISInputText, { iconPrefix: jsx(SearchIcon, {}), placeholder: placeholder, value: search, onChange: handleSearchChange }) })), (shouldShowNoResult || noResult) && (jsxs(DivLoaderSC, { children: [jsx(DivIconDataSC, { children: jsx(NoResultIcon, {}) }), jsx(PTitleSC$2, { children: noResultText })] })), noData && (jsxs(DivLoaderSC, { children: [jsx(DivIconDataSC, { children: jsx(NoDataIcon, {}) }), jsx(PTitleSC$2, { children: noDataText })] })), loading && (jsxs(DivLoaderSC, { children: [jsx(FISProgressCircular, { size: size, variant: "indeterminate" }), jsx(PTitleSC$2, { children: loadingText })] })), !shouldShowNoResult && !noData && !loading && (jsxs(Fragment, { children: [jsx(MenuContent, { "$removeSelectedGroup": !!removeSelectedGroup, children: groupsToRender.map((group, index) => (jsxs(DivWrapperSC$4, { children: [index !== 0 && jsx(FISMenuSection, { withDivider: true }), group?.groupLabel && (jsx(FISMenuSection, { label: group?.groupLabel })), group.items.map((item, idx) => (jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => handleItemClick(item), selected: selectedValues.includes(item.value), type: "select" }, idx)))] }, index))) }), removeSelectedGroup && (jsx(FixedBottomSection, { children: jsx(DivWrapperSC$4, { children: removeSelectedGroup.items.map((item, idx) => (jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => onChangeSelected?.([]), type: "select", iconPrefix: jsx(RemoveIcon, {}), negative: true }, idx))) }) }))] }))] }));
|
|
67657
|
+
return (jsxs(DivContainerSC$4, { "$maxHeight": maxHeight, className: className, children: [showInput && !combobox && (jsx(DivSearchSC, { children: jsx(FISInputText, { iconPrefix: jsx(SearchIcon, {}), placeholder: placeholder, value: search, onChange: handleSearchChange }) })), (shouldShowNoResult || noResult) && (jsxs(DivLoaderSC, { children: [jsx(DivIconDataSC, { children: jsx(NoResultIcon, {}) }), jsx(PTitleSC$2, { children: noResultText })] })), noData && (jsxs(DivLoaderSC, { children: [jsx(DivIconDataSC, { children: jsx(NoDataIcon, {}) }), jsx(PTitleSC$2, { children: noDataText })] })), loading && (jsxs(DivLoaderSC, { children: [jsx(FISProgressCircular, { size: size, variant: "indeterminate" }), jsx(PTitleSC$2, { children: loadingText })] })), !shouldShowNoResult && !noData && !loading && (jsxs(Fragment, { children: [jsx(MenuContent, { "$removeSelectedGroup": !!removeSelectedGroup, children: groupsToRender.map((group, index) => (jsxs(DivWrapperSC$4, { children: [index !== 0 && jsx(FISMenuSection, { withDivider: true }), group?.groupLabel && (jsx(FISMenuSection, { label: group?.groupLabel })), group.items.map((item, idx) => (jsx(FISTooltip, { title: item.label, variant: "primary", children: jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => handleItemClick(item), selected: selectedValues.includes(item.value), type: "select" }) }, idx)))] }, index))) }), removeSelectedGroup && (jsx(FixedBottomSection, { children: jsx(DivWrapperSC$4, { children: removeSelectedGroup.items.map((item, idx) => (jsx(FISTooltip, { title: item.label, variant: "primary", children: jsx(FISMenuItem, { title: item.label, description: item.description, size: size, onClickMenu: () => onChangeSelected?.([]), type: "select", iconPrefix: jsx(RemoveIcon, {}), negative: true }) }, idx))) }) }))] }))] }));
|
|
67607
67658
|
};
|
|
67608
67659
|
FISMenuSelect.displayName = "FISMenuSelect";
|
|
67609
67660
|
|