Skip to content

Commit

Permalink
refactor(AnalyticalTable): declare row height via css variable (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusNotheis authored Apr 16, 2020
1 parent 0d16c18 commit 5a4a083
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
53 changes: 24 additions & 29 deletions packages/main/src/components/AnalyticalTable/AnayticalTable.jss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const styles = {
tableContainer: {
width: '100%',
height: `calc(100% - ${CssSizeVariables.sapWcrAnalyticalTableRowHeight})`,
minHeight: '3rem',
minHeight: '3rem'
},
table: {
position: 'relative',
width: '100%',
maxWidth: '100%',
overflowX: 'auto',
overflowX: 'auto'
},
tableHeaderRow: {
boxShadow: 'none !important',
height: CssSizeVariables.sapWcrAnalyticalTableRowHeight,
position: 'relative',
position: 'relative'
},
th: {
backgroundColor: ThemingParameters.sapList_HeaderBackground,
Expand All @@ -31,18 +31,18 @@ const styles = {
textAlign: 'start',
boxSizing: 'border-box',
'&:first-child': {
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`,
},
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`
}
},
tbody: {
position: 'relative',
zIndex: 0,
backgroundColor: ThemingParameters.sapList_Background,
overflowX: 'hidden !important',
overflowY: 'auto !important',
overflowY: 'auto !important'
},
alternateRowColor: {
backgroundColor: ThemingParameters.sapList_HeaderBackground,
backgroundColor: ThemingParameters.sapList_HeaderBackground
},
emptyRow: {},
tr: {
Expand All @@ -52,38 +52,38 @@ const styles = {
'&[data-is-selected]': {
backgroundColor: `${ThemingParameters.sapList_SelectionBackgroundColor} !important`,
'& $tableCell': {
borderBottom: `1px solid ${ThemingParameters.sapList_SelectionBorderColor}`,
},
borderBottom: `1px solid ${ThemingParameters.sapList_SelectionBorderColor}`
}
},
'&[data-is-selected]:hover': {
backgroundColor: `${ThemingParameters.sapList_Hover_SelectionBackground} !important`,
},
backgroundColor: `${ThemingParameters.sapList_Hover_SelectionBackground} !important`
}
},
tableGroupHeader: {
'&$tr': {
backgroundColor: `${ThemingParameters.sapList_TableGroupHeaderBackground} !important`,
border: `1px solid ${ThemingParameters.sapList_TableGroupHeaderBorderColor}`,
color: ThemingParameters.sapList_TextColor,
'& $tableCell': {
borderRight: 'none',
},
},
borderRight: 'none'
}
}
},
selectable: {
'& $tr:hover:not($emptyRow)': {
backgroundColor: ThemingParameters.sapList_Hover_Background,
'&:not($selectionModeRowSelector)': {
cursor: 'pointer',
},
cursor: 'pointer'
}
},
'& $tr:active:not([data-is-selected]):not($tableGroupHeader):not($emptyRow):not($selectionModeRowSelector)': {
backgroundColor: ThemingParameters.sapList_Active_Background,
'& $tableCell': {
borderRight: `1px solid ${ThemingParameters.sapList_Active_Background}`,
color: `${ThemingParameters.sapList_Active_TextColor}`,
'--sapTextColor': ThemingParameters.sapList_Active_TextColor,
},
},
'--sapTextColor': ThemingParameters.sapList_Active_TextColor
}
}
},
selectionModeRowSelector: {},
tableCell: {
Expand All @@ -97,7 +97,7 @@ const styles = {
display: 'flex',
padding: '0 0.5rem',
'&:first-child': {
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`,
borderLeft: `1px solid ${ThemingParameters.sapList_BorderColor}`
},
overflow: 'hidden',
position: 'relative',
Expand All @@ -106,8 +106,8 @@ const styles = {
alignItems: 'center',
'&:focus': {
outlineOffset: '-2px',
outline: `1px dotted ${ThemingParameters.sapContent_FocusColor}`,
},
outline: `1px dotted ${ThemingParameters.sapContent_FocusColor}`
}
},
noDataContainer: {
display: 'flex',
Expand All @@ -121,13 +121,8 @@ const styles = {
fontFamily: ThemingParameters.sapFontFamily,
fontSize: ThemingParameters.sapFontSize,
fontWeight: 'normal',
borderBottom: `1px solid ${ThemingParameters.sapList_BorderColor}`,
},
modifiedRowHeight: {
'& $tableCell': {
height: (props) => `${props.rowHeight}px`,
},
},
borderBottom: `1px solid ${ThemingParameters.sapList_BorderColor}`
}
};

export default styles;
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ exports[`AnalyticalTable Tree Table 1`] = `

exports[`AnalyticalTable custom row height 1`] = `
<div
style="visibility: hidden;"
style="--sapWcrAnalyticalTableRowHeight: 60px; visibility: hidden;"
>
<div
style="min-height: 1.5rem; display: flex; align-items: center;"
Expand All @@ -2254,7 +2254,7 @@ exports[`AnalyticalTable custom row height 1`] = `
</ui5-title>
</div>
<div
class="AnalyticalTable-tableContainer-0 AnalyticalTable-modifiedRowHeight-0 AnalyticalTable-modifiedRowHeight-d5-0"
class="AnalyticalTable-tableContainer-0"
>
<div
aria-colcount="4"
Expand Down
46 changes: 25 additions & 21 deletions packages/main/src/components/AnalyticalTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import React, {
useCallback,
useEffect,
useMemo,
useRef
useRef,
CSSProperties
} from 'react';
import {
PluginHook,
Expand Down Expand Up @@ -164,7 +165,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
onLoadMore
} = props;

const classes = useStyles({ rowHeight: props.rowHeight });
const classes = useStyles();

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

const updateTableClientWidth = useCallback(() => {
requestAnimationFrame(() => {
if (tableRef.current) {
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth } });
}
});
}, []);

