@@ -4,48 +4,72 @@ import {
44 Text ,
55 TextStyle ,
66 TouchableOpacity ,
7+ ActivityIndicator ,
78 TouchableOpacityProps ,
89 ViewStyle ,
910} from "react-native" ;
1011import { reduceOpacity } from "../utils/reduceOpacity" ;
1112import MaterialIcons from "react-native-vector-icons/MaterialIcons" ;
12- import { COLORS } from "../utils/colors " ;
13+ import { COLORS } from "../utils/constants " ;
1314
1415interface ButtonOutlineProps extends TouchableOpacityProps {
16+ // container style
1517 title ?: string ;
18+ useColor ?: string ;
19+ style ?: ViewStyle ;
1620
17- disabled ?: boolean ;
18- useColor ?: string ; // rgb format required
21+ // container style utils
1922 opacityReducer ?: number ;
20- textOpacityReducer ?: number ;
2123 padding ?: number ;
2224 borderRadius ?: number ;
23- materialIcon ?: string ;
24- iconAlignRight ?: boolean ;
25- iconSize ?: number ;
26- iconColor ?: string ;
2725 noDisabledStyle ?: boolean ;
2826
29- style ?: ViewStyle ;
27+ // text style
3028 textStyle ?: TextStyle ;
29+
30+ // text style utils
31+ textOpacityReducer ?: number ;
32+
33+ // manage state
34+ disabled ?: boolean ;
35+ buttonLoading ?: boolean ;
36+
37+ // icon props
38+ materialIconRight ?: string ;
39+ materialIconLeft ?: string ;
40+ iconColor ?: string ;
41+ iconSize ?: number ;
3142}
3243
3344const ButtonOutline : FunctionComponent < ButtonOutlineProps > = ( {
45+ // container style
3446 title,
47+ useColor = COLORS . PRIMARY ,
3548 style,
36- textStyle,
37- disabled = false ,
38- useColor = COLORS . PRIMARY , // rgb format required
39- opacityReducer = 2 ,
40- textOpacityReducer = 6 ,
49+
50+ // container style utils
51+ opacityReducer = 3 ,
4152 padding = 18 ,
4253 borderRadius = 4 ,
43- materialIcon,
54+ noDisabledStyle = false ,
55+
56+ // text style
57+ textStyle = { } ,
58+
59+ // text style utils
60+ textOpacityReducer = 5 ,
61+
62+ // manage state
63+ disabled = false ,
64+ buttonLoading = false ,
65+
66+ // icon props
67+ materialIconRight,
68+ materialIconLeft,
4469 iconColor = useColor ,
45- iconAlignRight = false ,
70+ iconSize = 18 ,
71+
4672 onPress,
47- iconSize = 20 ,
48- noDisabledStyle,
4973} ) => {
5074 const borderWidth = 1 ;
5175 const backgroundColor = reduceOpacity ( useColor , opacityReducer ) ;
@@ -75,67 +99,64 @@ const ButtonOutline: FunctionComponent<ButtonOutlineProps> = ({
7599 outlineText : {
76100 color : useColor , // same as main color
77101 textAlign : "center" ,
102+ marginHorizontal : 7 ,
78103 } ,
79104 outlineTextDisabled : {
80- color : reduceOpacity ( useColor , textOpacityReducer ) , // main color with less opacity
105+ color : noDisabledStyle
106+ ? useColor
107+ : reduceOpacity ( useColor , textOpacityReducer ) , // main color with less opacity
81108 textAlign : "center" ,
109+ marginHorizontal : 7 ,
82110 } ,
83111 } ) ;
84112
85113 return (
86114 < >
87- { disabled ? (
88- // disabled button
89- < TouchableOpacity
90- style = { [
91- noDisabledStyle ? styles . button : styles . disabledButton ,
92- style ,
93- ] }
94- disabled = { disabled }
95- onPress = { onPress }
96- >
97- { ! iconAlignRight && materialIcon && (
98- < MaterialIcons
99- color = { iconColor }
100- name = { materialIcon }
101- size = { iconSize }
102- />
103- ) }
104- { /* disabled text */ }
105- < Text style = { [ styles . outlineTextDisabled , textStyle ] } > { title } </ Text >
106- { iconAlignRight && materialIcon && (
107- < MaterialIcons
108- color = { iconColor }
109- name = { materialIcon }
110- size = { iconSize }
111- />
112- ) }
113- </ TouchableOpacity >
114- ) : (
115- // enabled button
116- < TouchableOpacity
117- style = { [ styles . button , style ] }
118- disabled = { disabled }
119- onPress = { onPress }
120- >
121- { ! iconAlignRight && materialIcon && (
122- < MaterialIcons
123- color = { iconColor }
124- name = { materialIcon }
125- size = { iconSize }
126- />
127- ) }
128- { /* enabled text */ }
129- < Text style = { [ styles . outlineText , textStyle ] } > { title } </ Text >
130- { iconAlignRight && materialIcon && (
131- < MaterialIcons
132- color = { iconColor }
133- name = { materialIcon }
134- size = { iconSize }
135- />
136- ) }
137- </ TouchableOpacity >
138- ) }
115+ < TouchableOpacity
116+ style = { [
117+ noDisabledStyle || ! disabled ? styles . button : styles . disabledButton ,
118+ style ,
119+ ] }
120+ disabled = { disabled }
121+ onPress = { onPress }
122+ >
123+ { materialIconLeft && ! buttonLoading && (
124+ < MaterialIcons
125+ color = {
126+ disabled && noDisabledStyle
127+ ? reduceOpacity ( iconColor , textOpacityReducer )
128+ : iconColor
129+ }
130+ name = { materialIconLeft }
131+ size = { iconSize }
132+ />
133+ ) }
134+
135+ { buttonLoading ? (
136+ < ActivityIndicator color = { useColor } />
137+ ) : (
138+ < Text
139+ style = { [
140+ ! disabled ? styles . outlineText : styles . outlineTextDisabled ,
141+ textStyle ,
142+ ] }
143+ >
144+ { title }
145+ </ Text >
146+ ) }
147+
148+ { materialIconRight && ! buttonLoading && (
149+ < MaterialIcons
150+ color = {
151+ disabled && ! noDisabledStyle
152+ ? reduceOpacity ( iconColor , textOpacityReducer )
153+ : iconColor
154+ }
155+ name = { materialIconRight }
156+ size = { iconSize }
157+ />
158+ ) }
159+ </ TouchableOpacity >
139160 </ >
140161 ) ;
141162} ;
0 commit comments