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

react-mount-transition

v0.1.4

Published

React hook and component to transition elements in and out on mount.

Downloads

15

Readme

React Mount Transition is a minimal library of React utilities that allow an element to be transitioned in and out on mount without needing to already be rendered in the DOM. It is perfect for overlay components such as tooltips, popovers and modals.

How To Use?

npm i react-mount-transform
yarn add react-mount-transform

The react-mount-transition exposes two utilities:

useMountTransition Hook

<MountTransition /> Component


useMountTransition Hook

To get started, first import the hook into a React file.

import { useMountTransition } from 'react-mount-transition';

Then instantiate the hook within a component with the two required arguments, duration and isShown.

const { showTransitionElement, withTransitionStyles } = useMountTransition({
    duration: 150, // transition duration in milliseconds (ms)
    isShown: itemIsShown, // boolean toggle for when to render the element
});

The useMountTransition hook returns two properties to handle the mounting and transitioning of an element. In practice, these properties all work together to handle when to render and transition an element.

export function Sample(itemIsShown: boolean) {
    const { showTransitionElement, transitionElementAttrs, withTransitionStyles } = useMountTransition({
      duration: 150,
      isShown: itemIsShown,
    });

    return (
      showTransitionElement ? (
        <div className={withTransitionStyles ? styles.slideIn : ''} {...transitionElementAttrs}>
          ...
        </div>
      ) : null;
    )
  }

Arguments

| Prop | Type | Description | | -------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------- | | duration | number | --${string} | The duration of the transition in milliseconds either as a number or CSS custom property like --transition-short. | | isShown | boolean | The primary on/off value to toggle rendering the element |

Return

| Prop | Type | Description | | ---------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | showTransitionElement | boolean | This is the core prop to handle when and when not to render the transitioning element in the DOM. | | transitionElementAttrs | HTMLAttributes<HTMLElement> | An object of properties returned to the transitioning element. Currently, this handles inert values for improved accessibility during element transition. | | withTransitionStyles | boolean | This prop determines when the transition styles are to be applied and removed. |


<MountTransition /> Component

In some situations the useMountTransition hook won't work, for example, if iterating over children, or conditionally rendering an element. In those instances, the <MountTransition> wrapper component can be used.

The <MountTransition> component uses the useMountTransition hook under the hood.

To get started, first import the component into a React file.

import { MountTransition } from 'react-mount-transition';

Use the <MountTransition /> component to wrap the transitioning element, providing the required props: duration, isShown and transitionClassName.

return (
    <MountTransition
        duration="--transition-short"
        showPanel={itemIsShown}
        transitionClassName={styles.slideIn}
    >
        <div className="some-transitioning-element"> ... </div>
    </MountTransition>
);

Arguments

| Prop | Type | Description | | ------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | | duration | number | --${string} | The duration of the transition in milliseconds either as a number or CSS custom property like --transition-short. | | isShown | boolean | The primary on/off value to toggle rendering the element | | transitionClassName | string | The class name to toggle when the element is transitioned. This will be appended to any existing classnames of the element. |