Skip to content

Commit 08e9281

Browse files
feat: add tooltips to spectra list cells
1 parent 4fd7681 commit 08e9281

3 files changed

Lines changed: 49 additions & 11 deletions

File tree

src/component/panels/SpectraPanel/SpectraTable.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Tooltip } from '@blueprintjs/core';
12
import type {
23
ActiveSpectrum,
34
JpathTableColumn,
@@ -328,7 +329,17 @@ export function SpectraTable(props: SpectraTableProps) {
328329

329330
const cell: Column<Spectrum> = {
330331
Header: () => <ColumnHeader label={col.label} col={col} />,
331-
accessor: (row) => getValueByPath(row, jpath, format),
332+
Cell: ({ row }: CellProps<Spectrum>) => {
333+
const val = getValueByPath(row.original, jpath, format);
334+
return (
335+
<Tooltip
336+
content={val}
337+
renderTarget={({ isOpen, ...targetProps }) => (
338+
<div {...targetProps}>{val}</div>
339+
)}
340+
/>
341+
);
342+
},
332343
...(cellRender && { Cell: cellRender }),
333344
id: `${index}`,
334345
style,

src/component/panels/SpectraPanel/base/RenderAsHTML.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Tooltip } from '@blueprintjs/core';
12
import type { Spectrum } from '@zakodium/nmrium-core';
23
import dlv from 'dlv';
34

@@ -6,6 +7,17 @@ interface RenderAsHTMLProps {
67
jpath: string | string[];
78
}
89

10+
interface HTMLContentProps extends React.HTMLAttributes<HTMLDivElement> {
11+
html: string;
12+
}
13+
14+
function HTMLContent({ html }: HTMLContentProps) {
15+
return (
16+
// eslint-disable-next-line react/no-danger
17+
<div dangerouslySetInnerHTML={{ __html: html }} />
18+
);
19+
}
20+
921
export function RenderAsHTML(props: RenderAsHTMLProps) {
1022
const { data, jpath } = props;
1123

@@ -15,11 +27,17 @@ export function RenderAsHTML(props: RenderAsHTMLProps) {
1527
return value;
1628
}
1729

30+
const formattedHTML = formatValueAsHTML(value);
31+
1832
return (
19-
<div
20-
// eslint-disable-next-line react/no-danger
21-
dangerouslySetInnerHTML={{
22-
__html: formatValueAsHTML(value),
33+
<Tooltip
34+
content={<HTMLContent html={formattedHTML} />}
35+
renderTarget={({ isOpen, ...targetProps }) => {
36+
return (
37+
<div {...targetProps}>
38+
<HTMLContent html={formattedHTML} />
39+
</div>
40+
);
2341
}}
2442
/>
2543
);

src/component/panels/SpectraPanel/base/SpectrumName.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Tooltip } from '@blueprintjs/core';
12
import type { Spectrum } from '@zakodium/nmrium-core';
23
import { SvgNmr2D, SvgNmrFid, SvgNmrFt } from 'cheminfo-font';
34
import type { CSSProperties } from 'react';
@@ -24,13 +25,21 @@ const styles: Record<'info' | 'icon', CSSProperties> = {
2425
};
2526

2627
export function SpectrumName(props: SpectrumNameProps) {
28+
const name = props.data.info.name;
2729
return (
28-
<div style={styles.info}>
29-
<div style={styles.icon}>
30-
<SpectraIcon {...props} />
31-
</div>
32-
<span>{props.data.info.name}</span>
33-
</div>
30+
<Tooltip
31+
content={name}
32+
renderTarget={({ isOpen, ...targetProps }) => {
33+
return (
34+
<div style={styles.info} {...targetProps}>
35+
<div style={styles.icon}>
36+
<SpectraIcon {...props} />
37+
</div>
38+
<span>{props.data.info.name}</span>
39+
</div>
40+
);
41+
}}
42+
/>
3443
);
3544
}
3645

0 commit comments

Comments
 (0)