mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 07:35:52 +08:00
refactor: wrap tooltip text and remain file for tooltips (#3647)
This commit is contained in:
parent
92ba46b2f5
commit
05ea814c61
@ -0,0 +1,3 @@
|
|||||||
|
.overlay--text-wrap {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
89
frontend/src/components/TextToolTip/TextToolTip.tsx
Normal file
89
frontend/src/components/TextToolTip/TextToolTip.tsx
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import './TextToolTip.style.scss';
|
||||||
|
|
||||||
|
import { blue, grey } from '@ant-design/colors';
|
||||||
|
import {
|
||||||
|
QuestionCircleFilled,
|
||||||
|
QuestionCircleOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { Tooltip } from 'antd';
|
||||||
|
import { themeColors } from 'constants/theme';
|
||||||
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { popupContainer } from 'utils/selectPopupContainer';
|
||||||
|
|
||||||
|
import { style } from './constant';
|
||||||
|
|
||||||
|
function TextToolTip({
|
||||||
|
text,
|
||||||
|
url,
|
||||||
|
useFilledIcon = true,
|
||||||
|
urlText,
|
||||||
|
}: TextToolTipProps): JSX.Element {
|
||||||
|
const isDarkMode = useIsDarkMode();
|
||||||
|
|
||||||
|
const onClickHandler = (
|
||||||
|
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
|
||||||
|
): void => {
|
||||||
|
event.stopPropagation();
|
||||||
|
};
|
||||||
|
|
||||||
|
const overlay = useMemo(
|
||||||
|
() => (
|
||||||
|
<div className="overlay--text-wrap">
|
||||||
|
{`${text} `}
|
||||||
|
{url && (
|
||||||
|
<a
|
||||||
|
// Stopping event propagation on click so that parent click listener are not triggered
|
||||||
|
onClick={onClickHandler}
|
||||||
|
href={url}
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
{urlText || 'here'}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
[text, url, urlText],
|
||||||
|
);
|
||||||
|
|
||||||
|
const iconStyle = useMemo(
|
||||||
|
() => ({
|
||||||
|
...style,
|
||||||
|
color: isDarkMode ? themeColors.whiteCream : grey[0],
|
||||||
|
}),
|
||||||
|
[isDarkMode],
|
||||||
|
);
|
||||||
|
|
||||||
|
const iconOutlinedStyle = useMemo(
|
||||||
|
() => ({
|
||||||
|
...style,
|
||||||
|
color: isDarkMode ? themeColors.navyBlue : blue[6],
|
||||||
|
}),
|
||||||
|
[isDarkMode],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip getTooltipContainer={popupContainer} overlay={overlay}>
|
||||||
|
{useFilledIcon ? (
|
||||||
|
<QuestionCircleFilled style={iconStyle} />
|
||||||
|
) : (
|
||||||
|
<QuestionCircleOutlined style={iconOutlinedStyle} />
|
||||||
|
)}
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextToolTip.defaultProps = {
|
||||||
|
url: '',
|
||||||
|
urlText: '',
|
||||||
|
useFilledIcon: true,
|
||||||
|
};
|
||||||
|
interface TextToolTipProps {
|
||||||
|
url?: string;
|
||||||
|
text: string;
|
||||||
|
useFilledIcon?: boolean;
|
||||||
|
urlText?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextToolTip;
|
@ -1,87 +1,3 @@
|
|||||||
import { blue, grey } from '@ant-design/colors';
|
import TextToolTip from './TextToolTip';
|
||||||
import {
|
|
||||||
QuestionCircleFilled,
|
|
||||||
QuestionCircleOutlined,
|
|
||||||
} from '@ant-design/icons';
|
|
||||||
import { Tooltip } from 'antd';
|
|
||||||
import { themeColors } from 'constants/theme';
|
|
||||||
import { useIsDarkMode } from 'hooks/useDarkMode';
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import { popupContainer } from 'utils/selectPopupContainer';
|
|
||||||
|
|
||||||
import { style } from './styles';
|
|
||||||
|
|
||||||
function TextToolTip({
|
|
||||||
text,
|
|
||||||
url,
|
|
||||||
useFilledIcon = true,
|
|
||||||
urlText,
|
|
||||||
}: TextToolTipProps): JSX.Element {
|
|
||||||
const isDarkMode = useIsDarkMode();
|
|
||||||
|
|
||||||
const onClickHandler = (
|
|
||||||
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
|
|
||||||
): void => {
|
|
||||||
event.stopPropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
const overlay = useMemo(
|
|
||||||
() => (
|
|
||||||
<div>
|
|
||||||
{`${text} `}
|
|
||||||
{url && (
|
|
||||||
<a
|
|
||||||
// Stopping event propagation on click so that parent click listener are not triggered
|
|
||||||
onClick={onClickHandler}
|
|
||||||
href={url}
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
{urlText || 'here'}
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
[text, url, urlText],
|
|
||||||
);
|
|
||||||
|
|
||||||
const iconStyle = useMemo(
|
|
||||||
() => ({
|
|
||||||
...style,
|
|
||||||
color: isDarkMode ? themeColors.whiteCream : grey[0],
|
|
||||||
}),
|
|
||||||
[isDarkMode],
|
|
||||||
);
|
|
||||||
|
|
||||||
const iconOutlinedStyle = useMemo(
|
|
||||||
() => ({
|
|
||||||
...style,
|
|
||||||
color: isDarkMode ? themeColors.navyBlue : blue[6],
|
|
||||||
}),
|
|
||||||
[isDarkMode],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tooltip getTooltipContainer={popupContainer} overlay={overlay}>
|
|
||||||
{useFilledIcon ? (
|
|
||||||
<QuestionCircleFilled style={iconStyle} />
|
|
||||||
) : (
|
|
||||||
<QuestionCircleOutlined style={iconOutlinedStyle} />
|
|
||||||
)}
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextToolTip.defaultProps = {
|
|
||||||
url: '',
|
|
||||||
urlText: '',
|
|
||||||
useFilledIcon: true,
|
|
||||||
};
|
|
||||||
interface TextToolTipProps {
|
|
||||||
url?: string;
|
|
||||||
text: string;
|
|
||||||
useFilledIcon?: boolean;
|
|
||||||
urlText?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default TextToolTip;
|
export default TextToolTip;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user