Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@
"contributions": []
},
{
"login": "jpls93",
"name": "John Patrick Salcedo",
"avatar_url": "https://avatars2.githubusercontent.com/u/17956698?v=4",
"profile": "https://github.com/jpls93",
"contributions": [
"code"
]
},
"login": "ocarreterom",
"name": "Óscar Carretero",
"avatar_url": "https://avatars2.githubusercontent.com/u/11599942?v=4",
Expand Down
56 changes: 23 additions & 33 deletions src/components/badge.component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import styled from 'styled-components/native';

import { colors, fonts, normalize } from 'config';

Expand All @@ -10,39 +10,29 @@ type Props = {
largeText: boolean,
};

const styles = StyleSheet.create({
badge: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 18,
width: 18,
height: 18,
borderColor: colors.alabaster,
borderWidth: 1,
},
badgeText: {
...fonts.fontPrimaryBold,
backgroundColor: 'transparent',
},
textSmall: {
fontSize: normalize(7),
},
textLarge: {
fontSize: normalize(9.5),
},
});
const BadgeContainer = styled.View`
flex: 1;
align-items: 'center';
justify-content: 'center';
border-radius: 18;
width: 18;
height: 18;
border-color: ${colors.alabaster};
border-width: 1;
${({ backgroundColor }) => `background-color: ${backgroundColor};`};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do background-color: ${backgroundColor} instead,

`;

const BadgeText = styled.Text`
${{ ...fonts.fontPrimaryBold }};
background-color: 'transparent';
${({ largeText }) =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for this font-size: ${largeText ? normalize(9.5) : normalize(7)}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alejandronanez , might not work since unlike border-color: ${colors.alabaster};, colors is a file-wide variable whereas backgroundColor and largeText are props passed down to the styled components. https://www.styled-components.com/docs/basics#adapting-based-on-props

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alejandronanez , let me know if I can help you with anything else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, you're right. I missed that, sorry.
Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the usual way would be this though:

...
    font-size: ${({largeText}) => largeText ? normalize(9.5) : normalize(7)};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that would be more concise. I guess I just made the code style more consistent by making it parallel to how I wrote BadgeContainer's backgroundColor which doesn't have a default value. Since writing something without a default value that way would make it background-color: undefined which, without tree-shaking, would yield dead code.

`font-size: ${largeText ? normalize(9.5) : normalize(7)};`};
`;

export const Badge = ({ color, backgroundColor, text, largeText }: Props) => (
<View style={StyleSheet.flatten([styles.badge, { backgroundColor }])}>
<Text
style={[
styles.badgeText,
largeText ? styles.textLarge : styles.textSmall,
{ color },
]}
>
<BadgeContainer backgroundColor={backgroundColor}>
<BadgeText largeText={largeText} color={color}>
{text}
</Text>
</View>
</BadgeText>
</BadgeContainer>
);