@@ -16,42 +16,52 @@ import { ChevronDown } from '../../lib/icons/ChevronDown';
16
16
import { cn } from '../../lib/utils' ;
17
17
import { TextClassContext } from './text' ;
18
18
19
- const Accordion = React . forwardRef < AccordionPrimitive . RootRef , AccordionPrimitive . RootProps > (
20
- ( { children, ...props } , ref ) => {
21
- return (
22
- < LayoutAnimationConfig skipEntering >
23
- < AccordionPrimitive . Root ref = { ref } { ...props } asChild = { Platform . OS !== 'web' } >
24
- < Animated . View layout = { LinearTransition . duration ( 200 ) } > { children } </ Animated . View >
25
- </ AccordionPrimitive . Root >
26
- </ LayoutAnimationConfig >
27
- ) ;
28
- }
29
- ) ;
30
-
31
- Accordion . displayName = AccordionPrimitive . Root . displayName ;
19
+ function Accordion ( {
20
+ children,
21
+ ...props
22
+ } : Omit < AccordionPrimitive . RootProps , 'asChild' > & {
23
+ ref ?: React . RefObject < AccordionPrimitive . RootRef > ;
24
+ } ) {
25
+ return (
26
+ < LayoutAnimationConfig skipEntering >
27
+ < AccordionPrimitive . Root
28
+ { ...( props as AccordionPrimitive . RootProps ) }
29
+ asChild = { Platform . OS !== 'web' }
30
+ >
31
+ < Animated . View layout = { LinearTransition . duration ( 200 ) } > { children } </ Animated . View >
32
+ </ AccordionPrimitive . Root >
33
+ </ LayoutAnimationConfig >
34
+ ) ;
35
+ }
32
36
33
- const AccordionItem = React . forwardRef < AccordionPrimitive . ItemRef , AccordionPrimitive . ItemProps > (
34
- ( { className, value, ...props } , ref ) => {
35
- return (
36
- < Animated . View className = { 'overflow-hidden' } layout = { LinearTransition . duration ( 200 ) } >
37
- < AccordionPrimitive . Item
38
- ref = { ref }
39
- className = { cn ( 'border-b border-border' , className ) }
40
- value = { value }
41
- { ...props }
42
- />
43
- </ Animated . View >
44
- ) ;
45
- }
46
- ) ;
47
- AccordionItem . displayName = AccordionPrimitive . Item . displayName ;
37
+ function AccordionItem ( {
38
+ className,
39
+ value,
40
+ ...props
41
+ } : AccordionPrimitive . ItemProps & {
42
+ ref ?: React . RefObject < AccordionPrimitive . ItemRef > ;
43
+ } ) {
44
+ return (
45
+ < Animated . View className = { 'overflow-hidden' } layout = { LinearTransition . duration ( 200 ) } >
46
+ < AccordionPrimitive . Item
47
+ className = { cn ( 'border-b border-border' , className ) }
48
+ value = { value }
49
+ { ...props }
50
+ />
51
+ </ Animated . View >
52
+ ) ;
53
+ }
48
54
49
55
const Trigger = Platform . OS === 'web' ? View : Pressable ;
50
56
51
- const AccordionTrigger = React . forwardRef <
52
- AccordionPrimitive . TriggerRef ,
53
- AccordionPrimitive . TriggerProps
54
- > ( ( { className, children, ...props } , ref ) => {
57
+ function AccordionTrigger ( {
58
+ className,
59
+ children,
60
+ ...props
61
+ } : AccordionPrimitive . TriggerProps & {
62
+ children ?: React . ReactNode ;
63
+ ref ?: React . RefObject < AccordionPrimitive . TriggerRef > ;
64
+ } ) {
55
65
const { isExpanded } = AccordionPrimitive . useItemContext ( ) ;
56
66
57
67
const progress = useDerivedValue ( ( ) =>
@@ -65,7 +75,7 @@ const AccordionTrigger = React.forwardRef<
65
75
return (
66
76
< TextClassContext . Provider value = 'native:text-lg font-medium web:group-hover:underline' >
67
77
< AccordionPrimitive . Header className = 'flex' >
68
- < AccordionPrimitive . Trigger ref = { ref } { ...props } asChild >
78
+ < AccordionPrimitive . Trigger { ...props } asChild >
69
79
< Trigger
70
80
className = { cn (
71
81
'flex flex-row web:flex-1 items-center justify-between py-4 web:transition-all group web:focus-visible:outline-none web:focus-visible:ring-1 web:focus-visible:ring-muted-foreground' ,
@@ -81,13 +91,15 @@ const AccordionTrigger = React.forwardRef<
81
91
</ AccordionPrimitive . Header >
82
92
</ TextClassContext . Provider >
83
93
) ;
84
- } ) ;
85
- AccordionTrigger . displayName = AccordionPrimitive . Trigger . displayName ;
94
+ }
86
95
87
- const AccordionContent = React . forwardRef <
88
- AccordionPrimitive . ContentRef ,
89
- AccordionPrimitive . ContentProps
90
- > ( ( { className, children, ...props } , ref ) => {
96
+ function AccordionContent ( {
97
+ className,
98
+ children,
99
+ ...props
100
+ } : AccordionPrimitive . ContentProps & {
101
+ ref ?: React . RefObject < AccordionPrimitive . ContentRef > ;
102
+ } ) {
91
103
const { isExpanded } = AccordionPrimitive . useItemContext ( ) ;
92
104
return (
93
105
< TextClassContext . Provider value = 'native:text-lg' >
@@ -96,14 +108,13 @@ const AccordionContent = React.forwardRef<
96
108
'overflow-hidden text-sm web:transition-all' ,
97
109
isExpanded ? 'web:animate-accordion-down' : 'web:animate-accordion-up'
98
110
) }
99
- ref = { ref }
100
111
{ ...props }
101
112
>
102
113
< InnerContent className = { cn ( 'pb-4' , className ) } > { children } </ InnerContent >
103
114
</ AccordionPrimitive . Content >
104
115
</ TextClassContext . Provider >
105
116
) ;
106
- } ) ;
117
+ }
107
118
108
119
function InnerContent ( { children, className } : { children : React . ReactNode ; className ?: string } ) {
109
120
if ( Platform . OS === 'web' ) {
@@ -120,6 +131,4 @@ function InnerContent({ children, className }: { children: React.ReactNode; clas
120
131
) ;
121
132
}
122
133
123
- AccordionContent . displayName = AccordionPrimitive . Content . displayName ;
124
-
125
134
export { Accordion , AccordionContent , AccordionItem , AccordionTrigger } ;
0 commit comments