-
Notifications
You must be signed in to change notification settings - Fork 775
refactor(badge): refactor badge component to use styled-components #535
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
8f04e76
e0d9ab2
674b184
8a83bd4
16cf3ac
e9dfb85
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 { StyleSheet, View, Text } from 'react-native'; | ||
| import styled from 'styled-components/native'; | ||
|
|
||
| import { colors, fonts, normalize } from 'config'; | ||
|
|
||
|
|
@@ -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};`}; | ||
| `; | ||
|
|
||
| const BadgeText = styled.Text` | ||
| ${{ ...fonts.fontPrimaryBold }}; | ||
| background-color: 'transparent'; | ||
| ${({ largeText }) => | ||
|
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. Same goes for this
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. Hi @alejandronanez , might not work since unlike
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. @alejandronanez , let me know if I can help you with anything else
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. Oh yeah, you're right. I missed that, sorry.
Contributor
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. the usual way would be this though:
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. 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 |
||
| `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> | ||
| ); | ||
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.
I think you can do
background-color: ${backgroundColor}instead,