Update styling & add onClose to StatsTable to make it modal
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { FlatList, StyleSheet, View } from 'react-native'
|
import { Dimensions, FlatList, StyleSheet, View } from 'react-native'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
|
import CloseIcon from './close-icon'
|
||||||
|
|
||||||
import cycleModule from '../../lib/cycle'
|
import cycleModule from '../../lib/cycle'
|
||||||
import { Spacing, Typography, Colors } from '../../styles'
|
import { Sizes, Spacing, Typography, Colors } from '../../styles'
|
||||||
import { humanizeDate } from '../helpers/format-date'
|
import { humanizeDate } from '../helpers/format-date'
|
||||||
|
|
||||||
const Item = ({ data }) => {
|
const Item = ({ data }) => {
|
||||||
@@ -35,26 +36,35 @@ Item.propTypes = {
|
|||||||
data: PropTypes.object.isRequired,
|
data: PropTypes.object.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatsTable = () => {
|
const StatsTable = ({ onClose }) => {
|
||||||
const renderItem = ({ item }) => <Item data={item} />
|
const renderItem = ({ item }) => <Item data={item} />
|
||||||
const data = cycleModule().getStats()
|
const data = cycleModule().getStats()
|
||||||
|
|
||||||
if (!data || data.length === 0) return false
|
if (!data || data.length === 0) return false
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<View style={styles.modalContainer}>
|
||||||
data={data}
|
<View style={styles.headerContainer}>
|
||||||
renderItem={renderItem}
|
<CloseIcon onClose={onClose} />
|
||||||
keyExtractor={(item) => item.date}
|
</View>
|
||||||
ItemSeparatorComponent={ItemDivider}
|
<FlatList
|
||||||
ListHeaderComponent={FlatListHeader}
|
data={data}
|
||||||
ListHeaderComponentStyle={styles.headerDivider}
|
renderItem={renderItem}
|
||||||
stickyHeaderIndices={[0]}
|
keyExtractor={(item) => item.date}
|
||||||
contentContainerStyle={styles.container}
|
ItemSeparatorComponent={ItemDivider}
|
||||||
/>
|
ListHeaderComponent={FlatListHeader}
|
||||||
|
ListHeaderComponentStyle={styles.headerDivider}
|
||||||
|
stickyHeaderIndices={[0]}
|
||||||
|
contentContainerStyle={styles.container}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatsTable.propTypes = {
|
||||||
|
onClose: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
const ItemDivider = () => <View style={styles.divider} />
|
const ItemDivider = () => <View style={styles.divider} />
|
||||||
|
|
||||||
const FlatListHeader = () => (
|
const FlatListHeader = () => (
|
||||||
@@ -72,6 +82,17 @@ const FlatListHeader = () => (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
accentCell: {
|
||||||
|
flex: 3,
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
cell: {
|
||||||
|
flex: 2,
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
container: {
|
||||||
|
paddingHorizontal: Spacing.base,
|
||||||
|
},
|
||||||
divider: {
|
divider: {
|
||||||
height: 1,
|
height: 1,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -81,27 +102,31 @@ const styles = StyleSheet.create({
|
|||||||
...Typography.accentOrange,
|
...Typography.accentOrange,
|
||||||
paddingVertical: Spacing.small,
|
paddingVertical: Spacing.small,
|
||||||
},
|
},
|
||||||
|
headerContainer: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
paddingTop: Spacing.base,
|
||||||
|
paddingRight: Spacing.base,
|
||||||
|
},
|
||||||
headerDivider: {
|
headerDivider: {
|
||||||
borderBottomColor: Colors.purple,
|
borderBottomColor: Colors.purple,
|
||||||
borderBottomWidth: 2,
|
borderBottomWidth: 2,
|
||||||
},
|
},
|
||||||
|
modalContainer: {
|
||||||
|
alignSelf: 'center',
|
||||||
|
backgroundColor: Colors.turquoiseLight,
|
||||||
|
marginTop: Sizes.huge * 2,
|
||||||
|
maxHeight: Dimensions.get('window').height * 0.7,
|
||||||
|
minHeight: '40%',
|
||||||
|
position: 'absolute',
|
||||||
|
width: '100%',
|
||||||
|
},
|
||||||
row: {
|
row: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
paddingVertical: Spacing.tiny,
|
paddingVertical: Spacing.tiny,
|
||||||
backgroundColor: Colors.turquoiseLight,
|
backgroundColor: Colors.turquoiseLight,
|
||||||
},
|
},
|
||||||
cell: {
|
|
||||||
flex: 2,
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
accentCell: {
|
|
||||||
flex: 3,
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
container: {
|
|
||||||
paddingHorizontal: Spacing.base,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export default StatsTable
|
export default StatsTable
|
||||||
|
|||||||
Reference in New Issue
Block a user