Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Austenem/CAT-962 Show panel title on hover #3579

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-show-panel-title-on-hover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- If a title or description in a processed dataset helper panel is truncated, show the full text on hover in a tooltip.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CloudDownloadRounded from '@mui/icons-material/CloudDownloadRounded';
import { useIsDesktop } from 'js/hooks/media-queries';
import { WorkspacesIcon } from 'js/shared-styles/icons';
import { useAnimatedSidebarPosition } from 'js/shared-styles/sections/TableOfContents/hooks';
import { LineClamp } from 'js/shared-styles/text';
import { LineClampWithTooltip } from 'js/shared-styles/text';
import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';

import { formatDate } from 'date-fns/format';
Expand Down Expand Up @@ -53,7 +53,7 @@ interface HelperPanelBodyItemProps extends PropsWithChildren {
}

function HelperPanelBodyItem({ label, children, noWrap }: HelperPanelBodyItemProps) {
const body = noWrap ? <LineClamp lines={3}>{children}</LineClamp> : children;
const body = noWrap ? <LineClampWithTooltip lines={3}>{children}</LineClampWithTooltip> : children;
return (
<Stack direction="column">
<Typography variant="overline">{label}</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Typography from '@mui/material/Typography';

import { Entity } from 'js/components/types';
import LabelledSectionText from 'js/shared-styles/sections/LabelledSectionText';
import { LineClamp } from 'js/shared-styles/text';
import { LineClampWithTooltip } from 'js/shared-styles/text';

function CustomClamp({ children }: PropsWithChildren) {
return (
<LineClamp lines={3} component={Typography}>
{children}
</LineClamp>
<LineClampWithTooltip lines={3}>
<Typography>{children}</Typography>
</LineClampWithTooltip>
);
}

Expand Down
30 changes: 30 additions & 0 deletions context/app/static/js/shared-styles/text/LineClampWithTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { PropsWithChildren, useEffect, useRef, useState } from 'react';
import LineClamp from 'js/shared-styles/text/LineClamp';
import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';

interface LineClampWithTooltipProps extends PropsWithChildren {
lines: number;
}

function LineClampWithTooltip({ lines, children }: LineClampWithTooltipProps) {
const [isTruncated, setIsTruncated] = useState(false);
const ref = useRef<HTMLDivElement>(null);

// Check whether the child text is truncated, and show the full text in a tooltip if so
useEffect(() => {
const element = ref.current;
if (element) {
setIsTruncated(element.scrollHeight > element.clientHeight);
}
}, [children]);

const content = (
<LineClamp ref={ref} lines={lines}>
{children}
</LineClamp>
);

return isTruncated ? <SecondaryBackgroundTooltip title={children}>{content}</SecondaryBackgroundTooltip> : content;
}

export default LineClampWithTooltip;
3 changes: 2 additions & 1 deletion context/app/static/js/shared-styles/text/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LineClamp } from './LineClamp';
import LineClampWithTooltip from './LineClampWithTooltip';

export { LineClamp };
export { LineClamp, LineClampWithTooltip };
Loading