@@ -2,6 +2,8 @@ import React, { createContext, useContext } from "react";
22import classes from "../utils/classes" ;
33import { CellProps , RowProps , TableProps } from "./types" ;
44import themeDefault from "./style/Default.module.scss" ;
5+ import Tooltip from "../Tooltip" ;
6+
57
68const TableContext = createContext < any > ( { } ) ;
79
@@ -31,8 +33,21 @@ export default function Table({
3133 // TABLE HEADINGS
3234 // Hide column title if the item has an action (action button) or the title starts with underscore
3335 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+ }
3547
48+ return k ;
49+ } )
50+ : { } ;
3651 const context = {
3752 style,
3853 highlightColumns,
@@ -75,11 +90,10 @@ export default function Table({
7590 ) ;
7691}
7792
78- const Row = ( { datum, onClick } : RowProps ) => {
93+ const Row = ( { datum, onClick, isHeading } : RowProps ) => {
7994 const { style, highlightColumns, hideColumns, columnWidths, columnAlignments } = useContext ( TableContext ) ;
8095
8196 const className = classes ( [ style ?. tr ] ) ;
82-
8397 return (
8498 < div className = { className } role = "row" onClick = { ( ) => onClick ?.( datum ) } >
8599 { Object . keys ( datum )
@@ -89,9 +103,11 @@ const Row = ({ datum, onClick }: RowProps) => {
89103 // datum[k] is the content for the cell
90104 // If it is an object with the 'content' property, use that as content (can be JSX or a primitive)
91105 // 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 ] ;
93107 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 ;
95111 const wrappedContent = content && typeof content === "string" ? < span > { content } </ span > : content ;
96112
97113 const cellClass = classes ( [
@@ -121,4 +137,4 @@ const Cell = ({ children, cellClass, cellStyle, tooltip }: CellProps) => {
121137 ...( tooltip ? { title : tooltip } : { } ) ,
122138 } ;
123139 return < div { ...cellProps } > { children } </ div > ;
124- } ;
140+ } ;
0 commit comments