Skip to content

Commit 5a4a083

Browse files
refactor(AnalyticalTable): declare row height via css variable (#430)
1 parent 0d16c18 commit 5a4a083

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

packages/main/src/components/AnalyticalTable/AnayticalTable.jss.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ const styles = {
55
tableContainer: {
66
width: '100%',
77
height: `calc(100% - ${CssSizeVariables.sapWcrAnalyticalTableRowHeight})`,
8-
minHeight: '3rem',
8+
minHeight: '3rem'
99
},
1010
table: {
1111
position: 'relative',
1212
width: '100%',
1313
maxWidth: '100%',
14-
overflowX: 'auto',
14+
overflowX: 'auto'
1515
},
1616
tableHeaderRow: {
1717
boxShadow: 'none !important',
1818
height: CssSizeVariables.sapWcrAnalyticalTableRowHeight,
19-
position: 'relative',
19+
position: 'relative'
2020
},
2121
th: {
2222
backgroundColor: ThemingParameters.sapList_HeaderBackground,
@@ -31,18 +31,18 @@ const styles = {
3131
textAlign: 'start',
3232
boxSizing: 'border-box',
3333
'&:first-child': {
34-
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`,
35-
},
34+
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`
35+
}
3636
},
3737
tbody: {
3838
position: 'relative',
3939
zIndex: 0,
4040
backgroundColor: ThemingParameters.sapList_Background,
4141
overflowX: 'hidden !important',
42-
overflowY: 'auto !important',
42+
overflowY: 'auto !important'
4343
},
4444
alternateRowColor: {
45-
backgroundColor: ThemingParameters.sapList_HeaderBackground,
45+
backgroundColor: ThemingParameters.sapList_HeaderBackground
4646
},
4747
emptyRow: {},
4848
tr: {
@@ -52,38 +52,38 @@ const styles = {
5252
'&[data-is-selected]': {
5353
backgroundColor: `${ThemingParameters.sapList_SelectionBackgroundColor} !important`,
5454
'& $tableCell': {
55-
borderBottom: `1px solid ${ThemingParameters.sapList_SelectionBorderColor}`,
56-
},
55+
borderBottom: `1px solid ${ThemingParameters.sapList_SelectionBorderColor}`
56+
}
5757
},
5858
'&[data-is-selected]:hover': {
59-
backgroundColor: `${ThemingParameters.sapList_Hover_SelectionBackground} !important`,
60-
},
59+
backgroundColor: `${ThemingParameters.sapList_Hover_SelectionBackground} !important`
60+
}
6161
},
6262
tableGroupHeader: {
6363
'&$tr': {
6464
backgroundColor: `${ThemingParameters.sapList_TableGroupHeaderBackground} !important`,
6565
border: `1px solid ${ThemingParameters.sapList_TableGroupHeaderBorderColor}`,
6666
color: ThemingParameters.sapList_TextColor,
6767
'& $tableCell': {
68-
borderRight: 'none',
69-
},
70-
},
68+
borderRight: 'none'
69+
}
70+
}
7171
},
7272
selectable: {
7373
'& $tr:hover:not($emptyRow)': {
7474
backgroundColor: ThemingParameters.sapList_Hover_Background,
7575
'&:not($selectionModeRowSelector)': {
76-
cursor: 'pointer',
77-
},
76+
cursor: 'pointer'
77+
}
7878
},
7979
'& $tr:active:not([data-is-selected]):not($tableGroupHeader):not($emptyRow):not($selectionModeRowSelector)': {
8080
backgroundColor: ThemingParameters.sapList_Active_Background,
8181
'& $tableCell': {
8282
borderRight: `1px solid ${ThemingParameters.sapList_Active_Background}`,
8383
color: `${ThemingParameters.sapList_Active_TextColor}`,
84-
'--sapTextColor': ThemingParameters.sapList_Active_TextColor,
85-
},
86-
},
84+
'--sapTextColor': ThemingParameters.sapList_Active_TextColor
85+
}
86+
}
8787
},
8888
selectionModeRowSelector: {},
8989
tableCell: {
@@ -97,7 +97,7 @@ const styles = {
9797
display: 'flex',
9898
padding: '0 0.5rem',
9999
'&:first-child': {
100-
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`,
100+
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`
101101
},
102102
overflow: 'hidden',
103103
position: 'relative',
@@ -106,8 +106,8 @@ const styles = {
106106
alignItems: 'center',
107107
'&:focus': {
108108
outlineOffset: '-2px',
109-
outline: `1px dotted ${ThemingParameters.sapContent_FocusColor}`,
110-
},
109+
outline: `1px dotted ${ThemingParameters.sapContent_FocusColor}`
110+
}
111111
},
112112
noDataContainer: {
113113
display: 'flex',
@@ -121,13 +121,8 @@ const styles = {
121121
fontFamily: ThemingParameters.sapFontFamily,
122122
fontSize: ThemingParameters.sapFontSize,
123123
fontWeight: 'normal',
124-
borderBottom: `1px solid ${ThemingParameters.sapList_BorderColor}`,
125-
},
126-
modifiedRowHeight: {
127-
'& $tableCell': {
128-
height: (props) => `${props.rowHeight}px`,
129-
},
130-
},
124+
borderBottom: `1px solid ${ThemingParameters.sapList_BorderColor}`
125+
}
131126
};
132127

