blob: 145c614c064e63d56a37b0993b85c8bd4df9b189 (
plain)
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
|
import React from 'react';
import {StyleSheet, Text} from 'react-native';
import moment from 'moment';
interface DateLabelProps {
timestamp: string;
type: 'default' | 'short' | 'small';
decorate?: (date: string) => string;
}
const DateLabel: React.FC<DateLabelProps> = ({
timestamp,
type,
decorate = (date) => `${date}`,
}) => {
let parsedDate = moment(timestamp);
if (!parsedDate) {
return <React.Fragment />;
}
switch (type) {
case 'default':
return (
<Text style={styles.default}>
{decorate(parsedDate.format('h:mm a • MMM D, YYYY'))}
</Text>
);
case 'short':
return (
<Text style={styles.default}>
{decorate(parsedDate.format('MMM D'))}
</Text>
);
case 'small':
return (
<Text style={styles.smallAndBlue}>
{decorate(parsedDate.format('MMM D'))}
</Text>
);
}
};
const styles = StyleSheet.create({
default: {
fontSize: 15,
color: '#c4c4c4',
},
smallAndBlue: {
fontSize: 14,
fontWeight: 'bold',
color: '#8FA9C2',
},
});
export default DateLabel;
|