1
- import { createAccordion } from '@gluestack-ui/accordion' ;
2
1
import React from 'react' ;
2
+ import { createAccordion } from '@gluestack-ui/accordion' ;
3
3
import { View , Pressable , Text , Platform } from 'react-native' ;
4
4
import {
5
5
tva ,
6
6
withStyleContext ,
7
+ withStyleContextAndStates ,
7
8
useStyleContext ,
8
- withStates ,
9
+ VariantProps ,
9
10
} from '@gluestack-ui/nativewind-utils' ;
10
11
11
12
import { H3 } from '@expo/html-elements' ;
@@ -14,14 +15,13 @@ import { cssInterop } from 'nativewind';
14
15
/** Styles */
15
16
16
17
const accordionStyle = tva ( {
17
- base : 'w-full shadow-sm ' ,
18
+ base : 'w-full' ,
18
19
variants : {
19
20
variant : {
20
21
filled : 'bg-white' ,
21
22
} ,
22
23
} ,
23
24
} ) ;
24
-
25
25
const accordionItemStyle = tva ( {
26
26
parentVariants : {
27
27
variant : {
@@ -30,7 +30,6 @@ const accordionItemStyle = tva({
30
30
} ,
31
31
} ,
32
32
} ) ;
33
-
34
33
const accordionTitleTextStyle = tva ( {
35
34
base : 'text-typography-900 font-bold flex-1 text-left' ,
36
35
parentVariants : {
@@ -44,7 +43,6 @@ const accordionTitleTextStyle = tva({
44
43
const accordionIconStyle = tva ( {
45
44
base : 'text-typography-900' ,
46
45
} ) ;
47
-
48
46
const accordionContentTextStyle = tva ( {
49
47
base : 'text-typography-700 font-normal' ,
50
48
parentVariants : {
@@ -55,25 +53,28 @@ const accordionContentTextStyle = tva({
55
53
} ,
56
54
} ,
57
55
} ) ;
58
-
59
56
const accordionHeaderStyle = tva ( {
60
57
base : 'mx-0 my-0' ,
61
58
} ) ;
62
59
const accordionContentStyle = tva ( {
63
60
base : 'px-5 mt-2 pb-5' ,
64
61
} ) ;
65
-
66
62
const accordionTriggerStyle = tva ( {
67
63
base : 'w-full py-5 px-5 flex-row justify-between items-center web:outline-none focus:outline-none data-[disabled=true]:opacity-40 data-[disabled=true]:cursor-not-allowed data-[focus-visible=true]:bg-background-50' ,
68
64
} ) ;
69
65
70
66
/** Creator */
71
67
const UIAccordion = createAccordion ( {
72
- Root : withStyleContext ( View ) ,
68
+ //@ts -ignore
69
+ Root :
70
+ Platform . OS === 'web'
71
+ ? withStyleContext ( Pressable )
72
+ : withStyleContextAndStates ( Pressable ) ,
73
73
Item : View ,
74
74
// @ts -ignore
75
75
Header : Platform . OS === 'web' ? H3 : View ,
76
- Trigger : Platform . OS === 'web' ? Pressable : withStates ( Pressable ) ,
76
+ //@ts -ignore
77
+ Trigger : Pressable ,
77
78
Icon : View ,
78
79
TitleText : Text ,
79
80
ContentText : Text ,
@@ -89,33 +90,71 @@ cssInterop(UIAccordion.TitleText, { className: 'style' });
89
90
cssInterop ( UIAccordion . Content , { className : 'style' } ) ;
90
91
cssInterop ( UIAccordion . ContentText , { className : 'style' } ) ;
91
92
93
+ type IAccordionProps = React . ComponentProps < typeof UIAccordion > &
94
+ VariantProps < typeof accordionStyle > ;
95
+
96
+ type IAccordionItemProps = React . ComponentProps < typeof UIAccordion . Item > &
97
+ VariantProps < typeof accordionItemStyle > ;
98
+
99
+ type IAccordionContentProps = React . ComponentProps < typeof UIAccordion . Content > &
100
+ VariantProps < typeof accordionContentStyle > ;
101
+
102
+ type IAccordionContentTextProps = React . ComponentProps <
103
+ typeof UIAccordion . ContentText
104
+ > &
105
+ VariantProps < typeof accordionContentTextStyle > ;
106
+
107
+ type IAccordionIconProps = React . ComponentProps < typeof UIAccordion . Icon > & {
108
+ as ?: any ;
109
+ } ;
110
+
111
+ type IAccordionHeaderProps = React . ComponentProps < typeof UIAccordion . Header > &
112
+ VariantProps < typeof accordionHeaderStyle > ;
113
+
114
+ type IAccordionTriggerProps = React . ComponentProps < typeof UIAccordion . Trigger > &
115
+ VariantProps < typeof accordionTriggerStyle > ;
116
+
117
+ type IAccordionTitleTextProps = React . ComponentProps <
118
+ typeof UIAccordion . TitleText
119
+ > &
120
+ VariantProps < typeof accordionTitleTextStyle > ;
121
+
92
122
/** Components */
93
123
94
124
const Accordion = React . forwardRef (
95
125
(
96
- { className, variant = 'filled' , size = 'md' , ...props } : any ,
126
+ {
127
+ className,
128
+ variant = 'filled' ,
129
+ //@ts -ignore
130
+ size = 'md' ,
131
+ ...props
132
+ } : { className ?: string } & IAccordionProps ,
97
133
ref ?: any
98
134
) => {
99
135
return (
100
136
< UIAccordion
101
137
ref = { ref }
102
138
{ ...props }
103
- className = { accordionStyle ( { variant, size , class : className } ) }
139
+ className = { accordionStyle ( { variant, class : className } ) }
104
140
context = { { variant, size } }
105
141
/>
106
142
) ;
107
143
}
108
144
) ;
109
145
110
146
const AccordionItem = React . forwardRef (
111
- ( { className, ...props } : any , ref ?: any ) => {
112
- const { variant, size } = useStyleContext ( ) ;
147
+ (
148
+ { className, ...props } : { className ?: string } & IAccordionItemProps ,
149
+ ref ?: any
150
+ ) => {
151
+ const { variant } = useStyleContext ( ) ;
113
152
return (
114
153
< UIAccordion . Item
115
154
ref = { ref }
116
155
{ ...props }
117
156
className = { accordionItemStyle ( {
118
- parentVariants : { variant, size } ,
157
+ parentVariants : { variant } ,
119
158
class : className ,
120
159
} ) }
121
160
/>
@@ -124,7 +163,10 @@ const AccordionItem = React.forwardRef(
124
163
) ;
125
164
126
165
const AccordionContent = React . forwardRef (
127
- ( { className, ...props } : any , ref ?: any ) => {
166
+ (
167
+ { className, ...props } : { className ?: string } & IAccordionContentProps ,
168
+ ref ?: any
169
+ ) => {
128
170
return (
129
171
< UIAccordion . Content
130
172
ref = { ref }
@@ -138,36 +180,56 @@ const AccordionContent = React.forwardRef(
138
180
) ;
139
181
140
182
const AccordionContentText = React . forwardRef (
141
- ( { className, ...props } : any , ref ?: any ) => {
142
- const { variant, size } = useStyleContext ( ) ;
183
+ (
184
+ {
185
+ className,
186
+ ...props
187
+ } : { className ?: string } & IAccordionContentTextProps ,
188
+ ref ?: any
189
+ ) => {
190
+ const { size } = useStyleContext ( ) ;
143
191
return (
144
192
< UIAccordion . ContentText
145
193
ref = { ref }
146
194
{ ...props }
147
195
className = { accordionContentTextStyle ( {
148
- parentVariants : { variant , size } ,
196
+ parentVariants : { size } ,
149
197
class : className ,
150
198
} ) }
151
199
/>
152
200
) ;
153
201
}
154
202
) ;
155
203
156
- const AccordionIcon = React . forwardRef (
157
- ( { className, ...props } : any , ref ?: any ) => {
204
+ const AccordionIcon = ( {
205
+ className,
206
+ as : AsComp ,
207
+ ...props
208
+ } : IAccordionIconProps & { className ?: any } ) => {
209
+ if ( AsComp ) {
158
210
return (
159
- < UIAccordion . Icon
160
- ref = { ref }
161
- { ...props }
211
+ < AsComp
162
212
className = { accordionIconStyle ( {
163
213
class : className ,
164
214
} ) }
215
+ { ...props }
165
216
/>
166
217
) ;
167
218
}
168
- ) ;
219
+ return (
220
+ < UIAccordion . Icon
221
+ className = { accordionIconStyle ( {
222
+ class : className ,
223
+ } ) }
224
+ { ...props }
225
+ />
226
+ ) ;
227
+ } ;
169
228
const AccordionHeader = React . forwardRef (
170
- ( { className, ...props } : any , ref ?: any ) => {
229
+ (
230
+ { className, ...props } : { className ?: string } & IAccordionHeaderProps ,
231
+ ref ?: any
232
+ ) => {
171
233
return (
172
234
< UIAccordion . Header
173
235
ref = { ref }
@@ -180,7 +242,10 @@ const AccordionHeader = React.forwardRef(
180
242
}
181
243
) ;
182
244
const AccordionTrigger = React . forwardRef (
183
- ( { className, ...props } : any , ref ?: any ) => {
245
+ (
246
+ { className, ...props } : { className ?: string } & IAccordionTriggerProps ,
247
+ ref ?: any
248
+ ) => {
184
249
return (
185
250
< UIAccordion . Trigger
186
251
ref = { ref }
@@ -193,14 +258,17 @@ const AccordionTrigger = React.forwardRef(
193
258
}
194
259
) ;
195
260
const AccordionTitleText = React . forwardRef (
196
- ( { className, ...props } : any , ref ?: any ) => {
197
- const { variant, size } = useStyleContext ( ) ;
261
+ (
262
+ { className, ...props } : { className ?: string } & IAccordionTitleTextProps ,
263
+ ref ?: any
264
+ ) => {
265
+ const { size } = useStyleContext ( ) ;
198
266
return (
199
- < UIAccordion . Header
267
+ < UIAccordion . TitleText
200
268
ref = { ref }
201
269
{ ...props }
202
270
className = { accordionTitleTextStyle ( {
203
- parentVariants : { variant , size } ,
271
+ parentVariants : { size } ,
204
272
class : className ,
205
273
} ) }
206
274
/>
0 commit comments