133128
export default styles;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ exports[`AnalyticalTable Tree Table 1`] = `
22422242

22432243
exports[`AnalyticalTable custom row height 1`] = `
22442244
<div
2245-
style="visibility: hidden;"
2245+
style="--sapWcrAnalyticalTableRowHeight: 60px; visibility: hidden;"
22462246
>
22472247
<div
22482248
style="min-height: 1.5rem; display: flex; align-items: center;"
@@ -2254,7 +2254,7 @@ exports[`AnalyticalTable custom row height 1`] = `
22542254
</ui5-title>
22552255
</div>
22562256
<div
2257-
class="AnalyticalTable-tableContainer-0 AnalyticalTable-modifiedRowHeight-0 AnalyticalTable-modifiedRowHeight-d5-0"
2257+
class="AnalyticalTable-tableContainer-0"
22582258
>
22592259
<div
22602260
aria-colcount="4"

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import React, {
1616
useCallback,
1717
useEffect,
1818
useMemo,
19-
useRef
19+
useRef,
20+
CSSProperties
2021
} from 'react';
2122
import {
2223
PluginHook,
@@ -164,7 +165,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
164165
onLoadMore
165166
} = props;
166167

167-
const classes = useStyles({ rowHeight: props.rowHeight });
168+
const classes = useStyles();
168169

169170
const [analyticalTableRef, reactWindowRef] = useTableScrollHandles(ref);
170171
const tableRef: RefObject<HTMLDivElement> = useRef();
@@ -240,22 +241,20 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
240241
...tableHooks
241242
);
242243

243-
const updateTableClientWidth = useCallback(() => {
244-
requestAnimationFrame(() => {
245-
if (tableRef.current) {
246-
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth } });
247-
}
248-
});
249-
}, []);
250-
251244
useEffect(() => {
252245
// @ts-ignore
253-
const tableWidthObserver = new ResizeObserver(updateTableClientWidth);
246+
const tableWidthObserver = new ResizeObserver(() => {
247+
requestAnimationFrame(() => {
248+
if (tableRef.current) {
249+
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth } });
250+
}
251+
});
252+
});
254253
tableWidthObserver.observe(tableRef.current);
255254
return () => {
256255
tableWidthObserver.disconnect();
257256
};
258-
}, [updateTableClientWidth]);
257+
}, []);
259258

260259
useEffect(() => {
261260
dispatch({ type: 'SET_GROUP_BY', payload: groupBy });
@@ -267,10 +266,6 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
267266

268267
const tableContainerClasses = StyleClassHelper.of(classes.tableContainer);
269268

270-
if (!!rowHeight) {
271-
tableContainerClasses.put(classes.modifiedRowHeight);
272-
}
273-
274269
const calcRowHeight = parseInt(
275270
getComputedStyle(tableRef.current ?? document.body).getPropertyValue('--sapWcrAnalyticalTableRowHeight') || '44'
276271
);
@@ -327,15 +322,24 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
327322
]);
328323

329324
const inlineStyle = useMemo(() => {
330-
if(tableState.tableClientWidth > 0) {
331-
return style;
325+
const tableStyles = {};
326+
if (!!rowHeight) {
327+
tableStyles['--sapWcrAnalyticalTableRowHeight'] = `${rowHeight}px`;
328+
}
329+
330+
if (tableState.tableClientWidth > 0) {
331+
return {
332+
...tableStyles,
333+
style
334+
} as CSSProperties;
332335
}
333336
return {
337+
...tableStyles,
334338
...style,
335339
visibility: 'hidden' as 'hidden'
336-
};
337-
}, [tableState.tableClientWidth, style]);
338-
340+
} as CSSProperties;
341+
}, [tableState.tableClientWidth, style, rowHeight]);
342+
339343
return (
340344
<div className={className} style={inlineStyle} title={tooltip} ref={analyticalTableRef} {...passThroughProps}>
341345
{title && <TitleBar>{title}</TitleBar>}

prettier.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
printWidth: 120,
33
parser: 'typescript',
44
singleQuote: true,
5-
arrowParens: 'always'
5+
arrowParens: 'always',
6+
trailingComma: 'none'
67
};

0 commit comments

Comments
 (0)