1
- import { type CSSProperties , useEffect , useRef , useState } from "react" ;
2
- import { useIsomorphicEffect , useMergeRefs } from "../../hooks" ;
1
+ import { type CSSProperties , useEffect , useState } from "react" ;
2
+ import { useElementTransitionStatus , useIsomorphicEffect , useMergeRefs } from "../../hooks" ;
3
3
import type { EmptyObject , PrimitiveProps } from "../../primitives" ;
4
4
import { useOrientation } from "../../primitives/composite/orientation-context" ;
5
5
import { tx } from "../../utils" ;
6
- import { useCollapsibleContent } from "./collapsible-context" ;
6
+ import { useCollapsibleContent } from "./collapsible-content- context" ;
7
7
8
8
export const CollapsibleContent = ( props : PrimitiveProps < "div" , EmptyObject , "id" > ) => {
9
9
const { children, ref, ...rest } = props ;
10
10
11
- const { id, open, mounted, status, setElement } = useCollapsibleContent ( ) ;
12
-
13
11
const orientation = useOrientation ( true ) ;
14
12
15
- const elemRef = useRef < HTMLDivElement > ( null ) ;
13
+ const { id, open, duration } = useCollapsibleContent ( ) ;
14
+
15
+ const { isMounted, status, element, setElement } = useElementTransitionStatus ( open , { duration } ) ;
16
+
16
17
const [ size , setSize ] = useState < { width ?: number ; height ?: number } > ( ) ;
17
18
18
- const [ skipAnimation , setSkipAnimation ] = useState ( open || mounted ) ;
19
+ const [ skipAnimation , setSkipAnimation ] = useState ( open || isMounted ) ;
19
20
20
21
useEffect ( ( ) => {
21
22
const raf = requestAnimationFrame ( ( ) => {
@@ -28,19 +29,19 @@ export const CollapsibleContent = (props: PrimitiveProps<"div", EmptyObject, "id
28
29
} , [ ] ) ;
29
30
30
31
useIsomorphicEffect ( ( ) => {
31
- if ( mounted && elemRef . current ) {
32
- const rect = elemRef . current . getBoundingClientRect ( ) ;
32
+ if ( isMounted && element ) {
33
+ const rect = element . getBoundingClientRect ( ) ;
33
34
34
35
setSize ( {
35
36
width : rect . width ,
36
37
height : rect . height ,
37
38
} ) ;
38
39
}
39
- } , [ mounted ] ) ;
40
+ } , [ element , isMounted ] ) ;
40
41
41
- const refs = useMergeRefs ( ref , elemRef , setElement ) ;
42
+ const refs = useMergeRefs ( ref , setElement ) ;
42
43
43
- if ( ! mounted ) {
44
+ if ( ! isMounted ) {
44
45
return null ;
45
46
}
46
47
0 commit comments