Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

hello-goodbye

tobyzerner122MIT0.2.2TypeScript support: included

Tiny library to apply enter, leave, and move transitions to DOM elements.

readme

Hello Goodbye

Tiny library to apply enter, leave, and move transitions to DOM elements. Inspired by Vue's <transition> and <transition-group> components, but in plain DOM.

Size

Demo

Installation

npm install hello-goodbye --save

Usage

hello

Apply an enter transition to a newly-added element.

import { hello } from 'hello-goodbye';

parent.appendChild(el);
hello(el);
.enter-active { transition: transform .5s }
.enter-from { transform: translateY(100%) }

goodbye

Apply a leave transition to an element and remove it when finished.

import { goodbye } from 'hello-goodbye';

goodbye(el).then(() => parent.removeChild(el));
.leave-active { transition: opacity .5s }
.leave-to { opacity: 0 }

move

Smoothly move elements into their new positions.

import { move } from 'hello-goodbye';

move(parent.children, () => {
    // Shuffle the children
    for (let i = parent.children.length; i >= 0; i--) {
        parent.appendChild(parent.children[Math.random() * i | 0]);
    }
});
.move { transition: transform .5s }

transition

Run a named transition on an element. Used under the hood by hello and goodbye.

  1. The ${name}-active and ${name}-from classes are added
  2. Next frame: the ${name}-from class is removed, and the ${name}-to class is added
  3. When the transition ends: all classes are removed and the returned Promise resolves
import { transition } from 'hello-goodbye';

transition(
    el: HTMLElement,
    name: string,
    options?: TransitionOptions
): Promise<void>;

type TransitionOptions = {
    prefix?: string // optional prefix for animation class names
};

cancel

Cancel any currently-running transition on an element.

import { cancel } from 'hello-goodbye';

cancel(el: HTMLElement);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

changelog

Changelog

0.2.1 (2023-06-25)

Bug Fixes

  • fix transitions not running reliably (85c8c24)

0.2.0 (2023-03-21)

⚠ BREAKING CHANGES

  • Removed finish callback from options. Use the Promise returned from hello and goodbye instead.

Bug Fixes

  • Fix transition end detection in cases where a transition has been defined, but no properties are actually transitioned (eef3228)

0.1.1 (2023-03-16)

Bug Fixes

  • Fix missing library bundle

0.1.0 (2023-03-16) [YANKED]

Breaking Changes

  • Package is now ES module only

Bug Fixes

  • Improve transition reliability (ff861b5)

0.1.0-beta.5 (2021-05-18)

Fixed

  • Clean up animation if transition gets cancelled.

0.1.0-beta.4 (2021-03-31)

Added

  • Expose cancel function.

Fixed

  • Don't move elements that were previously hidden.

0.1.0-beta.3 (2021-03-05)

Fixed

  • Fix transition classes not being removed properly in same cases.
  • Recompile typings.
  • Mark package as side-effect free.

0.1.0-beta.2 (2021-03-04)

Changed

  • Rename animate to transition.
  • Rename AnimationOptions.classPrefix to AnimationOptions.prefix.

Fixed

  • Don't apply the move class to elements that aren't changing position.
  • Fix buggy behavior when a new transition is started while a previous one is still running.