Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add view transition navigation helper

Richie McIlroy8f3fe3b4859c
diff --git a/apps/web/utils/view-transition.ts b/apps/web/utils/view-transition.ts
new file mode 100644
index 000000000..e4d086cb7
--- /dev/null
+++ b/apps/web/utils/view-transition.ts
@@ -0,0 +1,23 @@
+export function navigateWithTransition(
+ transitionName: string,
+ navigate: () => void,
+) {
+ if (typeof document === "undefined") {
+ navigate();
+ return;
+ }
+ if (typeof document.startViewTransition !== "function") {
+ navigate();
+ return;
+ }
+ const html = document.documentElement;
+ html.dataset.viewTransition = transitionName;
+ const transition = document.startViewTransition(() => {
+ navigate();
+ });
+ transition.finished.finally(() => {
+ if (html.dataset.viewTransition === transitionName) {
+ delete html.dataset.viewTransition;
+ }
+ });
+}