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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ydant/transition

v0.2.0

Published

Transition components for Ydant

Readme

@ydant/transition

CSS transition components for Ydant.

Installation

pnpm add @ydant/transition

Usage

Transition (Enter-only)

For simple show/hide with enter animation:

import { mount, type Component } from "@ydant/core";
import { createBasePlugin, div, button, text, on, type Slot } from "@ydant/base";
import { Transition } from "@ydant/transition";

const App: Component = () => {
  let show = true;
  let transitionSlot: Slot;

  return div(function* () {
    yield* button(() => [
      on("click", () => {
        show = !show;
        transitionSlot.refresh(() =>
          Transition({
            show,
            enter: "transition-opacity duration-300",
            enterFrom: "opacity-0",
            enterTo: "opacity-100",
            content: () => div(() => [text("Fade me!")]),
          }),
        );
      }),
      text("Toggle"),
    ]);

    transitionSlot = yield* div(() =>
      Transition({
        show,
        enter: "transition-opacity duration-300",
        enterFrom: "opacity-0",
        enterTo: "opacity-100",
        content: () => div(() => [text("Fade me!")]),
      }),
    );
  });
};

createTransition (Enter + Leave)

For full enter/leave animation support with programmatic control:

import { type Component } from "@ydant/core";
import { div, button, text, on } from "@ydant/base";
import { createTransition, type TransitionHandle } from "@ydant/transition";

const App: Component = () => {
  let fadeTransition: TransitionHandle;

  return div(function* () {
    yield* button(function* () {
      yield* on("click", async () => {
        const isVisible = fadeTransition.slot.node.firstElementChild !== null;
        await fadeTransition.setShow(!isVisible);
      });
      yield* text("Toggle");
    });

    fadeTransition = yield* createTransition({
      enter: "fade-enter",
      enterFrom: "fade-enter-from",
      enterTo: "fade-enter-to",
      leave: "fade-leave",
      leaveFrom: "fade-leave-from",
      leaveTo: "fade-leave-to",
      content: () => div(() => [text("Animated content")]),
    });
  });
};

CSS Classes

Both Transition and createTransition use explicit class props:

| Prop | When Applied | | ----------- | -------------------------- | | enter | During enter animation | | enterFrom | Initial state before enter | | enterTo | Final state after enter | | leave | During leave animation | | leaveFrom | Initial state before leave | | leaveTo | Final state after leave |

All props are optional. Classes are applied as space-separated strings (e.g. Tailwind CSS compatible).

Example CSS

.fade-enter {
  transition: opacity 300ms ease;
}
.fade-enter-from {
  opacity: 0;
}
.fade-enter-to {
  opacity: 1;
}
.fade-leave {
  transition: opacity 300ms ease;
}
.fade-leave-from {
  opacity: 1;
}
.fade-leave-to {
  opacity: 0;
}

TransitionGroup

For animating lists of items:

import { type Component } from "@ydant/core";
import { div, text } from "@ydant/base";
import { TransitionGroup, createTransitionGroupRefresher } from "@ydant/transition";

const App: Component = () => {
  const items = [
    { id: 1, text: "Item 1" },
    { id: 2, text: "Item 2" },
  ];

  return div(function* () {
    const slot = yield* TransitionGroup({
      items,
      keyFn: (item) => item.id,
      enter: "transition-opacity duration-300",
      enterFrom: "opacity-0",
      enterTo: "opacity-100",
      leave: "transition-opacity duration-300",
      leaveFrom: "opacity-100",
      leaveTo: "opacity-0",
      content: (item) => div(() => [text(item.text)]),
    });

    // To update with transitions, use createTransitionGroupRefresher
  });
};

Updating with createTransitionGroupRefresher

createTransitionGroupRefresher creates a stateful refresh function that applies enter/leave transitions on list updates:

const refresher = createTransitionGroupRefresher({
  keyFn: (item) => item.id,
  enter: "transition-opacity duration-300",
  enterFrom: "opacity-0",
  enterTo: "opacity-100",
  leave: "transition-opacity duration-300",
  leaveFrom: "opacity-100",
  leaveTo: "opacity-0",
  content: (item) => div(() => [text(item.text)]),
});

// Later, update items with transitions:
refresher(slot, newItems);

API

Transition

function Transition(props: TransitionProps): Render;

interface TransitionProps {
  show: boolean;
  enter?: string;
  enterFrom?: string;
  enterTo?: string;
  leave?: string;
  leaveFrom?: string;
  leaveTo?: string;
  content: () => Render;
}

Enter-only transition component. For leave animations, use createTransition.

createTransition

function* createTransition(
  props: Omit<TransitionProps, "show">,
): TransitionInstruction;

type TransitionInstruction = Generator<Element, TransitionHandle, Slot>;

interface TransitionHandle {
  slot: Slot;
  setShow(show: boolean): Promise<void>;
}

Creates a transition with programmatic show/hide control including leave animations.

TransitionGroup

function* TransitionGroup<T>(props: TransitionGroupProps<T>): ElementRender;

interface TransitionGroupProps<T> {
  items: T[];
  keyFn: (item: T) => string | number;
  enter?: string;
  enterFrom?: string;
  enterTo?: string;
  leave?: string;
  leaveFrom?: string;
  leaveTo?: string;
  content: (item: T, index: number) => ElementRender;
}

createTransitionGroupRefresher

function createTransitionGroupRefresher<T>(
  props: Omit<TransitionGroupProps<T>, "items">,
): (slot: Slot, items: T[]) => void;

Creates a stateful refresher that applies enter/leave transitions when updating items.

Low-level APIs

function enterTransition(el: HTMLElement, props: TransitionProps): Promise<void>;
function leaveTransition(el: HTMLElement, props: TransitionProps): Promise<void>;

Module Structure

  • Transition.ts - Transition, createTransition, enterTransition, leaveTransition
  • TransitionGroup.ts - TransitionGroup, createTransitionGroupRefresher
  • utils.ts - CSS class helpers (addClasses, removeClasses, waitForTransition)