useEffect(() => {
// @ts-ignore
const tableWidthObserver = new ResizeObserver(updateTableClientWidth);
const tableWidthObserver = new ResizeObserver(() => {
requestAnimationFrame(() => {
if (tableRef.current) {
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth } });
}
});
});
tableWidthObserver.observe(tableRef.current);
return () => {
tableWidthObserver.disconnect();
};
}, [updateTableClientWidth]);
}, []);

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

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

if (!!rowHeight) {
tableContainerClasses.put(classes.modifiedRowHeight);
}

const calcRowHeight = parseInt(
getComputedStyle(tableRef.current ?? document.body).getPropertyValue('--sapWcrAnalyticalTableRowHeight') || '44'
);
Expand Down Expand Up @@ -327,15 +322,24 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
]);

const inlineStyle = useMemo(() => {
if(tableState.tableClientWidth > 0) {
return style;
const tableStyles = {};
if (!!rowHeight) {
tableStyles['--sapWcrAnalyticalTableRowHeight'] = `${rowHeight}px`;
}

if (tableState.tableClientWidth > 0) {
return {
...tableStyles,
style
} as CSSProperties;
}
return {
...tableStyles,
...style,
visibility: 'hidden' as 'hidden'
};
}, [tableState.tableClientWidth, style]);
} as CSSProperties;
}, [tableState.tableClientWidth, style, rowHeight]);

return (
<div className={className} style={inlineStyle} title={tooltip} ref={analyticalTableRef} {...passThroughProps}>
{title && <TitleBar>{title}</TitleBar>}
Expand Down
3 changes: 2 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
printWidth: 120,
parser: 'typescript',
singleQuote: true,
arrowParens: 'always'
arrowParens: 'always',
trailingComma: 'none'
};

0 comments on commit 5a4a083

Please sign in to comment.