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-transition-components

v4.2.0

Published

Easily configurable React components for animations / transitions ๐Ÿ’ƒ

Downloads

743

Readme

React Transition Components

An animation component library & higher-order component for generating easily configurable <Transition> components from react-transition-group.

react-transition-components is 3 kB gzipped, has peer dependencies on react and react-transition-group, and supports webpack tree-shaking by default: https://bundlephobia.com/result?p=react-transition-components

yarn install react-transition-components

Motivation

react-transition-components has 2 goals:

  • Provide a component library of common lightweight UI transitions that are configurable on durations, delays, easings, and other animation values.
  • Make it easy to create configurable transition components by providing a createTransition higher-order component.

The aforementioned createTransition higher-order component wraps <Transition> from react-transition-group, maintains backwards compatibility with its props, and enhances it with configurable timings, delays, and easings. It provides a concise API, allowing you to express an enter/exit CSS transition in 6 lines of code in the simplest case:

import { createTransition } from 'react-transition-components';

const CustomTransition = createTransition({
  from: { transform: 'scale(0) skew(45deg)', opacity: 0 },
  enter: { transform: 'scale(1) skew(0deg)', opacity: 1 }
});

Component Library

react-transition-components comes with multiple components that work out of the box. A Storybook is live at: https://setsun.io/react-transition-components

The following components are included, and implement the most common CSS transitions:

  • FadeTransition for opacity animations
  • HeightTransition for height animations
  • TranslateTransition for translate3d animations
  • ScaleTransition for scale3d animations
  • RotateTransition for rotate3d animations
  • SkewTransition for skew animations
  • ClipTransition for clip-path animations

Higher-order component API

createTransition(config: TransitionConfig)

The createTransition higher-order component returns a pre-configured <Transition> component that allows you to create transition components that can be used immediately, and can be configured via props as your animation needs change.

All components created via createTransition support all props from the <Transition> component from react-transition-group (https://reactcommunity.org/react-transition-group/transition).

These generated components also have extended functionality and have the following base props for customizing transition properties and timings:

type Props = {
  // a custom duration for your transition, with the ability
  // to also have separate enter / exit durations
  duration?: number | {
    enter: number;
    exit: number;
  };

  // a custom delay for your transition, with the ability
  // to also have separate enter / exit delays
  delay?: number | {
    enter: number;
    exit: number;
  };

  // a CSS transition easing curve
  easing?: string;

  // React children can either be a ReactNode, or a function that takes
  // a style and status, and returns a ReactNode
  children: React.ReactNode | ((style: React.CSSProperties, status: TransitionStatus) => React.ReactNode);
}

createTransition has the following type signature:

type TransitionConfig = {
  from: React.CSSProperties | LazyCSSProperties;
  enter: React.CSSProperties | LazyCSSProperties;
  exit?: React.CSSProperties | LazyCSSProperties;
  transitionProperty?: string;
}

type createTransition = (config: TransitionConfig) => React.SFC<TransitionProps>

from: React.CSSProperties | LazyCSSProperties

The from property is the starting style of your transition component. This is the first state that your component animation will animate from. If the exit property is not specified, the from property is also used for the exit animation.

enter: React.CSSProperties | LazyCSSProperties

The enter property is the entering style of your transition component. This is the state where your component animation will animate to, and its final resting state.

exit?: React.CSSProperties | LazyCSSProperties

The exit property is the exiting style of your transition component. This is an optional property for explicitly specifying a state to animate to when exiting, especially if you want an exit animation that is asymmetric from your enter animation.

Example Recipes

Symmetric Enter/Exit Transition

const FadeTransition = createTransition({
  from: { opacity: 0 },
  enter: { opacity: 1 }
});

Asymmetric Enter/Exit Transition

const ScaleEnterClipExitTransition = createTransition({
  from: {
    transform: 'scale(0.5)',
    opacity: 0,
    clipPath: 'circle(100% at 50% 50%)'
  },
  enter: {
    transform: 'scale(1)',
    opacity: 1,
    clipPath: 'circle(100% at 50% 50%)'
  },
  exit: {
    transform: 'scale(1)',
    opacity: 0,
    clipPath: 'circle(0% at 50% 50%)'
  },
});

Configurable Transition

const ClipScaleFadeTransition = createTransition({
  from: (props) => {
    return {
      opacity: props.fade ? 0 : 1,
      transform: `scale(${props.scale.start})`,
      clipPath: 'circle(100% at 50% 50%)'
    }
  },
  enter: (props) => {
    return {
      opacity: 1,
      transform: `scale(${props.scale.end})`
      clipPath: 'circle(100% at 50% 50%)'
    }
  },
  exit: (props) => {
    return {
      opacity: props.fade ? 0 : 1,
      transform: `scale(${props.scale.start})`,
      clipPath: 'circle(0% at 50% 50%)'
    }
  },
});

ClipScaleFadeTransition.defaultProps = {
  fade: true,
  scale: {
    start: 0.5,
    end: 1,
  }
}