1.0.5 • Published 1 year ago

react-simple-animation-viewer v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-simple-animation-viewer

The very simple animation viewer in React.

demo

Installation

npm install react-simple-animation-viewer

Example

All you have to do is enclose <AnimationViewProvider>, <AnimationViews>, <AnimationView>!

import React from 'react';
import {
  AnimationViewProvider,
  AnimationViews,
  AnimationView,
  useAnimationViewer,
} from 'react-simple-animation-viewer'

const Component = (props) => {
  return (
    <AnimationViewProvider>
      <AnimationViews {...props} value="sample">
        <AnimationView
          isRoot
          value={'top'}
          containerStyle={{
            width: '100vw',
            height: '100vh',
            backgroundColor: 'green',
          }}
        >
          <Top />
        </AnimationView>
        <AnimationView
          value={'second'}
          containerStyle={{
            width: '100vw',
            height: '100vh',
            backgroundColor: 'blue',
          }}
        >
          <Second />
        </AnimationView>
        <AnimationView
          value={'third'}
          containerStyle={{
            width: '100vw',
            height: '100vh',
            backgroundColor: 'red',
          }}
        >
          <Third />
        </AnimationView>
        <AnimationView
          value={'fourth'}
          containerStyle={{
            width: '100vw',
            height: '100vh',
            backgroundColor: 'black',
          }}
        >
          <Fourth />
        </AnimationView>
      </AnimationViews>
    </AnimationViewProvider>
  );
};

const Top = () => {
  const { forwardView } = useAnimationViewer();
  return (
    <Button primary onClick={() => forwardView('second')}>
      second
    </Button>
  );
};
const Second = () => {
  const { forwardView, backwardView } = useAnimationViewer();
  return (
    <>
      <Button primary onClick={() => backwardView()}>
        back
      </Button>
      <Button primary onClick={() => forwardView('third')}>
        third
      </Button>
    </>
  );
};
const Third = () => {
  const { forwardView, backwardView } = useAnimationViewer();
  return (
    <>
      <div style={{ height: '50vh' }} />
      <Button primary onClick={() => backwardView()}>
        back
      </Button>
      <Button primary onClick={() => forwardView('fourth')}>
        fourth
      </Button>
      <div style={{ height: '100vh' }} />
    </>
  );
};
const Fourth = () => {
  const { backwardView } = useAnimationViewer();
  return (
    <Button primary onClick={() => backwardView()}>
      back
    </Button>
  );
};

Props

AnimationViews

* is required.

propstypedescription
*childrenArray<React.ReactElement<AnimationViewProps>> or React.ReactElement<AnimationViewProps>The Animation View component(s)
*valuestringThe unique value to manage the another animation views
inContainerStyleReact.CSSPropertiesThe style to be applied to the inComponent
outContainerStyleReact.CSSPropertiesThe style to be applied to the outComponent
timeoutnumberThe time for animation (ms). Default to 300
onChangeViewValues(_value: string \| null) => voidThe event handler on changing the view

AnimationView

* is required.

propstypedescription
*childrenReact.ReactNodeThe component to be shown
*valuestringThe unique value to manage the view
isRootbooleanWhether to be root (top) view or not. This parameter must be true in only one view.
containerStyleReact.CSSPropertiesThe style of div

useAnimationViewer

Note: You should enclose <AnimationViewProvider> at the top components to use useAnimationViewer

propstypedescription
viewValuestring \| nullThe current view's value
forwardView(_newViewValue: string) => voidThe function to forward (left to right) the view
backwardView() => voidThe function to backward (right to left) the view
closeView() => voidThe function to close the view
1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago