aretherecookies-mobile/js/components/ItemTile.js

59 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2017-03-26 12:02:14 -05:00
//@flow
import React from 'react';
2017-05-21 19:44:51 -05:00
import { Text, View, Image } from 'react-native';
2017-03-26 12:02:14 -05:00
import theme from '../ui-theme';
import { getQuantityLabelText } from '../helpers/QuantityHelpers';
import moment from 'moment';
import type { Quantity } from '../constants/QuantityConstants';
2017-03-26 12:02:14 -05:00
const getRelativeDateText = (lastupdated: ?number) => {
return lastupdated ? ` - ${moment(lastupdated).fromNow()}` : '';
};
export const Thumbnail = ({ thumb }: { thumb: ?string }) => (
2017-04-20 16:28:13 -05:00
<View
style={{
height: theme.itemTile.thumbnailSize,
width: theme.itemTile.thumbnailSize,
borderRadius: Math.round(theme.itemTile.thumbnailSize / 2),
backgroundColor: theme.itemTile.thumbnailColor,
marginLeft: 16,
marginRight: 16,
marginTop: 4,
marginBottom: 4,
2017-04-20 16:28:13 -05:00
}}
>
{!!thumb && (
2017-05-21 19:44:51 -05:00
<Image
style={{
height: theme.itemTile.thumbnailSize,
width: theme.itemTile.thumbnailSize,
borderRadius: Math.round(theme.itemTile.thumbnailSize / 2),
}}
source={{ uri: thumb }}
/>
)}
</View>
);
2017-03-26 12:02:14 -05:00
export const StrongText = ({ children, style = {} }: { children?: string, style?: Object }) => {
return <Text style={{ ...theme.itemTile.itemNameStyle, ...style }}>{children}</Text>;
};
export const SubText = ({ children, style = {} }: { children?: string, style?: Object }) => {
return <Text style={{ ...theme.itemTile.itemPlaceStyle, ...style }}>{children}</Text>;
};
export const TileBox = ({ children, style = {} }: { children?: any, style?: Object }) => (
2018-04-23 16:16:04 -05:00
<View style={{ flexDirection: 'row', backgroundColor: 'white', alignItems: 'center', paddingTop: 15, paddingBottom: 15, ...style }}>
{children}
</View>
);
export const QuantityLine = ({ quantity, lastupdated }: { quantity: Quantity, lastupdated: ?number }) => (
<SubText>
{getQuantityLabelText(quantity)}
{getRelativeDateText(lastupdated)}
</SubText>
);