From c568278fd7bb6ed02c40902e718bf622ff5faf58 Mon Sep 17 00:00:00 2001 From: Alejandro Hernandez Date: Mon, 29 Apr 2024 15:42:37 -0400 Subject: [PATCH 1/3] ResultTable: HeaderCell and Cell rendering tweaks - Do not wrap `HeaderCell` children in a `span` by default because it makes providing a custom `HeaderCell` harder. - Support `headerCellProps` and `cellProps` to accomodate the very common pattern of needing to only pass props to the header/cell components. --- .changeset/light-planets-care.md | 8 + .../src/exampleTypes/ResultTable/Header.js | 239 +++++++++--------- .../src/exampleTypes/ResultTable/TableBody.js | 13 +- .../src/exampleTypes/ResultTable/index.js | 27 +- packages/react/src/greyVest/Style.js | 6 +- 5 files changed, 169 insertions(+), 124 deletions(-) create mode 100644 .changeset/light-planets-care.md diff --git a/.changeset/light-planets-care.md b/.changeset/light-planets-care.md new file mode 100644 index 000000000..a85ddc6e5 --- /dev/null +++ b/.changeset/light-planets-care.md @@ -0,0 +1,8 @@ +--- +'contexture-react': patch +--- + +ResultTable: HeaderCell and Cell rendering tweaks + +- Do not wrap `HeaderCell` children in a `span` by default because it makes providing a custom `HeaderCell` harder. +- Support `headerCellProps` and `cellProps` to accomodate the very common pattern of needing to only pass props to the header/cell components. diff --git a/packages/react/src/exampleTypes/ResultTable/Header.js b/packages/react/src/exampleTypes/ResultTable/Header.js index df2142f6a..18fe68ac5 100644 --- a/packages/react/src/exampleTypes/ResultTable/Header.js +++ b/packages/react/src/exampleTypes/ResultTable/Header.js @@ -2,7 +2,7 @@ import React from 'react' import _ from 'lodash/fp.js' import F from 'futil' import { observer } from 'mobx-react' -import { Dynamic } from '../../greyVest/index.js' +import { Dynamic, Flex } from '../../greyVest/index.js' import { withTheme } from '../../utils/theme.js' const moveColumn = ( @@ -67,7 +67,16 @@ let Header = ({ hideMenu, typeDefault, } = fieldSchema - let HeaderCell = fieldSchema.HeaderCell || Th + let HeaderCell = + fieldSchema.HeaderCell || + (({ children, ...props }) => ( + + + {children} + + + )) + let filterNode = criteria && _.find({ field }, _.getOr([], 'children', tree.getNode(criteria))) @@ -81,136 +90,138 @@ let Header = ({ F.flip(filtering)() } let Label = label + let { className, style, ...headerCellProps } = + fieldSchema.headerCellProps ?? {} return ( - - {_.isFunction(label) ? ) } diff --git a/packages/react/src/exampleTypes/ResultTable/TableBody.js b/packages/react/src/exampleTypes/ResultTable/TableBody.js index cda489fa3..533d7917a 100644 --- a/packages/react/src/exampleTypes/ResultTable/TableBody.js +++ b/packages/react/src/exampleTypes/ResultTable/TableBody.js @@ -53,14 +53,23 @@ let TableBody = ({ {...{ fields, visibleFields, hiddenFields }} > {_.map( - ({ field, display = (x) => x, Cell = Td }) => ( + ({ + field, + display = (x) => x, + Cell = Td, + cellProps: { className, style, ...cellProps } = {}, + }) => ( {defaultDisplay({ display, diff --git a/packages/react/src/exampleTypes/ResultTable/index.js b/packages/react/src/exampleTypes/ResultTable/index.js index 5de867480..f2ec93daf 100644 --- a/packages/react/src/exampleTypes/ResultTable/index.js +++ b/packages/react/src/exampleTypes/ResultTable/index.js @@ -98,7 +98,10 @@ let ResultTable = ({ )(visibleFields) let columnGroups = _.reduce( - (columnGroups, { fieldGroup, HeaderCell, HeaderGroup }) => { + ( + columnGroups, + { fieldGroup, headerCellProps, HeaderCell, HeaderGroup } + ) => { for (let i = 0; i < columnGroupsHeight; i++) { let groupRow = columnGroups[i] || (columnGroups[i] = []) let groupName = _.getOr('', i, fieldGroup) @@ -106,7 +109,14 @@ let ResultTable = ({ if (_.get('groupName', lastGroup) === groupName) { lastGroup.colspan++ lastGroup.HeaderCell = HeaderCell - } else groupRow.push({ groupName, colspan: 1, HeaderCell, HeaderGroup }) + } else + groupRow.push({ + groupName, + colspan: 1, + headerCellProps, + HeaderCell, + HeaderGroup, + }) } return columnGroups }, @@ -122,8 +132,17 @@ let ResultTable = ({ (columnGroupRow, i) => ( {F.mapIndexed( - ({ groupName, colspan, HeaderCell = Th, HeaderGroup }, j) => ( - + ( + { + groupName, + colspan, + headerCellProps, + HeaderCell = Th, + HeaderGroup, + }, + j + ) => ( + {HeaderGroup ? ( {groupName} diff --git a/packages/react/src/greyVest/Style.js b/packages/react/src/greyVest/Style.js index b5769baf4..4a5fe52ed 100644 --- a/packages/react/src/greyVest/Style.js +++ b/packages/react/src/greyVest/Style.js @@ -139,16 +139,14 @@ export default () => ( /* Go on top of table content */ z-index: 2; } - + .gv-table th.sticky-column-header { /* Go on top of table headers */ z-index: 3; } - .gv-table th > span { - display: flex; - align-items: center; + .gv-table th > *:first-child { box-sizing: border-box; padding: ${tableCellPadding}px; min-height: 45px; From 2a08c122114f6a79dd43c1a38c78603fcf0ae90f Mon Sep 17 00:00:00 2001 From: Alejandro Hernandez Date: Tue, 30 Apr 2024 11:26:27 -0400 Subject: [PATCH 2/3] Remove span in pivot table --- packages/react/src/exampleTypes/ResultTable/index.js | 12 +++++------- packages/react/src/greyVest/Style.js | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/react/src/exampleTypes/ResultTable/index.js b/packages/react/src/exampleTypes/ResultTable/index.js index f2ec93daf..a693cbb7f 100644 --- a/packages/react/src/exampleTypes/ResultTable/index.js +++ b/packages/react/src/exampleTypes/ResultTable/index.js @@ -143,13 +143,11 @@ let ResultTable = ({ j ) => ( - - {HeaderGroup ? ( - {groupName} - ) : ( - groupName - )} - + {HeaderGroup ? ( + {groupName} + ) : ( + groupName + )} ), columnGroupRow diff --git a/packages/react/src/greyVest/Style.js b/packages/react/src/greyVest/Style.js index 4a5fe52ed..fc1142c8a 100644 --- a/packages/react/src/greyVest/Style.js +++ b/packages/react/src/greyVest/Style.js @@ -192,14 +192,14 @@ export default () => ( z-index: 1; } - .gv-table th.sticky-column-header + th > span, + .gv-table th.sticky-column-header + th > *:only-child, .gv-table td.sticky-column + td, - .gv-table th:first-child > span , + .gv-table th:first-child > *:only-child , .gv-table td:first-child { padding-left: ${2 * tableCellPadding}px; } - .gv-table th:last-child > span , + .gv-table th:last-child > *:only-child , .gv-table td:last-child { padding-right: ${2 * tableCellPadding}px; } From 81aeca07f0ad7584183493ff9f369631f23de2cf Mon Sep 17 00:00:00 2001 From: Alejandro Hernandez Date: Mon, 17 Jun 2024 14:12:52 -0400 Subject: [PATCH 3/3] Address feedback --- .../src/exampleTypes/ResultTable/Header.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/react/src/exampleTypes/ResultTable/Header.js b/packages/react/src/exampleTypes/ResultTable/Header.js index 18fe68ac5..a8ae7b9a1 100644 --- a/packages/react/src/exampleTypes/ResultTable/Header.js +++ b/packages/react/src/exampleTypes/ResultTable/Header.js @@ -116,24 +116,18 @@ let Header = ({ style={popoverStyle} > {!disableSort && ( - { - mutate({ sortField, sortDir: 'asc' }) - }} - > - - Sort Ascending - - )} - {!disableSort && ( - { - mutate({ sortField, sortDir: 'desc' }) - }} - > - - Sort Descending - + <> + mutate({ sortField, sortDir: 'asc' })}> + + Sort Ascending + + mutate({ sortField, sortDir: 'desc' })} + > + + Sort Descending + + )}