license import React from 'react' ; import { GestureResponderEvent , ImageProps , NativeSyntheticEvent , StyleSheet , TargetedEvent , } from 'react-native' ; import { EvaSize , EvaStatus , FalsyFC , FalsyText , RenderProp , TouchableWeb , TouchableWebElement , TouchableWebProps , Overwrite , LiteralUnion , } from '../../devsupport' ; import { Interaction , styled , StyledComponentProps , StyleType , } from '../../theme' ; import { TextProps } from '../text/text.component' ; type ButtonStyledProps = Overwrite < StyledComponentProps , { appearance ? : LiteralUnion < 'filled' | 'outline' | 'ghost' > ; } > ; export interface ButtonProps extends TouchableWebProps , ButtonStyledProps { children ? : RenderProp < TextProps > | React . ReactText ; accessoryLeft ? : RenderProp < Partial < ImageProps > > ; accessoryRight ? : RenderProp < Partial < ImageProps > > ; status ? : EvaStatus ; size ? : EvaSize ; } export type ButtonElement = React . ReactElement < ButtonProps > ; extends React . Component property property property property property property property overview-example overview-example overview-example overview-example overview-example overview-example overview-example overview-example overview-example overview-example @ styled ( 'Button' ) export class Button extends React . Component < ButtonProps > { private onMouseEnter = ( event ) : void => { this . props . eva . dispatch ( [ Interaction . HOVER ] ) ; this . props . onMouseEnter && this . props . onMouseEnter ( event ) ; } ; private onMouseLeave = ( event ) : void => { this . props . eva . dispatch ( [ ] ) ; this . props . onMouseLeave && this . props . onMouseLeave ( event ) ; } ; private onFocus = ( event ) : void => { this . props . eva . dispatch ( [ Interaction . FOCUSED ] ) ; this . props . onFocus && this . props . onFocus ( event ) ; } ; private onBlur = ( event ) : void => { this . props . eva . dispatch ( [ ] ) ; this . props . onBlur && this . props . onBlur ( event ) ; } ; private onPressIn = ( event ) : void => { this . props . eva . dispatch ( [ Interaction . ACTIVE ] ) ; this . props . onPressIn && this . props . onPressIn ( event ) ; } ; private onPressOut = ( event ) : void => { this . props . eva . dispatch ( [ ] ) ; this . props . onPressOut && this . props . onPressOut ( event ) ; } ; private getComponentStyle = ( source ) => { const { textColor , textFontFamily , textFontSize , textFontWeight , textMarginHorizontal , iconWidth , iconHeight , iconTintColor , iconMarginHorizontal , ... containerParameters } = source ; return { container : containerParameters , text : { color : textColor , fontFamily : textFontFamily , fontSize : textFontSize , fontWeight : textFontWeight , marginHorizontal : textMarginHorizontal , } , icon : { width : iconWidth , height : iconHeight , tintColor : iconTintColor , marginHorizontal : iconMarginHorizontal , } , } ; } ; public render ( ) { const { eva , style , accessoryLeft , accessoryRight , children , ... touchableProps } = this . props ; const evaStyle = this . getComponentStyle ( eva . style ) ; return ( < TouchableWeb { ... touchableProps } style = { [ evaStyle . container , styles . container , style ] } onMouseEnter = { this . onMouseEnter } onMouseLeave = { this . onMouseLeave } onFocus = { this . onFocus } onBlur = { this . onBlur } onPressIn = { this . onPressIn } onPressOut = { this . onPressOut } > < FalsyFC style = { evaStyle . icon } component = { accessoryLeft } / > < FalsyText style = { evaStyle . text } component = { children } / > < FalsyFC style = { evaStyle . icon } component = { accessoryRight } / > < /TouchableWeb>); } } const styles = StyleSheet . create ( { container : { flexDirection : 'row' , justifyContent : 'center' , alignItems : 'center' , } , } ) ;