react-native-table-component
Version:
Build table for react native.
50 lines (46 loc) • 1.29 kB
JavaScript
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
export class Cell extends Component {
static propTypes = {
style: PropTypes.object,
textStyle: PropTypes.object,
borderStyle: PropTypes.object
};
render() {
const { data, width, height, flex, style, textStyle, borderStyle, ...props } = this.props;
const textDom = React.isValidElement(data) ? (
data
) : (
<Text style={[textStyle, styles.text]} {...props}>
{data}
</Text>
);
const borderTopWidth = (borderStyle && borderStyle.borderWidth) || 0;
const borderRightWidth = borderTopWidth;
const borderColor = (borderStyle && borderStyle.borderColor) || '#000';
return (
<View
style={[
{
borderTopWidth,
borderRightWidth,
borderColor
},
styles.cell,
width && { width },
height && { height },
flex && { flex },
!width && !flex && !height && !style && { flex: 1 },
style
]}
>
{textDom}
</View>
);
}
}
const styles = StyleSheet.create({
cell: { justifyContent: 'center' },
text: { backgroundColor: 'transparent' }
});