npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tailwindcss-view-transitions

v0.1.1

Published

TailwindCSS plugin for customizing styles for the View Transitions Web API

Downloads

2,221

Readme

tailwindcss-view-transitions

NPM package version

A plugin for customizing styles for the View Transitions Web API.

Installation

npm install -D tailwindcss-view-transitions

Then add the plugin to your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require("tailwindcss-view-transitions"),
    // ...
  ],
}

Usage

Use the vt-name-[ANY_STRING] utility class to create a separate view transition on specific elements.

<div class="vt-name-[main-header]">
</div>

Use vt-name-none to disable a view transition. Can be used with any Tailwind variant, such as md:*.

<div class="vt-name-[main-header] md:vt-name-none">
</div>

<div class="vt-name-[main-header] motion-reduce:vt-name-none">
</div>

The name can be any string except root (❌ vt-name-[root]), which is reserved for the default top-level view transition.

| Class | CSS properties | | --- | --- | | vt-name-[foo] | view-transition-name: foo; | | vt-name-[foo-bar] | view-transition-name: foo-bar; | | vt-name-none | view-transition-name: none; |

Styling with CSS

Style the view transition pseudo-elements from your global CSS file.

/* input.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

::view-transition-old(main-content) {
  /* Add custom animation or style here */
  /* animation: ... */
}

::view-transition-new(main-content) {
  /* Add custom animation or style here */
  /* animation: ... */
}

Configuration

Alternatively, you can define styles from plugin configuration in your tailwind.config.js file.

// tailwind.config.js
module.exports = {
  plugins: [
    require("tailwindcss-view-transitions")({
      disableAllReduceMotion: false,
      styles: {
        // ...
      },
    }),
    // ... other plugins
  ],
}

Options

The plugin config accepts an options object as argument which contains these properties. All are optional.

disableAllReduceMotion

  • Type: boolean
  • Default: false

Disables all view transitions animation if user has set preference for reduced motion. (Note: Consider this point before disabling animations completely.)

If true, it applies this code globally:

@media (prefers-reduced-motion) {
  ::view-transition-group(*),::view-transition-old(*),::view-transition-new(*) {
    animation: none !important;
  }
}

styles

  • Type: Record<string, CSSRuleObject & { old?: CSSRuleObject; new?: CSSRuleObject }>
  • Default: {}

Defines CSS styles for the view transition pseudo-elements.

The styles object may contain any number of properties.

  • The key is the view transition name (root or any string value assigned here)
  • The value is one or more of these:
    • a CSS rule object, which will be applied to both outgoing (::view-transition-old(VT_NAME)) and incoming (::view-transition-new(VT_NAME)) pseudo-elements
    • a propery old containing a CSS rule object, which will be applied only to ::view-transition-old(VT_NAME)
    • a propery new containing a CSS rule object, which will be applied only to ::view-transition-new(VT_NAME)

| styles config | Generated CSS | | --- | --- | | { root: { animation: "none" },} | ::view-transition-old(root),::view-transition-new(root) { animation: none;} | | { root: { old: { animationDuration: "1s" }, new: { animationDuration: "3s" }, },} | ::view-transition-old(root) { animation-duration: 1s;}::view-transition-new(root) { animation-duration: 3s;} | | { root: { animation: "none" }, "main-content": { old: { animationDuration: "1s" }, new: { animationDuration: "3s" }, },} | ::view-transition-old(root),::view-transition-new(root) { animation: none;}::view-transition-old(main-content) { animation-duration: 1s;}::view-transition-new(main-content) { animation-duration: 3s;} |

⚠️ If applying custom CSS animation, you need to define @keyframes separately in your CSS file or through Tailwind theme configuration, or alternatively use an existing @keyframes animation.

Detailed examples: https://github.com/ekafyi/tailwindcss-view-transitions/blob/main/docs/examples.md

When not to use?

You may not need this plugin if:

  • You don’t need to customize the default browser transition styles
  • You do styling outside of Tailwind configuration
  • You exclusively use a (meta)framework that has its own API for conveniently styling view transitions, such as Astro

As an unofficial plugin, it will be deprecated when/if Tailwind adds an official plugin for styling view transitions.

Bugs & feature requests

While I'm not actively accepting feature requests, I outlined future plans in the Discussions.

Found a bug? Feel free to open an issue.