Skip to content

Commit

Permalink
feat: First View Transition integration (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD authored Nov 25, 2024
1 parent f1494a6 commit f098911
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
20 changes: 17 additions & 3 deletions apps/shelve/app/components/project/MainSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ function getProjectManager(manager: string) {
<div v-if="!loading">
<div class="flex items-start justify-between gap-4">
<div class="flex items-start gap-4">
<UAvatar :src="project.logo" size="xl" :alt="project.name" />
<UAvatar :src="project.logo" size="xl" :alt="project.name" class="logo" />
<div>
<h2 class="text-base font-semibold leading-7">
<h3 class="text-base font-semibold leading-7">
{{ project.name }}
</h2>
</h3>
<p class="text-sm leading-6 text-neutral-500">
{{ project.description }}
</p>
Expand Down Expand Up @@ -203,3 +203,17 @@ function getProjectManager(manager: string) {
</UModal>
</div>
</template>

<style scoped>
.logo {
view-transition-name: project-logo;
}
h3 {
view-transition-name: project-name;
}
p {
view-transition-name: project-description;
}
</style>
31 changes: 21 additions & 10 deletions apps/shelve/app/components/setting/ThemeToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const switchTheme = () => {
colorMode.preference = colorMode.value
}
function startViewTransition(theme) {
const startViewTransition = (theme) => {
if (theme === colorMode.value) return
if (!document.startViewTransition) {
switchTheme()
Expand All @@ -23,7 +23,16 @@ function startViewTransition(theme) {
switchTheme()
return
}
document.startViewTransition(switchTheme)
document.documentElement.classList.add('theme-transitioning')
const transition = document.startViewTransition(() => {
switchTheme()
})
transition.finished.then(() => {
document.documentElement.classList.remove('theme-transitioning')
})
}
</script>

Expand All @@ -46,24 +55,25 @@ function startViewTransition(theme) {
</template>

<style>
/* Dark/Light reveal effect */
::view-transition-group(root) {
.theme-transitioning::view-transition-group(root) {
animation-duration: 1.5s;
}
::view-transition-new(root),
::view-transition-old(root) {
.theme-transitioning::view-transition-new(root),
.theme-transitioning::view-transition-old(root) {
mix-blend-mode: normal;
}
::view-transition-new(root) {
.theme-transitioning::view-transition-new(root) {
animation-name: reveal-light;
}
::view-transition-old(root),
.dark::view-transition-old(root) {
.theme-transitioning::view-transition-old(root),
.dark.theme-transitioning::view-transition-old(root) {
animation: none;
}
.dark::view-transition-new(root) {
.dark.theme-transitioning::view-transition-new(root) {
animation-name: reveal-dark;
}
Expand All @@ -84,4 +94,5 @@ function startViewTransition(theme) {
clip-path: polygon(130% 0, -30% 0, -15% 100%, 110% 115%);
}
}
</style>
24 changes: 21 additions & 3 deletions apps/shelve/app/pages/projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const projects = useUserProjects()
const { loading, fetchProjects } = useProjects()
await fetchProjects()
const active = useState('active-project')
</script>

<template>
Expand All @@ -35,19 +37,21 @@ await fetchProjects()
:key="project.id"
:to="`/project/${project.id}`"
>
<UCard class="h-full">
<UCard class="h-full" @click.native="active = project.id">
<div class="flex w-full items-start gap-4">
<UAvatar
:src="project.logo"
:alt="project.name"
size="sm"
img-class="object-cover"
class="logo"
:class="{ active: active === project.id }"
/>
<div class="flex flex-col gap-1">
<h3 class="flex flex-col text-lg font-semibold">
<h3 class="flex flex-col text-lg font-semibold" :class="{ active: active === project.id }">
{{ project.name }}
</h3>
<div class="text-xs font-normal text-neutral-500">
<div class="text-xs font-normal text-neutral-500" :class="{ active: active === project.id }">
{{ project.description }}
</div>
</div>
Expand All @@ -61,3 +65,17 @@ await fetchProjects()
</div>
</div>
</template>

<style scoped>
.logo.active {
view-transition-name: project-logo;
}
h3.active {
view-transition-name: project-name;
}
div.active {
view-transition-name: project-description;
}
</style>
4 changes: 4 additions & 0 deletions apps/shelve/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default defineNuxtConfig({
compatibilityVersion: 4,
},

experimental: {
viewTransition: true,
},

ssr: false,

nitro: {
Expand Down

0 comments on commit f098911

Please sign in to comment.