Skip to content

Commit 8b91b37

Browse files
committed
Add example using View Transition Classes and CSS Modules
I did have to rename my classes because there's a bug where generated CSS Module class names can have the `+` character in them which is invalid for View Transition Class Names.
1 parent f4b7bbc commit 8b91b37

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

fixtures/view-transition/src/components/Page.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import React, {
88

99
import './Page.css';
1010

11+
import transitions from './Transitions.module.css';
12+
1113
const a = (
1214
<div key="a">
1315
<ViewTransition>
@@ -24,6 +26,17 @@ const b = (
2426
</div>
2527
);
2628

29+
function Component() {
30+
return (
31+
<ViewTransition
32+
className={
33+
transitions['enter-slide-right'] + ' ' + transitions['exit-slide-left']
34+
}>
35+
<p>Slide In from Left, Slide Out to Right</p>
36+
</ViewTransition>
37+
);
38+
}
39+
2740
export default function Page() {
2841
const [show, setShow] = useState(false);
2942
useEffect(() => {
@@ -70,6 +83,7 @@ export default function Page() {
7083
<div>!!</div>
7184
</ViewTransition>
7285
</Activity>
86+
{show ? <Component /> : null}
7387
</div>
7488
);
7589
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@keyframes enter-slide-right {
2+
0% {
3+
opacity: 0;
4+
translate: -200px 0;
5+
}
6+
100% {
7+
opacity: 1;
8+
translate: 0 0;
9+
}
10+
}
11+
12+
@keyframes exit-slide-left {
13+
0% {
14+
opacity: 1;
15+
translate: 0 0;
16+
}
17+
100% {
18+
opacity: 0;
19+
translate: 200px 0;
20+
}
21+
}
22+
23+
::view-transition-new(.enter-slide-right):only-child {
24+
animation: enter-slide-right ease-in 0.25s;
25+
}
26+
::view-transition-old(.exit-slide-left):only-child {
27+
animation: exit-slide-left ease-in 0.25s;
28+
}

0 commit comments

Comments
 (0)