Created
July 8, 2019 21:51
-
-
Save kaueDM/dafda2d88e4d93d8b6a858db53aa2577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Spinner from '../Spinner' | |
import ButtonIcon from './ButtonIcon' | |
import ButtonLabel from './ButtonLabel' | |
import ButtonContainer from './ButtonContainer' | |
import ButtonInterface from './ButtonInterface' | |
import { TouchableWithoutFeedback } from 'react-native' | |
const Button: React.FC<ButtonInterface> = (props) => { | |
const { | |
theme, | |
icon, | |
label, | |
onPress, | |
color, | |
disabled, | |
outline, | |
loading | |
} = props | |
const buttonContainerProps = { ...props } | |
const spinnerProps = { | |
loading, | |
color: outline ? color : `${color.split('-')[0]}-contrast` | |
} | |
const buttonIconProps = { | |
theme, | |
icon, | |
color, | |
disabled, | |
outline, | |
loading | |
} | |
const buttonLabelProps = { | |
theme, | |
icon, | |
label, | |
color, | |
disabled, | |
outline, | |
loading | |
} | |
delete buttonContainerProps['onPress'] | |
return ( | |
<TouchableWithoutFeedback onPress={disabled ? null : onPress}> | |
<ButtonContainer {...buttonContainerProps}> | |
<Spinner {...spinnerProps} /> | |
<ButtonIcon {...buttonIconProps} /> | |
<ButtonLabel {...buttonLabelProps} /> | |
</ButtonContainer> | |
</TouchableWithoutFeedback> | |
) | |
} | |
Button.defaultProps = { | |
loading: false, | |
disabled: false | |
} | |
export default Button |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Container: