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

@captaincodeman/transition

v1.0.2

Published

CSS Class Transitions

Downloads

1,153

Readme

x-transition

A Web Component for adding animated transition effects by swapping CSS classes. Useful if you want to use Tailwind CSS / Tailwind UI with something other than Alpine.js, Vue or React (e.g. lit-element / lit-html or Vanilla JavaScript).

Automatically handles nested transitions so parent isn't hidden until child transitions have completed.

702 bytes Brotli, 877 bytes Gzipped, 2.28 KB Minified.

demo

Usage

Wrap the element to transition with <x-transition> and set the open attribute or .open property to control visibility. Define the classes to apply using the attributes:

  • enter Applied when the element is being shown (enter transition)
  • enter-from Applied at the start of the enter transition
  • enter-to Applied at the end of the enter transition
  • leave Applied when the element is being hidden (leave transition)
  • leave-from Applied at the start of the leave transition
  • leave-to Applied at the end of the leave transition

After enter, the elements style.display property is cleared. After leave, the elements style.display property is set to none.

If the enter & leave transitions are symmetrical, a more compact definition can be used:

  • with Will apply the same values to enter and leave.
  • show Will apply the same values to enter-to and leave-from (i.e. the showing state).
  • hide Will apply the same values to enter-from and leave-to (i.e. the hiding state).

CDN / Static HTML / Vanilla JS

Add the script to the page:

<script src="https://unpkg.com/@captaincodeman/transition?module" type="module"></script>

Wrap elements to transition with <x-transition> element using Tailwind CSS suggested classes:

<!--
  Off-canvas menu overlay, show/hide based on off-canvas menu state.

  Entering: "transition-opacity ease-linear duration-300"
    From: "opacity-0"
    To: "opacity-100"
  Leaving: "transition-opacity ease-linear duration-300"
    From: "opacity-100"
    To: "opacity-0"
-->
<x-transition
    id="overlay"
    enter="transition-opacity ease-linear duration-300"
    enter-from="opacity-0"
    enter-to="opacity-100"
    leave="transition-opacity ease-linear duration-300"
    leave-from="opacity-100"
    leave-to="opacity-0">
  <div class="fixed inset-0">
    <div class="absolute inset-0 bg-gray-600 opacity-75"></div>
  </div>
</x-transition>

Or, alternatively, using the shortened form:

<x-transition 
    id="overlay"
    with="transition-opacity ease-linear duration-300"
    hide="opacity-0"
    show="opacity-100">
    &hellip;
</x-transition>

Show or hide the child element, with transition effects, by adding an open attribute to the <x-transition> element or by setting the .open property to true.

function showMenu() {
  overlay.open = true
}

Compiled Script

Install using npm:

npm install --save @captaincodeman/transition

Import into app:

import '@captaincodeman/transition'

Include in template using Tailwind CSS suggested classes setting show based on app templating system used (lit-element for instance):

<!--
  Profile dropdown panel, show/hide based on dropdown state.

  Entering: "transition ease-out duration-200"
    From: "transform opacity-0 scale-95"
    To: "transform opacity-100 scale-100"
  Leaving: "transition ease-in duration-75"
    From: "transform opacity-100 scale-100"
    To: "transform opacity-0 scale-95"
-->
<x-transition
    enter="transition ease-out duration-200"
    enter-from="transform opacity-0 scale-95"
    enter-to="transform opacity-100 scale-100"
    leave="transition ease-in duration-75"
    leave-from="transform opacity-100 scale-100"
    leave-to="transform opacity-0 scale-95"
  >
  <div class="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg">
    &hellip;
  </div>
</x-transition>

Group Key

It's possible that a separate set of transitions could be enclosed within some parent that also uses transitions. To avoid them all reacting / waiting on the wrong things, use a key attribute to group them.

e.g. all mobile menu related transitions might have key="mobile-menu" which would make them ignore events from other transitions and vice-versa.

TODO

Use tailwind example code