Skip to content

Commit 3cde696

Browse files
authored
feat(AnalyticalTable): add header tooltip property to column (#721)
closes #704
1 parent e98b3ca commit 3cde696

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { DefaultNoDataComponent } from './defaults/NoDataComponent';
2323
columns: [
2424
{
2525
Header: 'Name',
26+
headerTooltip: 'Full Name', // A more extensive description!
2627
accessor: 'name' // String-based value accessors!
2728
},
2829
{
@@ -177,6 +178,7 @@ import { DefaultNoDataComponent } from './defaults/NoDataComponent';
177178
| Attribute | Type | Description |
178179
| ------------------ | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
179180
| `Header` | `string OR ComponentType` | Can either be `string` or a React component that will be rendered as column header |
181+
| `headerTooltip` | `string` | Tooltip for the column header. If not set, the display text will be the same as the Header if it is a `string` |
180182
| `Cell` | `ComponentType` | Custom cell renderer. If set, the table will call that component for every cell and pass all required information as props, e.g. the cell value as `props.cell.value` |
181183
| `width` | `number` | Cell width, if not set the table will distribute all columns without a width evenly |
182184
| `minWidth` | `number` | min width of the column, e.g. used for resizing |

packages/main/src/components/AnalyticalTable/AnalyticalTable.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import React, { useRef } from 'react';
1010
const columns = [
1111
{
1212
Header: 'Name',
13+
headerTooltip: 'Full Name', // A more extensive description!
1314
accessor: 'name' // String-based value accessors!
1415
},
1516
{

packages/main/src/components/AnalyticalTable/ColumnHeader/ColumnHeaderContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const ColumnHeaderContainer = (props) => {
9191
onDragEnter={onDragEnter}
9292
onDragEnd={onDragEnd}
9393
dragOver={column.id === dragOver}
94+
headerTooltip={column.headerTooltip}
9495
isDraggable={column.canReorder && !resizeInfo.isResizingColumn}
9596
virtualColumn={virtualColumn}
9697
>

packages/main/src/components/AnalyticalTable/ColumnHeader/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface ColumnHeaderProps {
3939
onDragEnd: DragEventHandler<HTMLDivElement>;
4040
dragOver: boolean;
4141
isResizing: boolean;
42+
headerTooltip: string;
4243
isDraggable: boolean;
4344
role: string;
4445
isLastColumn: boolean;
@@ -102,6 +103,7 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
102103
onDragStart,
103104
onDrop,
104105
onDragEnd,
106+
headerTooltip,
105107
isDraggable,
106108
dragOver,
107109
role,
@@ -110,6 +112,16 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
110112

111113
const isFiltered = column.filterValue && column.filterValue.length > 0;
112114

115+
const tooltip = useMemo(() => {
116+
if (headerTooltip) {
117+
return headerTooltip;
118+
}
119+
if (typeof children === 'string') {
120+
return children;
121+
}
122+
return null;
123+
}, [children, headerTooltip]);
124+
113125
const textStyle = useMemo(() => {
114126
let margin = 0;
115127

@@ -176,12 +188,7 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
176188
onClick={onOpenPopover}
177189
>
178190
<div className={classes.header} data-h-align={column.hAlign}>
179-
<Text
180-
tooltip={typeof children === 'string' ? children : null}
181-
wrapping={false}
182-
style={textStyle}
183-
className={classes.text}
184-
>
191+
<Text tooltip={tooltip} wrapping={false} style={textStyle} className={classes.text}>
185192
{children}
186193
</Text>
187194
<div className={classes.iconContainer}>

packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ exports[`AnalyticalTable Alternate Row Color 1`] = `
4848
>
4949
<span
5050
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
51-
title="Name"
51+
title="Full Name"
5252
>
5353
Name
5454
</span>
@@ -452,7 +452,7 @@ exports[`AnalyticalTable Loading - Loader 1`] = `
452452
>
453453
<span
454454
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
455-
title="Name"
455+
title="Full Name"
456456
>
457457
Name
458458
</span>
@@ -856,7 +856,7 @@ exports[`AnalyticalTable Loading - Placeholder 1`] = `
856856
>
857857
<span
858858
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
859-
title="Name"
859+
title="Full Name"
860860
>
861861
Name
862862
</span>
@@ -1274,7 +1274,7 @@ exports[`AnalyticalTable Tree Table 1`] = `
12741274
>
12751275
<span
12761276
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
1277-
title="Name"
1277+
title="Full Name"
12781278
>
12791279
Name
12801280
</span>
@@ -1746,7 +1746,7 @@ exports[`AnalyticalTable custom row height 1`] = `
17461746
>
17471747
<span
17481748
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
1749-
title="Name"
1749+
title="Full Name"
17501750
>
17511751
Name
17521752
</span>
@@ -2164,7 +2164,7 @@ exports[`AnalyticalTable highlight row with custom row key 1`] = `
21642164
>
21652165
<span
21662166
class="Text-text Text-noWrap TableColumnHeader-text"
2167-
title="Name"
2167+
title="Full Name"
21682168
>
21692169
Name
21702170
</span>
@@ -2610,7 +2610,7 @@ exports[`AnalyticalTable render without data 1`] = `
26102610
>
26112611
<span
26122612
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
2613-
title="Name"
2613+
title="Full Name"
26142614
>
26152615
Name
26162616
</span>
@@ -2781,7 +2781,7 @@ exports[`AnalyticalTable test Asc desc 1`] = `
27812781
>
27822782
<span
27832783
class="Text-text Text-noWrap TableColumnHeader-text"
2784-
title="Name"
2784+
title="Full Name"
27852785
>
27862786
Name
27872787
</span>
@@ -3188,7 +3188,7 @@ exports[`AnalyticalTable test Asc desc 2`] = `
31883188
>
31893189
<span
31903190
class="Text-text Text-noWrap TableColumnHeader-text"
3191-
title="Name"
3191+
title="Full Name"
31923192
>
31933193
Name
31943194
</span>
@@ -3595,7 +3595,7 @@ exports[`AnalyticalTable test Asc desc 3`] = `
35953595
>
35963596
<span
35973597
class="Text-text Text-noWrap TableColumnHeader-text"
3598-
title="Name"
3598+
title="Full Name"
35993599
>
36003600
Name
36013601
</span>
@@ -4000,7 +4000,7 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
40004000
>
40014001
<span
40024002
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
4003-
title="Name"
4003+
title="Full Name"
40044004
>
40054005
Name
40064006
</span>
@@ -4453,7 +4453,7 @@ exports[`AnalyticalTable with highlight row 1`] = `
44534453
>
44544454
<span
44554455
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
4456-
title="Name"
4456+
title="Full Name"
44574457
>
44584458
Name
44594459
</span>
@@ -5030,7 +5030,7 @@ exports[`AnalyticalTable with initial column order 1`] = `
50305030
>
50315031
<span
50325032
class="Text-text Text-noWrap TableColumnHeader-text"
5033-
title="Name"
5033+
title="Full Name"
50345034
>
50355035
Name
50365036
</span>
@@ -5335,7 +5335,7 @@ exports[`AnalyticalTable without selection Column 1`] = `
53355335
>
53365336
<span
53375337
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
5338-
title="Name"
5338+
title="Full Name"
53395339
>
53405340
Name
53415341
</span>

packages/main/src/interfaces/AnalyticalTableColumnDefinition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface AnalyticalTableColumnDefinition {
1111
id?: string;
1212

1313
Header?: string | ComponentType<any>;
14+
headerTooltip?: string;
1415
Cell?: string | ComponentType<any>;
1516
width?: number;
1617
minWidth?: number;

0 commit comments

Comments
 (0)