@@ -2,6 +2,8 @@ import React, { createContext, useContext } from "react";
2
2
import classes from "../utils/classes" ;
3
3
import { CellProps , RowProps , TableProps } from "./types" ;
4
4
import themeDefault from "./style/Default.module.scss" ;
5
+ import Tooltip from "../Tooltip" ;
6
+
5
7
6
8
const TableContext = createContext < any > ( { } ) ;
7
9
@@ -31,8 +33,21 @@ export default function Table({
31
33
// TABLE HEADINGS
32
34
// Hide column title if the item has an action (action button) or the title starts with underscore
33
35
const modelDatum = data ?. [ 0 ] ;
34
- const thead : any = modelDatum ? Object . keys ( modelDatum ) . map ( ( k ) => ( k . indexOf ( "_" ) === 0 ? "" : k ) ) : { } ;
36
+ const thead : any = modelDatum
37
+ ? Object . keys ( modelDatum ) . map ( ( k ) => {
38
+ const value = modelDatum [ k ] ;
39
+
40
+ if ( k . indexOf ( "_" ) === 0 ) {
41
+ return "" ;
42
+ }
43
+
44
+ if ( typeof value === 'object' && value ?. captionInfo ) {
45
+ return { key : k , captionInfo : value . captionInfo } ;
46
+ }
35
47
48
+ return k ;
49
+ } )
50
+ : { } ;
36
51
const context = {
37
52
style,
38
53
highlightColumns,
@@ -75,11 +90,10 @@ export default function Table({
75
90
) ;
76
91
}
77
92
78
- const Row = ( { datum, onClick } : RowProps ) => {
93
+ const Row = ( { datum, onClick, isHeading } : RowProps ) => {
79
94
const { style, highlightColumns, hideColumns, columnWidths, columnAlignments } = useContext ( TableContext ) ;
80
95
81
96
const className = classes ( [ style ?. tr ] ) ;
82
-
83
97
return (
84
98
< div className = { className } role = "row" onClick = { ( ) => onClick ?.( datum ) } >
85
99
{ Object . keys ( datum )
@@ -89,9 +103,11 @@ const Row = ({ datum, onClick }: RowProps) => {
89
103
// datum[k] is the content for the cell
90
104
// If it is an object with the 'content' property, use that as content (can be JSX or a primitive)
91
105
// Another 'raw' property with a primitive value is used to sort and search
92
- const content = ( datum [ k ] as any ) ?. content || datum [ k ] ;
106
+ let content = ( datum [ k ] as any ) ?. content || datum [ k ] ;
93
107
const tooltip = ( datum [ k ] as any ) ?. tooltip ;
94
-
108
+ const captionInfo = isHeading ? ( datum [ k ] as any ) ?. captionInfo : null ;
109
+ const headingKey = isHeading ? ( datum [ k ] as any ) ?. key : null ;
110
+ content = isHeading && captionInfo ? < Tooltip title = { captionInfo } > { headingKey } </ Tooltip > : content ;
95
111
const wrappedContent = content && typeof content === "string" ? < span > { content } </ span > : content ;
96
112
97
113
const cellClass = classes ( [
@@ -121,4 +137,4 @@ const Cell = ({ children, cellClass, cellStyle, tooltip }: CellProps) => {
121
137
...( tooltip ? { title : tooltip } : { } ) ,
122
138
} ;
123
139
return < div { ...cellProps } > { children } </ div > ;
124
- } ;
140
+ } ;
0 commit comments