|
| 1 | +import { TextAlign } from '@ui5/webcomponents-react/lib/TextAlign'; |
| 2 | +import { VerticalAlign } from '@ui5/webcomponents-react/lib/VerticalAlign'; |
| 3 | +import { CSSProperties } from 'react'; |
1 | 4 | import { PluginHook } from 'react-table'; |
2 | | -import { useCellStyling } from './useCellStyling'; |
3 | 5 |
|
4 | 6 | export const useTableCellStyling = (classes, rowHeight) => { |
5 | 7 | const hook: PluginHook<{}> = (instance) => { |
6 | | - instance.getCellProps.push(useCellStyling({ rowHeight }, classes)); |
| 8 | + instance.getCellProps.push(({ column }) => { |
| 9 | + const style: CSSProperties = {}; |
| 10 | + |
| 11 | + if (rowHeight) { |
| 12 | + style.height = `${rowHeight}px`; |
| 13 | + } |
| 14 | + switch (column.hAlign) { |
| 15 | + case TextAlign.Begin: |
| 16 | + style.textAlign = 'start'; |
| 17 | + break; |
| 18 | + case TextAlign.Center: |
| 19 | + style.textAlign = 'center'; |
| 20 | + break; |
| 21 | + case TextAlign.End: |
| 22 | + style.textAlign = 'end'; |
| 23 | + break; |
| 24 | + case TextAlign.Left: |
| 25 | + style.textAlign = 'left'; |
| 26 | + break; |
| 27 | + case TextAlign.Right: |
| 28 | + style.textAlign = 'right'; |
| 29 | + break; |
| 30 | + } |
| 31 | + switch (column.vAlign) { |
| 32 | + case VerticalAlign.Bottom: |
| 33 | + style.verticalAlign = 'bottom'; |
| 34 | + break; |
| 35 | + case VerticalAlign.Middle: |
| 36 | + style.verticalAlign = 'middle'; |
| 37 | + break; |
| 38 | + case VerticalAlign.Top: |
| 39 | + style.verticalAlign = 'top'; |
| 40 | + break; |
| 41 | + } |
| 42 | + |
| 43 | + let className = classes.tableCell; |
| 44 | + if (column.className) { |
| 45 | + className += ` ${column.className}`; |
| 46 | + } |
| 47 | + return { |
| 48 | + className, |
| 49 | + style |
| 50 | + }; |
| 51 | + }); |
7 | 52 | }; |
8 | 53 | hook.pluginName = 'useTableCellStyling'; |
9 | 54 | return hook; |
|
0 commit comments