Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(AnalyticalTable): declare row height via css variable #430

Merged
merged 2 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
};