4.0.2 • Published 2 months ago

react-components-transition v4.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

React Components Transition live example!

Scroll down to updates and issues

Use case

A React component, which allows to on demand conditionally render components and give them animations on mounting and unmounting

Instaling

  npm i react-components-transition

Usage

Initializing

  import { ComponentsTransition } from "react-components-transition";

  const Component () => {

    const firstVisibleChildKey = "example2"

    return (
      <ComponentsTransition firstVisible={firstVisibleChildKey}>

        {/* At Least 2 components and first given is visible on first render if not specified in 'firstVisible' prop */}

        <Exmaple1 key="example1"></Example>
        <Exmaple2 key="example2"></Example>
      </ComponentsTransition>
    );
  }

Switching component

  import { TransitionButton } from "react-components-transition";

  const componentKey = "example2"

  const Example1 = () => {
    return <TransitionButton show={componentKey}>Show example 2 component</TransitionButton>
  }

Or with animations

  import { TransitionButton } from "react-components-transition";

  const componentKey = "example2"

  const Example1 = () => {
    return (
      <TransitionButton show={componentKey}
      animationIn={{ className: "animationIn", duration: 500 }}     // Animation in to new rendered child
      animationOut={{ className: "animationOut", duration: 500 }}>  // Animation out to already rendered child
        Show example 2 component
      </TransitionButton>
    );
  };

In css

/* CSS file of Exmaple1 component */

/* Remember to give unique animation name */

@keyframes animationOut {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(0);
  }
}

.animationOut {
  transform: scale(1);
  animation: animationOut 500ms forwards;
}
/* CSS file of Exmaple2 component */

/* Remember to give unique animation name */

@keyframes animationIn {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}

.animationIn {
  transform: scale(0);
  animation: animationIn 500ms forwards;
}

Manipulate from outside

  import { ComponentsTransition, TransitionButton} from "react-components-transition";


  const Component () => {
    const [context, setContext] =  useState(null);

    return (
        <>
          <ComponentsTransition getContext={setContext}>  // Pass a function that will get the context
            <Exmaple1 key="example1"></Example>
            <Exmaple2 key="example2"></Example>
          </ComponentsTransition>
          <TransitionButton
            context={context}  // Add the cotext
            show={"example2"}
            animationIn={{ className: "animationIn", duration: 500 }}
            animationOut={{ className: "animationOut", duration: 500 }}>
            Show example 2 component
          </TransitionButton>
        </>
    );
  }

Last update 4.0.0 - > 4.0.2

  • Changed main behavior

    • Parent ref is no longer required
    • has been removed. There is no need to use to render static components due to ability to get the context and use them anywhere

    • Bug fixes

      • The first onClick in run before transitions so changing key in time on the first fire did nothing
      • Fixed bug with using hooks in child component

Update 3.0.0 - > 3.0.8

  • Changed main behavior

    • Parent ref must be specified in
    • has been change to and renderToRef prop must be specified
  • Bug fixes

    • Children could not update content when any property has been changed
    • No limitations while children are animated (it was not possible to render more then 2 children)

Update 2.4.1 -> 2.4.7

  • Added possibility to choose render first child

Update 2.4.0

  • Fixed issues with styling (every given child in was wrapped into single div element what leads to styles problems)

Update 2.3.0

  • Changed animation. It is possbile now to give an "animationIn" and "animationOut"

Update 2.1.0 -> 2.2.1

  • Now is possible to manipulate children from outside element which is always visible
  • And move out from ComponentsTransition

Update 2.0.2 -> 2.0.3

  • Fixed bugs with rendering components when already is showing one (prohibiting rendering more then 2 components in time)

Update 2.0.1

  • Changed render method:
    • New showed child always display before (on html page) current hiding child. (There was bug with correct positioning elements)
    • Current showing child always is visible on the top of others (has the highest z-index)

Update 2.0.0

  • Added smooth transitions between rerenders based on CSS class

Update Issues

  • Conditional rendering may cause errors. Remember to always return an element (React.Fragment also provides an error)

What's next?

Maybe any async/await rendering?

Any suggestions? Write to: s.stepniak01@gmail.com

4.0.1

2 months ago

4.0.0

2 months ago

4.0.2

2 months ago

3.1.0

8 months ago

2.3.0

12 months ago

2.2.1

12 months ago

2.0.3

12 months ago

2.2.0

12 months ago

2.1.1

12 months ago

2.0.2

12 months ago

2.4.1

12 months ago

2.4.0

12 months ago

2.4.3

12 months ago

2.4.2

12 months ago

2.4.5

11 months ago

2.4.4

12 months ago

3.0.9

9 months ago

2.1.0

12 months ago

2.0.1

12 months ago

3.0.12

9 months ago

3.0.4

9 months ago

3.0.3

9 months ago

3.0.10

9 months ago

3.0.2

9 months ago

3.0.11

9 months ago

3.0.1

9 months ago

3.0.8

9 months ago

3.0.7

9 months ago

3.0.6

9 months ago

3.0.5

9 months ago

2.4.7

11 months ago

2.4.6

11 months ago

3.0.0

9 months ago

2.0.0

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago