1
1
import React from 'react' ;
2
2
import { createButton } from '@gluestack-ui/button' ;
3
+
3
4
import {
4
5
tva ,
5
6
withStyleContextAndStates ,
6
7
useStyleContext ,
7
8
withStyleContext ,
9
+ cssInterop ,
10
+ VariantProps ,
8
11
} from '@gluestack-ui/nativewind-utils' ;
12
+
9
13
import {
10
14
ActivityIndicator ,
11
15
Pressable ,
12
16
Text ,
13
17
View ,
14
18
Platform ,
15
19
} from 'react-native' ;
16
- import { cssInterop } from 'nativewind' ;
17
20
18
21
const UIButton = createButton ( {
19
22
// @ts -ignore
@@ -34,23 +37,24 @@ cssInterop(UIButton.Spinner, { className: 'style' });
34
37
cssInterop ( UIButton . Icon , { className : 'style' } ) ;
35
38
36
39
const buttonStyle = tva ( {
37
- base : 'group/button rounded-lg bg-primary-500 flex-row items-center justify-center data-[focus=true]:outline-none data-[focus-visible=true]:ring-2 ' ,
40
+ base : 'group/button rounded-lg bg-primary-500 flex-row items-center justify-center data-[focus=true]:web: outline-none data-[focus-visible=true]:web :ring-2 ' ,
38
41
variants : {
39
42
action : {
40
43
primary :
41
- 'bg-primary-500 hover:bg-primary-600 active:bg-primary-700 border-primary-300 hover:border-primary-400 active:border-primary-500 data-[focus-visible=true]:ring-primary-500' ,
44
+ 'bg-primary-500 hover:bg-primary-600 active:bg-primary-700 border-primary-300 hover:border-primary-400 active:border-primary-500 data-[focus-visible=true]:web: ring-primary-500' ,
42
45
secondary :
43
- 'bg-secondary-500 border-secondary-300 hover:bg-secondary-600 hover:border-secondary-400 active:bg-secondary-700 active:border-secondary-500 data-[focus-visible=true]:ring-secondary-500' ,
46
+ 'bg-secondary-500 border-secondary-300 hover:bg-secondary-600 hover:border-secondary-400 active:bg-secondary-700 active:border-secondary-500 data-[focus-visible=true]:web: ring-secondary-500' ,
44
47
positive :
45
- 'bg-success-500 border-success-300 hover:bg-success-600 hover:border-success-400 active:bg-success-700 active:border-success-500 data-[focus-visible=true]:ring-success-500' ,
48
+ 'bg-success-500 border-success-300 hover:bg-success-600 hover:border-success-400 active:bg-success-700 active:border-success-500 data-[focus-visible=true]:web: ring-success-500' ,
46
49
negative :
47
- 'bg-error-500 border-error-300 hover:bg-error-600 hover:border-error-400 active:bg-error-700 active:border-error-500 data-[focus-visible=true]:ring-error-500' ,
50
+ 'bg-error-500 border-error-300 hover:bg-error-600 hover:border-error-400 active:bg-error-700 active:border-error-500 data-[focus-visible=true]:web: ring-error-500' ,
48
51
default : 'bg-transparent hover:bg-background-50 active:bg-transparent' ,
49
52
} ,
50
53
variant : {
51
54
link : 'px-0' ,
52
55
outline :
53
56
'bg-transparent border hover:bg-background-50 active:bg-transparent' ,
57
+ solid : '' ,
54
58
} ,
55
59
56
60
size : {
@@ -156,6 +160,11 @@ const buttonTextStyle = tva({
156
160
] ,
157
161
} ) ;
158
162
163
+ type IButtonProps = React . ComponentProps < typeof UIButton > &
164
+ VariantProps < typeof buttonStyle > ;
165
+
166
+ type IButtonTextProps = React . ComponentProps < typeof UIButton . Text > &
167
+ VariantProps < typeof buttonTextStyle > ;
159
168
const Button = React . forwardRef (
160
169
(
161
170
{
@@ -164,11 +173,12 @@ const Button = React.forwardRef(
164
173
size = 'md' ,
165
174
action = 'primary' ,
166
175
...props
167
- } : any ,
176
+ } : { className ?: string } & IButtonProps ,
168
177
ref
169
178
) => {
170
179
return (
171
180
< UIButton
181
+ // @ts -ignore
172
182
ref = { ref }
173
183
{ ...props }
174
184
className = { buttonStyle ( { variant, size, action, class : className } ) }
@@ -178,8 +188,20 @@ const Button = React.forwardRef(
178
188
}
179
189
) ;
180
190
191
+ type IButtonIcon = React . ComponentProps < typeof UIButton . Icon > & {
192
+ as ?: any ;
193
+ } ;
181
194
const ButtonText = React . forwardRef (
182
- ( { className, variant, size, action, ...props } : any , ref ) => {
195
+ (
196
+ {
197
+ className,
198
+ variant,
199
+ size,
200
+ action,
201
+ ...props
202
+ } : { className ?: string } & IButtonTextProps ,
203
+ ref ?: any
204
+ ) => {
183
205
const {
184
206
variant : parentVariant ,
185
207
size : parentSize ,
@@ -188,6 +210,7 @@ const ButtonText = React.forwardRef(
188
210
189
211
return (
190
212
< UIButton . Text
213
+ // @ts -ignore
191
214
ref = { ref }
192
215
{ ...props }
193
216
className = { buttonTextStyle ( {
@@ -208,13 +231,19 @@ const ButtonText = React.forwardRef(
208
231
209
232
const ButtonSpinner = UIButton . Spinner ;
210
233
211
- const ButtonIcon = ( { className, as : AsComp , ...props } : any ) => {
234
+ const ButtonIcon = ( {
235
+ className,
236
+ as : AsComp ,
237
+ ...props
238
+ } : IButtonIcon & { className ?: any } ) => {
212
239
if ( AsComp ) {
213
240
return < AsComp className = { className } { ...props } /> ;
214
241
}
215
242
return < UIButton . Icon className = { className } { ...props } /> ;
216
243
} ;
217
244
Button . displayName = 'Button' ;
218
245
ButtonText . displayName = 'ButtonText' ;
246
+ ButtonSpinner . displayName = 'ButtonSpinner' ;
247
+ ButtonIcon . displayName = 'ButtonIcon' ;
219
248
220
249
export { Button , ButtonText , ButtonSpinner , ButtonIcon } ;
0 commit comments