4.0.21 • Published 7 months ago

react-components-transition v4.0.21

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

React components transition live example!

Scroll down to updates and issues

Use case

A very small but useful React component, which allows to smart transition between components without adding unnecessary state's hooks to render conditionally

Something like React router but simplified and without rendering based on URL. Just more static

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-transitionn";

  const componentKey = "example2"

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

Or with animations

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

  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, TransitionChild } from "react-components-transition";

  const Component () => {

    return (
      <>
        <ComponentsTransition>

          // Remember to give unique key

          <TransitionChild isStatic={true} key="OutsideComponentWrapper">
            <OutsideComponent key="OutsideComponent"></OutsideComponent>
          </TransitionChild>

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

Or

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

  const Component () => {
    const divRef = useState(null)

    return (
      <>
        <div ref={divRef}></div>
        <ComponentsTransition>

          // Remember to give unique key

          <TransitionChild key="OutsideComponentWrapper" isStatic={true} renderTo={divRef}>
            <OutsideComponent key="OutsideComponent"></OutsideComponent>
          </TransitionChild>

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

Last update 3.1.0

  • Added possibility to choose context on button (f.e if u want to use other transition context in other ComponetsTransition)

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

What's next?

Probably maybe any async/await rendering?

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

4.0.19

7 months ago

4.0.21

7 months ago

4.0.20

7 months ago

4.0.16

7 months ago

4.0.15

8 months ago

4.0.18

7 months ago

4.0.17

7 months ago

4.0.14

8 months ago

4.0.13

9 months ago

4.0.5

1 year ago

4.0.4

1 year ago

4.0.10

1 year ago

4.0.7

1 year ago

4.0.6

1 year ago

4.0.3

1 year ago

4.0.12

11 months ago

4.0.11

1 year ago

4.0.9

1 year ago

4.0.8

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.1.0

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.0.3

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

3.0.9

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

3.0.12

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.10

2 years ago

3.0.2

2 years ago

3.0.11

2 years ago

3.0.1

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

2.4.7

2 years ago

2.4.6

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago