Skip to content

Commit

Permalink
WIP: Remove redundant cell styling hook
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusNotheis committed Dec 9, 2019
1 parent e85e84e commit 529ac00
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 50 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
import { TextAlign } from '@ui5/webcomponents-react/lib/TextAlign';
import { VerticalAlign } from '@ui5/webcomponents-react/lib/VerticalAlign';
import { CSSProperties } from 'react';
import { PluginHook } from 'react-table';
import { useCellStyling } from './useCellStyling';

export const useTableCellStyling = (classes, rowHeight) => {
const hook: PluginHook<{}> = (instance) => {
instance.getCellProps.push(useCellStyling({ rowHeight }, classes));
instance.getCellProps.push(({ column }) => {
const style: CSSProperties = {};

if (rowHeight) {
style.height = `${rowHeight}px`;
}
switch (column.hAlign) {
case TextAlign.Begin:
style.textAlign = 'start';
break;
case TextAlign.Center:
style.textAlign = 'center';
break;
case TextAlign.End:
style.textAlign = 'end';
break;
case TextAlign.Left:
style.textAlign = 'left';
break;
case TextAlign.Right:
style.textAlign = 'right';
break;
}
switch (column.vAlign) {
case VerticalAlign.Bottom:
style.verticalAlign = 'bottom';
break;
case VerticalAlign.Middle:
style.verticalAlign = 'middle';
break;
case VerticalAlign.Top:
style.verticalAlign = 'top';
break;
}

let className = classes.tableCell;
if (column.className) {
className += ` ${column.className}`;
}
return {
className,
style
};
});
};
hook.pluginName = 'useTableCellStyling';
return hook;
Expand Down

0 comments on commit 529ac00

Please sign in to comment.