-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useGenericTransition): add composable for generic from-to transi…
…tions
- Loading branch information
1 parent
369cfe5
commit 0dbe5a1
Showing
5 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { toRef, tryOnMounted, unref, unrefElement, watch } from "#imports"; | ||
import type { Simplify } from "../../types"; | ||
import { type StrongTweenVars, useGsap } from "../use-gsap"; | ||
import { | ||
useConstructTransition, | ||
type TransitionOutput, | ||
type UseConstructTransitionOptions, | ||
} from "./construct"; | ||
|
||
export type UseGenericTransitionOptions = Simplify< | ||
{ from: StrongTweenVars; to: StrongTweenVars } & UseConstructTransitionOptions | ||
>; | ||
/** | ||
* Composable to create generic transitions | ||
*/ | ||
export function useGenericTransition( | ||
options: UseGenericTransitionOptions, | ||
): TransitionOutput { | ||
const { from, to, ...constructOptions } = options; | ||
const container = toRef(constructOptions.parentContainer); | ||
|
||
const { set } = useGsap(); | ||
|
||
const { enterTl, leaveTl, ...output } = | ||
useConstructTransition(constructOptions); | ||
|
||
tryOnMounted(() => { | ||
set(container, from); | ||
}); | ||
|
||
watch( | ||
() => [unrefElement(container), unref(enterTl), unref(leaveTl)] as const, | ||
([parent, eTl, lTl]) => { | ||
if (!parent || !eTl || !lTl) return; | ||
|
||
eTl.fromTo(parent, from, to); | ||
|
||
lTl.fromTo(parent, to, from); | ||
}, | ||
{ immediate: true, flush: "post" }, | ||
); | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters