2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
2022-03-21 20:44:06 +00:00
|
|
|
import { 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 ITableRow {
|
2022-03-25 17:20:09 +00:00
|
|
|
children: React.ReactElement | null;
|
2021-09-13 20:41:05 +00:00
|
|
|
isLastRow: boolean;
|
|
|
|
}
|
|
|
|
|
2022-06-27 21:27:22 +00:00
|
|
|
const TableRow = React.memo(({ isLastRow, children: _children }: ITableRow) => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
|
|
|
|
const rowStyle: ViewStyle[] = [styles.row, { borderColor: colors.borderColor }];
|
2019-08-27 12:25:38 +00:00
|
|
|
if (!isLastRow) {
|
|
|
|
rowStyle.push(styles.rowBottomBorder);
|
|
|
|
}
|
|
|
|
|
2022-03-25 17:20:09 +00:00
|
|
|
const children = React.Children.toArray(_children) as React.ReactElement[];
|
2019-08-27 12:25:38 +00:00
|
|
|
children[children.length - 1] = React.cloneElement(children[children.length - 1], {
|
|
|
|
isLastCell: true
|
|
|
|
});
|
|
|
|
|
|
|
|
return <View style={rowStyle}>{children}</View>;
|
|
|
|
});
|
|
|
|
|
|
|
|
export default TableRow;
|