Skip to content
nuxt-penumbra
Esc
↑↓navigate↵open⌘Jpreview
On this page

Introduction

Animated theme switching for Nuxt, built on View Transitions.

nuxt-penumbra is a Nuxt module that animates theme switches with the View Transitions API: a circle that grows from the button you clicked, a fade, a wipe, or an effect you write yourself. It adds the animation to the theme handling you already have. With @nuxtjs/color-mode it only animates changes to preference. Without it, the module keeps a small theme store of its own.

The current version is 1.0.0. See the changelog for what each release changed.

The animation is the whole job. Your CSS decides what each theme looks like, and the theme is applied before first paint, so a reload shows no flash. Where the browser has no View Transitions API, or the visitor prefers reduced motion, the theme switches instantly.

Quick start

npm install nuxt-penumbra @nuxtjs/color-mode
export default defineNuxtConfig({
  modules: ['@nuxtjs/color-mode', 'nuxt-penumbra'],
  colorMode: { classSuffix: '' },
})
:root {
  color-scheme: light;
  --bg: #fff;
  --fg: #111;
}

:root.dark {
  color-scheme: dark;
  --bg: #000;
  --fg: #eee;
}

body {
  background: var(--bg);
  color: var(--fg);
}
<template>
  <PenumbraToggle />
  <NuxtPage />
</template>

Add the stylesheet to css in nuxt.config.ts. The circle opens from the click.

Where to go next

What it does not do

It ships no palette, leaves storage to @nuxtjs/color-mode and does not animate page navigation. Not covered yet lists what has not been tested, and prior art compares it with the alternatives.

Was this page helpful?