Skip to content

Commit 37de4bb

Browse files
authored
Add usePortal prop to VuiTooltip. (#322)
1 parent 95958bd commit 37de4bb

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

src/docs/pages/tooltip/Tooltip.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import { BiEdit } from "react-icons/bi";
2-
import { VuiButtonPrimary, VuiIcon, VuiTooltip } from "../../../lib";
2+
import { VuiButtonPrimary, VuiIcon, VuiSpacer, VuiToggle, VuiTooltip } from "../../../lib";
3+
import { useState } from "react";
34

45
export const Tooltip = () => {
6+
const [usePortal, setUsePortal] = useState(false);
7+
58
return (
6-
<VuiTooltip tip="Watchers will be notified of your changes and an audit trail will be created.">
7-
<VuiButtonPrimary
8-
icon={
9-
<VuiIcon>
10-
<BiEdit />
11-
</VuiIcon>
12-
}
13-
color="neutral"
14-
href="https://www.vectara.com"
15-
>
16-
Edit
17-
</VuiButtonPrimary>
18-
</VuiTooltip>
9+
<>
10+
<VuiToggle checked={usePortal} onChange={(e) => setUsePortal(e.target.checked)} label="Use portal" />
11+
12+
<VuiSpacer size="m" />
13+
14+
<VuiTooltip tip="Watchers will be notified of your changes and an audit trail will be created.">
15+
<VuiButtonPrimary
16+
icon={
17+
<VuiIcon>
18+
<BiEdit />
19+
</VuiIcon>
20+
}
21+
color="neutral"
22+
href="https://www.vectara.com"
23+
>
24+
Edit
25+
</VuiButtonPrimary>
26+
</VuiTooltip>
27+
</>
1928
);
2029
};

src/lib/components/button/IconButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Props = {
2626
tooltip?: {
2727
darkTheme?: TooltipProps["darkTheme"];
2828
position?: TooltipProps["position"];
29+
usePortal?: TooltipProps["usePortal"];
2930
};
3031
};
3132

src/lib/components/tooltip/Tooltip.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { useState, cloneElement } from "react";
22
import { Tooltip, TooltipRefProps } from "react-tooltip";
33
import { useVuiContext } from "../context/Context";
4+
import { VuiPortal } from "../portal/Portal";
45

56
export type Props = {
67
children: React.ReactNode;
78
tip: React.ReactNode;
89
darkTheme?: boolean;
910
position?: TooltipRefProps["place"];
11+
usePortal?: boolean;
1012
};
1113

1214
const generateTooltipId = () => {
1315
return `tooltip-${Math.random().toString(36).slice(2, 9)}`;
1416
};
1517

16-
export const VuiTooltip = ({ children, darkTheme, position, tip }: Props) => {
18+
export const VuiTooltip = ({ children, darkTheme, position, tip, usePortal }: Props) => {
1719
const { getThemeStyle } = useVuiContext();
1820
const [id] = useState(generateTooltipId());
1921

@@ -25,13 +27,16 @@ export const VuiTooltip = ({ children, darkTheme, position, tip }: Props) => {
2527
// the light theme class in order to enable having a different theme than the
2628
// parent.
2729
const style = getThemeStyle(darkTheme ? "dark" : "light");
30+
const tooltip = (
31+
<Tooltip id={id} offset={10} className="vuiTooltip" style={style} opacity={1} place={position}>
32+
{tip}
33+
</Tooltip>
34+
);
2835

2936
return (
3037
<>
3138
{target}
32-
<Tooltip id={id} offset={10} className="vuiTooltip" style={style} opacity={1} place={position}>
33-
{tip}
34-
</Tooltip>
39+
{usePortal ? <VuiPortal>{tooltip}</VuiPortal> : tooltip}
3540
</>
3641
);
3742
};

0 commit comments

Comments
 (0)