New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

use-posed-wave

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-posed-wave

React hook to animate a wave-like effect with SVG.

latest
npmnpm
Version
2.0.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

usePosedWave

A React hook that returns a "react-pose" svg path component animated like a wave.


Waves


What ?

Given a size and amplitude parameters, the hook returns an enhanced component and a "pose" string to pass it. By default, every 3s the wave goes down, morph a little, then up - indefinitely.

Example

function App() {
  // Configure the wave animation and get the component to render.
  // Hint: You could pass the screen width as `x` and any height as `y`
  // to make a full screen width animation.
  const [Wave, wavePose]  = usePosedWave({ size: { x: 200, y: 50 , amplitude: 25 });
  const [Foam, foamPose]  = usePosedWave({ size: { x: 200, y: 50 , amplitude: 35, originOffset: 15 });

  // The component being a SVG path tag, it must be wrapped inside a <svg/>
  // component.
  return (
    <svg width={size.x} height={size.y * 2} style={{ background: "sandybrown" }} >
      {Foam && <Foam pose={foamPose} fill="white" />
      {Wave && <Wave pose={wavePose} fill="teal" />}
    </svg>
  )
}

⚠️ Note: The component will re-render if the "size" parameter changes. Either define it outside the component or with React.useState.

Install

Has react, react-pose and popmotion as --peer dependencies.

yarn add use-posed-wave
yarn add --peer react react-pose popmotion

or

npm i use-posed-wave
npm i --peer react react-pose popmotion

API

const { usePosedWave } = require('use-posed-wave')

  • A react hook that retuns the SVG path component.
  • Takes the following arguments:
    • Required:

      • size: { x: number, y: number } The bounding rect of the animation.
      • amplitude: number The animation's y distance it grows (in pixel).
    • Optional:

      • optionalDuration: number || 3000 The duration for the wave to transit from one state to the other.
      • optionalOffset: number || 0 The y offset to add to the generated path.
      • optionalFade: boolean || false Should the wave fade in and out during the transition?

Todo

  • Make the initial delay optional
  • Return the path component only (without the pose string)
  • Make the wave orientation dynamic (vertical, horizontal)

Acknowledgement

Without those libraries, this hook would not exists.

  • popmotion
  • react-pose
  • flubber

Created by

License

MIT

FAQs

Package last updated on 11 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts