Back to blogs
Blog
Writing in public
Longer posts — published here first, then cross-posted to Dev.to with a canonical URL back to this site.
Blog
Longer posts — published here first, then cross-posted to Dev.to with a canonical URL back to this site.
Back to blogs
Back to blogs
Postcss, transitions, themes, web
Add cool effect when trnsitionning from light to dark mode using css and view...
Date published

Why You Might Still Pick Next.js Over TanStack Start From a TanStack Start...

A complete theme management system for React applications with SSR support! ✨ 🌟...

A guide to creating Android home screen widgets using Expo modules, complete with state management,...
<video controls width="320" height="240" autoplay src="https://github.com/tigawanna/view-transition-theme-change-react/blob/main/public/view-transitions.mp4?raw=true" title="Title"></video>
copied from @jhey on twitter
>[!NOTE]
This assumes you've already have your dark light mode setup with some sort of function to update your theme
1 /* Angled */2 [data-style='angled']::view-transition-old(root) {3 animation: none;4 z-index: -1;5 }67 [data-style='angled']::view-transition-new(root) {8 animation: unclip 1s;9 clip-path: polygon(-100vmax 100%, 100% 100%, 100% -100vmax);10 }1112 @keyframes unclip {13 0% {14 clip-path: polygon(100% 100%, 100% 100%, 100% 100%);15 }16 }17
data-style="angled" attribute is set on the root element in SPA react we use a useEffect hook1 useEffect(() => {2 // set the data-style attribute3 document.documentElement.dataset.style = "angled";4 }, []);
in SSR it can be set directly in the html tag
documnet.startViewTransition to start the view transition1 function transitionColors() {2 if (typeof window !== "undefined") {3 document.startViewTransition(() => {4 const newTheme = theme === "light" ? "dark" : "light";5 document.documentElement.dataset.theme = newTheme;6 updateTheme(newTheme);7 });8 }9 }10
more transition styles can be added by including the corresponding css file and adding the correct data-style attribute
1 <select2 className="select select-bordered select-sm max-w-xs"3 onChange={(e) =>4 (document.documentElement.dataset.style = e.target.value)5 }6 >7 <option value="default">Default</option>8 <option value="vertical">Vertical</option>9 <option value="wipe">Wipe</option>10 <option value="angled">Angled</option>11 <option value="flip">Flip</option>12 <option value="slides">Slides</option>13 </select>
If you like this type of css tricks consider following jhey