react-better-html 1.1.285 → 1.1.287
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.js +112 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +123 -123
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7252,74 +7252,49 @@ var Table2 = memo23(TableComponent);
|
|
|
7252
7252
|
var Table_default = Table2;
|
|
7253
7253
|
|
|
7254
7254
|
// src/components/Tooltip.tsx
|
|
7255
|
-
import {
|
|
7255
|
+
import {
|
|
7256
|
+
memo as memo24,
|
|
7257
|
+
useCallback as useCallback16,
|
|
7258
|
+
useRef as useRef7,
|
|
7259
|
+
useState as useState12,
|
|
7260
|
+
useEffect as useEffect13,
|
|
7261
|
+
useLayoutEffect,
|
|
7262
|
+
forwardRef as forwardRef16,
|
|
7263
|
+
useImperativeHandle as useImperativeHandle3,
|
|
7264
|
+
useMemo as useMemo10
|
|
7265
|
+
} from "react";
|
|
7266
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
7256
7267
|
import { useTheme as useTheme26 } from "react-better-core";
|
|
7257
7268
|
import styled13, { css as css6 } from "styled-components";
|
|
7258
7269
|
import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
7259
|
-
var
|
|
7270
|
+
var isStartAlign = (align) => align === "left" || align === "top";
|
|
7271
|
+
var tooltipClosedTransform = (props) => ({
|
|
7260
7272
|
top: css6`
|
|
7261
|
-
|
|
7262
|
-
${props.align === "center" ? "left: 50%;" : props.align === "left" ? "left: 0;" : "right: 0;"}
|
|
7273
|
+
transform: translateY(${props.theme.styles.gap}px);
|
|
7263
7274
|
`,
|
|
7264
7275
|
bottom: css6`
|
|
7265
|
-
|
|
7266
|
-
${props.align === "center" ? "left: 50%;" : props.align === "left" ? "left: 0;" : "right: 0;"};
|
|
7276
|
+
transform: translateY(-${props.theme.styles.gap}px);
|
|
7267
7277
|
`,
|
|
7268
7278
|
left: css6`
|
|
7269
|
-
${props.
|
|
7270
|
-
right: calc(100% + ${props.gap}px + ${props.arrowSize}px);
|
|
7279
|
+
transform: translateX(${props.theme.styles.gap}px);
|
|
7271
7280
|
`,
|
|
7272
7281
|
right: css6`
|
|
7273
|
-
|
|
7274
|
-
left: calc(100% + ${props.gap}px + ${props.arrowSize}px);
|
|
7282
|
+
transform: translateX(-${props.theme.styles.gap}px);
|
|
7275
7283
|
`
|
|
7276
7284
|
});
|
|
7277
|
-
var tooltipPositionStyle = (props) => ({
|
|
7278
|
-
top: {
|
|
7279
|
-
opened: css6`
|
|
7280
|
-
transform: translateX(${props.align === "center" ? "-50%" : "0"});
|
|
7281
|
-
`,
|
|
7282
|
-
closed: css6`
|
|
7283
|
-
transform: translateX(${props.align === "center" ? "-50%" : "0"}) translateY(${props.theme.styles.gap}px);
|
|
7284
|
-
`
|
|
7285
|
-
},
|
|
7286
|
-
bottom: {
|
|
7287
|
-
opened: css6`
|
|
7288
|
-
transform: translateX(${props.align === "center" ? "-50%" : "0"});
|
|
7289
|
-
`,
|
|
7290
|
-
closed: css6`
|
|
7291
|
-
transform: translateX(${props.align === "center" ? "-50%" : "0"}) translateY(-${props.theme.styles.gap}px);
|
|
7292
|
-
`
|
|
7293
|
-
},
|
|
7294
|
-
left: {
|
|
7295
|
-
opened: css6`
|
|
7296
|
-
transform: translateY(${props.align === "center" ? "-50%" : "0"});
|
|
7297
|
-
`,
|
|
7298
|
-
closed: css6`
|
|
7299
|
-
transform: translateX(${props.theme.styles.gap}px) translateY(${props.align === "center" ? "-50%" : "0"});
|
|
7300
|
-
`
|
|
7301
|
-
},
|
|
7302
|
-
right: {
|
|
7303
|
-
opened: css6`
|
|
7304
|
-
transform: translateY(${props.align === "center" ? "-50%" : "0"});
|
|
7305
|
-
`,
|
|
7306
|
-
closed: css6`
|
|
7307
|
-
transform: translateX(-${props.theme.styles.gap}px) translateY(${props.align === "center" ? "-50%" : "0"});
|
|
7308
|
-
`
|
|
7309
|
-
}
|
|
7310
|
-
});
|
|
7311
7285
|
var TooltipContainer = styled13.div.withConfig({
|
|
7312
|
-
shouldForwardProp: (prop) => !["theme", "position", "
|
|
7286
|
+
shouldForwardProp: (prop) => !["theme", "position", "pointerEvents", "isOpen"].includes(prop)
|
|
7313
7287
|
})`
|
|
7314
|
-
position:
|
|
7288
|
+
position: fixed;
|
|
7289
|
+
top: 0;
|
|
7290
|
+
left: 0;
|
|
7315
7291
|
opacity: ${(props) => props.isOpen ? 1 : 0};
|
|
7316
7292
|
pointer-events: ${(props) => props.isOpen ? props.pointerEvents : "none"};
|
|
7317
7293
|
transition: ${(props) => props.theme.styles.transition};
|
|
7294
|
+
transition-property: opacity, transform;
|
|
7318
7295
|
z-index: 1000;
|
|
7319
7296
|
|
|
7320
|
-
${(props) =>
|
|
7321
|
-
|
|
7322
|
-
${(props) => props.isOpen ? tooltipPositionStyle(props)[props.position].opened : tooltipPositionStyle(props)[props.position].closed}
|
|
7297
|
+
${(props) => props.isOpen ? "transform: none;" : tooltipClosedTransform(props)[props.position]}
|
|
7323
7298
|
`;
|
|
7324
7299
|
var arrowStyle = (props, borderWidth) => ({
|
|
7325
7300
|
top: {
|
|
@@ -7412,6 +7387,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7412
7387
|
children
|
|
7413
7388
|
}, ref) {
|
|
7414
7389
|
const theme2 = useTheme26();
|
|
7390
|
+
const wrapperRef = useRef7(null);
|
|
7415
7391
|
const triggerHolderRef = useRef7(null);
|
|
7416
7392
|
const contentRef = useRef7(null);
|
|
7417
7393
|
const tooltipContainerRef = useRef7(null);
|
|
@@ -7422,31 +7398,15 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7422
7398
|
const gap = theme2.styles.gap / 2;
|
|
7423
7399
|
const outsideScreenGap = theme2.styles.gap / 2;
|
|
7424
7400
|
const totalGap = arrowSize + gap;
|
|
7401
|
+
const arrowSideSpace = theme2.styles.borderRadius;
|
|
7402
|
+
const arrowAnchorOffset = withArrow ? arrowSideSpace + arrowSize : 0;
|
|
7425
7403
|
const openTooltip = useCallback16(() => {
|
|
7426
7404
|
if (disabled) return;
|
|
7427
7405
|
if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
|
|
7428
7406
|
setIsOpen(true);
|
|
7429
7407
|
setIsOpenLate(true);
|
|
7430
|
-
setTimeout(() => {
|
|
7431
|
-
if (!tooltipContainerRef.current) return;
|
|
7432
|
-
if (!contentRef.current) return;
|
|
7433
|
-
const clientRects = tooltipContainerRef.current.getBoundingClientRect();
|
|
7434
|
-
if (clientRects) {
|
|
7435
|
-
const { width, height, x, y } = clientRects;
|
|
7436
|
-
const topOutside = y < 0;
|
|
7437
|
-
const bottomOutside = y + height > window.innerHeight;
|
|
7438
|
-
const leftOutside = x < 0;
|
|
7439
|
-
const rightOutside = x + width > window.innerWidth;
|
|
7440
|
-
if (topOutside) contentRef.current.style.transform = `translateY(${y * -1 + outsideScreenGap}px)`;
|
|
7441
|
-
if (bottomOutside)
|
|
7442
|
-
contentRef.current.style.transform = `translateY(${window.innerHeight - (y + height) - totalGap}px)`;
|
|
7443
|
-
if (leftOutside) contentRef.current.style.transform = `translateX(${x * -1 + outsideScreenGap}px)`;
|
|
7444
|
-
if (rightOutside)
|
|
7445
|
-
contentRef.current.style.transform = `translateX(${window.innerWidth - (x + width) - totalGap}px)`;
|
|
7446
|
-
}
|
|
7447
|
-
}, 1);
|
|
7448
7408
|
onOpen?.();
|
|
7449
|
-
}, [disabled, onOpen
|
|
7409
|
+
}, [disabled, onOpen]);
|
|
7450
7410
|
const closeTooltip = useCallback16(() => {
|
|
7451
7411
|
setIsOpen(false);
|
|
7452
7412
|
closeTimerRef.current = setTimeout(() => setIsOpenLate(false), 300);
|
|
@@ -7477,6 +7437,36 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7477
7437
|
},
|
|
7478
7438
|
[trigger, isOpen, closeTooltip]
|
|
7479
7439
|
);
|
|
7440
|
+
const updateContainerPosition = useCallback16(() => {
|
|
7441
|
+
if (!wrapperRef.current || !contentRef.current || !tooltipContainerRef.current) return;
|
|
7442
|
+
const wrapperRect = wrapperRef.current.getBoundingClientRect();
|
|
7443
|
+
const contentWidth2 = contentRef.current.offsetWidth;
|
|
7444
|
+
const contentHeight = contentRef.current.offsetHeight;
|
|
7445
|
+
const getCrossAxisStart = (wrapperStart, wrapperSize, contentSize) => {
|
|
7446
|
+
const wrapperCenter = wrapperStart + wrapperSize / 2;
|
|
7447
|
+
if (align === "center") return wrapperCenter - contentSize / 2;
|
|
7448
|
+
if (isStartAlign(align)) return arrowAnchorOffset ? wrapperCenter - arrowAnchorOffset : wrapperStart;
|
|
7449
|
+
return arrowAnchorOffset ? wrapperCenter + arrowAnchorOffset - contentSize : wrapperStart + wrapperSize - contentSize;
|
|
7450
|
+
};
|
|
7451
|
+
let expectedLeft;
|
|
7452
|
+
let expectedTop;
|
|
7453
|
+
if (position === "top" || position === "bottom") {
|
|
7454
|
+
expectedTop = position === "top" ? wrapperRect.top - totalGap - contentHeight : wrapperRect.bottom + totalGap;
|
|
7455
|
+
expectedLeft = getCrossAxisStart(wrapperRect.left, wrapperRect.width, contentWidth2);
|
|
7456
|
+
} else {
|
|
7457
|
+
expectedLeft = position === "left" ? wrapperRect.left - totalGap - contentWidth2 : wrapperRect.right + totalGap;
|
|
7458
|
+
expectedTop = getCrossAxisStart(wrapperRect.top, wrapperRect.height, contentHeight);
|
|
7459
|
+
}
|
|
7460
|
+
const getShift = (start, size, viewportSize) => {
|
|
7461
|
+
if (start < outsideScreenGap) return outsideScreenGap - start;
|
|
7462
|
+
if (start + size > viewportSize - outsideScreenGap) return viewportSize - outsideScreenGap - (start + size);
|
|
7463
|
+
return 0;
|
|
7464
|
+
};
|
|
7465
|
+
const shiftX = getShift(expectedLeft, contentWidth2, window.innerWidth);
|
|
7466
|
+
const shiftY = getShift(expectedTop, contentHeight, window.innerHeight);
|
|
7467
|
+
tooltipContainerRef.current.style.left = `${expectedLeft + shiftX}px`;
|
|
7468
|
+
tooltipContainerRef.current.style.top = `${expectedTop + shiftY}px`;
|
|
7469
|
+
}, [position, align, totalGap, outsideScreenGap, arrowAnchorOffset]);
|
|
7480
7470
|
useEffect13(() => {
|
|
7481
7471
|
if (trigger === "click") {
|
|
7482
7472
|
document.addEventListener("mousedown", onClickOutside);
|
|
@@ -7489,6 +7479,16 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7489
7479
|
if (!disabled) return;
|
|
7490
7480
|
closeTooltip();
|
|
7491
7481
|
}, [disabled]);
|
|
7482
|
+
useLayoutEffect(() => {
|
|
7483
|
+
if (!isOpen) return;
|
|
7484
|
+
updateContainerPosition();
|
|
7485
|
+
window.addEventListener("scroll", updateContainerPosition, true);
|
|
7486
|
+
window.addEventListener("resize", updateContainerPosition);
|
|
7487
|
+
return () => {
|
|
7488
|
+
window.removeEventListener("scroll", updateContainerPosition, true);
|
|
7489
|
+
window.removeEventListener("resize", updateContainerPosition);
|
|
7490
|
+
};
|
|
7491
|
+
}, [isOpen, updateContainerPosition]);
|
|
7492
7492
|
useImperativeHandle3(ref, () => {
|
|
7493
7493
|
return {
|
|
7494
7494
|
isOpen,
|
|
@@ -7505,6 +7505,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7505
7505
|
onClick: onClickHolder,
|
|
7506
7506
|
onMouseEnter,
|
|
7507
7507
|
onMouseLeave,
|
|
7508
|
+
ref: wrapperRef,
|
|
7508
7509
|
children: [
|
|
7509
7510
|
/* @__PURE__ */ jsx25(
|
|
7510
7511
|
Div_default,
|
|
@@ -7516,61 +7517,60 @@ var TooltipComponent = forwardRef16(function Tooltip({
|
|
|
7516
7517
|
children
|
|
7517
7518
|
}
|
|
7518
7519
|
),
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
}
|
|
7520
|
+
createPortal2(
|
|
7521
|
+
/* @__PURE__ */ jsx25(
|
|
7522
|
+
TooltipContainer,
|
|
7523
|
+
{
|
|
7524
|
+
theme: theme2,
|
|
7525
|
+
position,
|
|
7526
|
+
pointerEvents: contentPointerEvents,
|
|
7527
|
+
isOpen,
|
|
7528
|
+
role: "tooltip",
|
|
7529
|
+
ref: tooltipContainerRef,
|
|
7530
|
+
children: (isOpen || isOpenLate) && /* @__PURE__ */ jsxs21(Div_default, { position: "relative", ref: contentRef, children: [
|
|
7531
|
+
/* @__PURE__ */ jsx25(
|
|
7532
|
+
Div_default.box,
|
|
7533
|
+
{
|
|
7534
|
+
position: "relative",
|
|
7535
|
+
width: contentWidth,
|
|
7536
|
+
minWidth: contentMinWidth,
|
|
7537
|
+
backgroundColor: backgroundColor ?? theme2.colors.backgroundContent,
|
|
7538
|
+
boxShadow: "0px 10px 20px #00000020",
|
|
7539
|
+
paddingBlock: contentPaddingBlock ?? (isSmall ? theme2.styles.gap / 2 : theme2.styles.gap),
|
|
7540
|
+
paddingInline: contentPaddingInline ?? (asContextMenu ? 0 : isSmall ? theme2.styles.space / 2 : theme2.styles.space),
|
|
7541
|
+
overflow: asContextMenu ? "hidden" : void 0,
|
|
7542
|
+
children: content
|
|
7543
|
+
}
|
|
7544
|
+
),
|
|
7545
|
+
/* @__PURE__ */ jsx25(
|
|
7546
|
+
Div_default,
|
|
7547
|
+
{
|
|
7548
|
+
position: "absolute",
|
|
7549
|
+
width: position === "left" || position === "right" ? totalGap : "100%",
|
|
7550
|
+
height: position === "top" || position === "bottom" ? totalGap : "100%",
|
|
7551
|
+
top: position === "top" ? "100%" : position === "bottom" ? void 0 : 0,
|
|
7552
|
+
bottom: position === "bottom" ? "100%" : position === "top" ? void 0 : 0,
|
|
7553
|
+
left: position === "left" ? "100%" : position === "right" ? void 0 : 0,
|
|
7554
|
+
right: position === "right" ? "100%" : position === "left" ? void 0 : 0,
|
|
7555
|
+
borderTopLeftRadius: 999,
|
|
7556
|
+
borderTopRightRadius: 999
|
|
7557
|
+
}
|
|
7558
|
+
),
|
|
7559
|
+
withArrow && /* @__PURE__ */ jsx25(
|
|
7560
|
+
Arrow,
|
|
7561
|
+
{
|
|
7562
|
+
position,
|
|
7563
|
+
align,
|
|
7564
|
+
sideSpace: arrowSideSpace,
|
|
7565
|
+
size: arrowSize,
|
|
7566
|
+
color: backgroundColor ?? theme2.colors.backgroundContent,
|
|
7567
|
+
isOpen
|
|
7568
|
+
}
|
|
7569
|
+
)
|
|
7570
|
+
] })
|
|
7571
|
+
}
|
|
7572
|
+
),
|
|
7573
|
+
document.body
|
|
7574
7574
|
)
|
|
7575
7575
|
]
|
|
7576
7576
|
}
|