@@ -3,6 +3,10 @@ import { Text, StyleSheet, View, Pressable } from "react-native";
3
3
import { colors , paddings , rounded , textStyles } from '../../style' ;
4
4
import LoadingDots from "../../animations/LoadingDots" ;
5
5
6
+ /**
7
+ * Style configurations for different button types
8
+ * Defines background colors, text colors, and border styles for each button type
9
+ */
6
10
const typeStyles = {
7
11
primary : { backgroundColor : colors . violet500 , textColor : colors . white } ,
8
12
secondary : { backgroundColor : colors . grey800 , textColor : colors . white } ,
@@ -14,6 +18,10 @@ const typeStyles = {
14
18
} ,
15
19
} ;
16
20
21
+ /**
22
+ * Style configurations for different button states
23
+ * Defines how buttons appear in different states: default, hover, pressed, disabled, loading
24
+ */
17
25
const stateStyles = {
18
26
default : {
19
27
primary : { backgroundColor : colors . violet500 } ,
@@ -34,7 +42,6 @@ const stateStyles = {
34
42
primary : { backgroundColor : colors . grey100 , textColor : colors . grey600 } ,
35
43
secondary : { backgroundColor : colors . grey100 , textColor : colors . grey600 } ,
36
44
tertiary : { backgroundColor : colors . white , textColor : colors . grey500 , borderColor : colors . grey500 , borderWidth : 1 } ,
37
-
38
45
} ,
39
46
loading : {
40
47
primary : { backgroundColor : colors . violet500 } ,
@@ -43,13 +50,24 @@ const stateStyles = {
43
50
} ,
44
51
} ;
45
52
53
+ /**
54
+ * Style configurations for different button sizes
55
+ * Defines height and padding for each size variant
56
+ */
46
57
const sizeStyles = {
47
58
1 : { height : 32 , padding : paddings . p_4 } ,
48
59
2 : { height : 40 , padding : paddings . p_8 } ,
49
60
3 : { height : 48 , padding : paddings . p_12 } ,
50
61
4 : { height : 56 , padding : paddings . p_16 } ,
51
62
} ;
52
63
64
+ /**
65
+ * Combines styles based on button type, state, and size
66
+ * @param {string } type - Button type (primary, secondary, tertiary)
67
+ * @param {string } state - Button state (default, hover, pressed, disabled, loading)
68
+ * @param {number } size - Button size (1-4)
69
+ * @returns {Object } Combined style object
70
+ */
53
71
const getCombinedStyles = ( type , state , size ) => {
54
72
const typeStyle = typeStyles [ type ] ;
55
73
const stateStyle = stateStyles [ state ] ?. [ type ] ;
@@ -62,6 +80,17 @@ const getCombinedStyles = (type, state, size) => {
62
80
} ;
63
81
} ;
64
82
83
+ /**
84
+ * CustomButtonIcon Component
85
+ * A button component that displays an icon with configurable styles and states
86
+ *
87
+ * @param {Object } containerStyle - Custom styles for the button container
88
+ * @param {Function } onPress - Function to call when button is pressed
89
+ * @param {string } type - Button type: "primary", "secondary", or "tertiary"
90
+ * @param {number } size - Button size: 1 (smallest) to 4 (largest)
91
+ * @param {React.ReactNode } icon - Icon component to display
92
+ * @param {boolean } disabled - Whether the button is disabled
93
+ */
65
94
const CustomButtonIcon = ( {
66
95
containerStyle,
67
96
onPress,
@@ -74,6 +103,7 @@ const CustomButtonIcon = ({
74
103
const state = disabled ? 'disabled' : buttonState ;
75
104
const combinedStyles = getCombinedStyles ( type , state , size ) ;
76
105
106
+ // Handle button press events
77
107
const handlePressIn = ( ) => {
78
108
if ( ! disabled ) {
79
109
setButtonState ( 'pressed' ) ;
@@ -111,13 +141,13 @@ const CustomButtonIcon = ({
111
141
] }
112
142
onPress = { handlePress }
113
143
onPressIn = { handlePressIn }
114
- onPressOut = { handlePressOut }
144
+ onPressOut = { handlePressOut }
115
145
disabled = { disabled }
116
- >
117
- < View style = { styles . contentContainer } >
118
- { icon && < View style = { styles . icon } > { icon } </ View > }
119
- </ View >
120
- </ Pressable >
146
+ >
147
+ < View style = { styles . contentContainer } >
148
+ { icon && < View style = { styles . icon } > { icon } </ View > }
149
+ </ View >
150
+ </ Pressable >
121
151
) ;
122
152
} ;
123
153
0 commit comments