-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathstate-badge.component.js
64 lines (56 loc) · 1.27 KB
/
state-badge.component.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
62
63
64
import React from 'react';
import styled from 'styled-components';
import { colors, fonts, normalize } from 'config';
import { t } from 'utils';
type Props = {
issue: Object,
isMerged: boolean,
text: string,
type: string,
style: Object,
locale: string,
};
const Badge = styled.View`
padding: 3px 12px;
border-radius: 20px;
background-color: ${props => props.color};
`;
const BadgeText = styled.Text`
color: ${colors.white};
font-size: ${normalize(12)};
${fonts.fontPrimarySemiBold};
`;
export const StateBadge = ({
issue,
isMerged,
text,
type,
style,
locale,
}: Props) => {
let issueState = type;
let issueText = text;
if (isMerged) {
issueState = 'merged';
issueText = t('Merged', locale);
} else if (issue && issue.state === 'open') {
issueState = 'open';
issueText = t('Open', locale);
} else if (issue && issue.state === 'closed') {
issueState = 'closed';
issueText = t('Closed', locale);
}
const stateColor = {
merged: colors.purple,
open: colors.green,
closed: colors.red,
};
const issueStateColor = stateColor[issueState]
? stateColor[issueState]
: colors.gray;
return (
<Badge color={issueStateColor} style={style}>
<BadgeText>{issueText}</BadgeText>
</Badge>
);
};