-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
61 lines (55 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react'
import { ScrollView, Text, View, ViewPropTypes } from 'react-native'
import { StyleSheet } from 'fela-tools'
import * as colors from '../../../../utils/colors'
import { getCellColor, toPercent } from '../../../../utils/helpers'
import { TablePropTypes } from '../../../../utils/types'
import { wrapRenderer } from '../helpers'
const rules = StyleSheet.create({
table: {},
row: {
flexDirection: 'row',
},
cell: {
flex: 1,
padding: 10,
},
text: {
textAlign: 'center',
color: colors.white,
},
})
const TableComponent = ({ table, ...props }, { renderer }) => (
<ScrollView
removeClippedSubviews={false}
{...props}
style={renderer.renderRule(rules.table, props.style)}
>
{table.map((row, rowIndex) => (
<View key={`row-${rowIndex}`} style={renderer.renderRule(rules.row)}>
{row.map((value, columnIndex) => (
<View
key={`row-${rowIndex}-column-${columnIndex}`}
style={[
renderer.renderRule(rules.cell),
{
backgroundColor: getCellColor(parseFloat(value)),
},
]}
>
<Text numberOfLines={1} style={renderer.renderRule(rules.text)}>
{toPercent(value)}
</Text>
</View>
))}
</View>
))}
</ScrollView>
)
TableComponent.key = 'fela-inline-table'
TableComponent.title = 'Fela (Inline)'
TableComponent.propTypes = {
style: ViewPropTypes.style,
table: TablePropTypes.isRequired,
}
export default wrapRenderer(TableComponent)