Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #41 from loadsmart/feature/component-update
Browse files Browse the repository at this point in the history
Feature/component update
  • Loading branch information
lenoirzamboni committed Oct 9, 2019
2 parents 6a373aa + fe92197 commit b375742
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/components/Buttons/PrimaryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class PrimaryButton extends PureComponent<ButtonProps> {
return (
<ThemeContext.Consumer>
{theme => {
const styles = themedStyles(theme)
const styles = themedStyles(theme, this.props.style)
return (
<TouchableOpacity onPress={this.onPress.bind(this)}>
<View style={[styles.wrapper, this.props.style]}>
Expand All @@ -40,7 +40,9 @@ export default class PrimaryButton extends PureComponent<ButtonProps> {
}

private renderLoadingState = (styles: any) => {
return <ActivityIndicator color={Colors.White} style={styles.activityIndicator} />
return (
<ActivityIndicator color={styles.activityIndicator.color} style={styles.activityIndicator} />
)
}

private onPress = () => {
Expand All @@ -51,7 +53,7 @@ export default class PrimaryButton extends PureComponent<ButtonProps> {
}
}

const themedStyles = (theme: Partial<Theme>) => {
const themedStyles = (theme: Partial<Theme>, style: any) => {
return StyleSheet.create({
wrapper: {
flexDirection: 'row',
Expand All @@ -66,14 +68,16 @@ const themedStyles = (theme: Partial<Theme>) => {
marginRight: 8,
},
text: {
color: 'white',
fontFamily: Fonts.SharpSansExtrabold,
fontSize: 15,
alignSelf: 'center',
fontFamily: Fonts.SharpSansExtrabold,
color: style && style.color ? style.color : Colors.White,
fontSize: style && style.fontSize ? style.fontSize : 15,
fontWeight: style && style.fontWeight ? style.fontWeight : 'normal',
},
activityIndicator: {
alignSelf: 'center',
position: 'absolute',
color: style && style.color ? style.color : Colors.White,
},
})
}
44 changes: 42 additions & 2 deletions src/components/Buttons/__tests__/PrimaryButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import { ActivityIndicator, Text, TouchableOpacity, Image } from 'react-native'
import { ActivityIndicator, Text, TouchableOpacity, Image, ViewStyle } from 'react-native'
import renderer from 'react-test-renderer'
import PrimaryButton from '../PrimaryButton'
import { ButtonDisplayState, ButtonProps } from '../ButtonProps'
import { Images } from '../../../res'
import { Images, Colors } from '../../../res'

describe('PrimaryButton', () => {
describe('when state is normal', () => {
Expand All @@ -16,6 +16,7 @@ describe('PrimaryButton', () => {
title: 'accept',
displayState: ButtonDisplayState.Normal,
onPress: onPressCallback,
style: undefined,
}
testRenderer = renderer.create(<PrimaryButton {...props} />)
})
Expand Down Expand Up @@ -43,6 +44,28 @@ describe('PrimaryButton', () => {
it('has a valid snapshot', () => {
expect(testRenderer.toJSON()).toMatchSnapshot()
})

it('renders button text with custom style', () => {
const style = {
color: Colors.White,
fontSize: 12,
fontWeight: 'bold',
}
const props = {
icon: Images.Warning,
title: 'accept',
displayState: ButtonDisplayState.Normal,
onPress: onPressCallback,
style: style,
} as ButtonProps

testRenderer = renderer.create(<PrimaryButton {...props} />)
const text = testRenderer.root.findByType(Text)

expect(text.props.style.color).toBe(style.color)
expect(text.props.style.fontSize).toBe(style.fontSize)
expect(text.props.style.fontWeight).toBe(style.fontWeight)
})
})

describe('when state is loading', () => {
Expand Down Expand Up @@ -79,6 +102,23 @@ describe('PrimaryButton', () => {
it('has a valid snapshot', () => {
expect(testRenderer.toJSON()).toMatchSnapshot()
})

it('renders activity indicator with custom spinner color', () => {
const style = {
color: Colors.DarkGrey,
}
const props = {
title: 'accept',
displayState: ButtonDisplayState.Loading,
onPress: onPressCallback,
style: style,
} as ButtonProps

testRenderer = renderer.create(<PrimaryButton {...props} />)
const activityIndicator = testRenderer.root.findByType(ActivityIndicator)

expect(activityIndicator.props.style.color).toBe(style.color)
})
})

describe('when state is disabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ exports[`PrimaryButton when state is disabled has a valid snapshot 1`] = `
style={
Object {
"alignSelf": "center",
"color": "white",
"color": "#fff",
"fontFamily": "SharpSans-Extrabold",
"fontSize": 15,
"fontWeight": "normal",
}
}
>
Expand Down Expand Up @@ -88,6 +89,7 @@ exports[`PrimaryButton when state is loading has a valid snapshot 1`] = `
style={
Object {
"alignSelf": "center",
"color": "#fff",
"position": "absolute",
}
}
Expand Down Expand Up @@ -147,9 +149,10 @@ exports[`PrimaryButton when state is normal has a valid snapshot 1`] = `
style={
Object {
"alignSelf": "center",
"color": "white",
"color": "#fff",
"fontFamily": "SharpSans-Extrabold",
"fontSize": 15,
"fontWeight": "normal",
}
}
>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Dialogs/__tests__/Dialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Image, Text } from 'react-native'
import { Image, Text, ButtonProps } from 'react-native'
import renderer from 'react-test-renderer'
import { Dialog, DialogProps } from '../Dialog'
import DialogBox from '../DialogBox'
Expand Down Expand Up @@ -51,10 +51,13 @@ describe('Dialog', () => {
})

it('renders buttons if passed as prop', () => {
const buttonProps: any = {
style: { color: 'white' },
}
const props: DialogProps = {
buttons: (
<>
<PrimaryButton title={'Confirm'} />
<PrimaryButton title={'Confirm'} {...buttonProps} />
<SecondaryButton title={'Cancel'} />
</>
),
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInputs/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class NumberInput extends PureComponent<Props, State> {
keyboardType={Platform.OS === 'ios' ? 'number-pad' : 'default'}
maxLength={1}
selectionColor={Colors.Transparent}
style={[styles.container, borderStyle]}
style={[styles.container, borderStyle, this.props.style]}
onChangeText={this.onChangeText}
onBlur={this.onBlur}
onFocus={this.onFocus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`NumberInput render renders with gray border when blurred 1`] = `
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -60,6 +61,7 @@ exports[`NumberInput render renders with green border when focused 1`] = `
Object {
"borderColor": "#14d64d",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -65,6 +66,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -96,6 +98,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -127,6 +130,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -158,6 +162,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -189,6 +194,7 @@ exports[`PinCodeTextInput render renders all number inputs with a digit if auth
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -231,6 +237,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -262,6 +269,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -293,6 +301,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -324,6 +333,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -355,6 +365,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -386,6 +397,7 @@ exports[`PinCodeTextInput render renders all number inputs with a empty value if
Object {
"borderColor": "#c4ccd6",
},
undefined,
]
}
underlineColorAndroid="transparent"
Expand Down

0 comments on commit b375742

Please sign in to comment.