-
Notifications
You must be signed in to change notification settings - Fork 775
Refactor StateBadge component #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
68f7dab
6244d12
a96bace
0bd2f1e
d339c2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import React from 'react'; | ||
| import { Text, View, StyleSheet } from 'react-native'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| import { colors, fonts, normalize } from 'config'; | ||
| import { translate } from 'utils'; | ||
|
|
@@ -13,28 +13,17 @@ type Props = { | |
| locale: string, | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| badge: { | ||
| padding: 12, | ||
| paddingTop: 3, | ||
| paddingBottom: 3, | ||
| borderRadius: 20, | ||
| }, | ||
| mergedIssue: { | ||
| backgroundColor: colors.purple, | ||
| }, | ||
| openIssue: { | ||
| backgroundColor: colors.green, | ||
| }, | ||
| closedIssue: { | ||
| backgroundColor: colors.red, | ||
| }, | ||
| text: { | ||
| fontSize: normalize(12), | ||
| ...fonts.fontPrimarySemiBold, | ||
| color: colors.white, | ||
| }, | ||
| }); | ||
| 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, | ||
|
|
@@ -58,19 +47,18 @@ export const StateBadge = ({ | |
| issueText = translate('issue.main.states.closed', locale); | ||
| } | ||
|
|
||
| let issueStyle = {}; | ||
|
|
||
| if (issueState === 'merged') { | ||
| issueStyle = styles.mergedIssue; | ||
| } else if (issueState === 'open') { | ||
| issueStyle = styles.openIssue; | ||
| } else if (issueState === 'closed') { | ||
| issueStyle = styles.closedIssue; | ||
| } | ||
| const stateColor = { | ||
| merged: colors.purple, | ||
| open: colors.green, | ||
| closed: colors.red, | ||
| }; | ||
| const issueStateColor = stateColor[issueState] | ||
| ? stateColor[issueState] | ||
| : colors.gray; | ||
|
|
||
| return ( | ||
| <View style={[styles.badge, style, issueStyle]}> | ||
| <Text style={styles.text}>{issueText}</Text> | ||
| </View> | ||
| <Badge color={issueStateColor} style={style}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not passing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I thought to get completely rid of the style prop but it could still be useful in case there is a need to override something from a parent component without modifying again this one instead. But it's up for discussion, don't know if it is really needed or not so I left it there 😆
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prop
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was on Gitter, I added the relevant screenshot in the issue you opened. |
||
| <BadgeText>{issueText}</BadgeText> | ||
| </Badge> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used just for the Badge styles so I removed it. I don't think is needed here, also styled-components are already imported.
Also the styles defined for the Badge don't change the UI so they are useless for what I can saw.