2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
2022-03-21 20:44:06 +00:00
|
|
|
import { Text, View, ViewStyle } from 'react-native';
|
2019-08-27 12:25:38 +00:00
|
|
|
|
2022-06-27 21:27:22 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2019-08-27 12:25:38 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
2022-06-27 21:27:22 +00:00
|
|
|
export interface ITableCell {
|
2021-09-13 20:41:05 +00:00
|
|
|
align: '' | 'left' | 'center' | 'right';
|
2022-03-25 17:20:09 +00:00
|
|
|
children: React.ReactElement | null;
|
2021-09-13 20:41:05 +00:00
|
|
|
isLastCell: boolean;
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
export const CELL_WIDTH = 100;
|
|
|
|
|
2022-06-27 21:27:22 +00:00
|
|
|
const TableCell = React.memo(({ isLastCell, align, children }: ITableCell) => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
|
|
|
|
const cellStyle: ViewStyle[] = [styles.cell, { borderColor: colors.borderColor }];
|
2019-08-27 12:25:38 +00:00
|
|
|
if (!isLastCell) {
|
|
|
|
cellStyle.push(styles.cellRightBorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
let textStyle = null;
|
|
|
|
if (align === 'center') {
|
|
|
|
textStyle = styles.alignCenter;
|
|
|
|
} else if (align === 'right') {
|
|
|
|
textStyle = styles.alignRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={[...cellStyle, { width: CELL_WIDTH }]}>
|
2022-06-27 21:27:22 +00:00
|
|
|
<Text style={[textStyle, { color: colors.bodyText }]}>{children}</Text>
|
2019-08-27 12:25:38 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default TableCell;
|