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-flip-tilt

v0.2.0

Published

A Performant Customizable React Component Providing the Flip-Tilt Effect

Downloads

208

Readme

install size npm bundle size npm downloads Known Vulnerabilities

Table of Contents

Features

  • Easy to use
  • Highly customizable
  • Built with performance in mind
  • Built from the ground up using React Hooks/TypeScript (is not a port of another library)
  • Minimum amount of component re-renders
  • Typed props with JSDoc descriptions
  • Tested extensively using Cypress/Storybook
  • Plus all of the features of react-next-tilt like:
    • Touch and Gyroscope support
    • Two customizable glare effects (spot/line)
    • Scale on Hover/Touch
    • Shadow on Hover/Touch
    • Disable Scroll on Touch
    • Full-Page Listening
    • Control Element
    • Parallax ready
    • and more
  • Plus all of the features of react-next-parallax like:
    • Parallax effect
    • Animations based on tilt angle
    • Multiple animation modes
    • and more

Installation

$ npm install framer-motion react-flip-tilt

Once the package is installed, you can import the component:

import { FlipTilt } from 'react-flip-tilt';

Usage

You can set the front/back properties to either an image source as string or an element/component

Image Source

<FlipTilt front="/front.webp" back="/back.webp" />

Element/Component

<FlipTilt front={<div>...</div>} back={<MyComponent />} />

Mixture of Both

<FlipTilt front="/front.webp" back={<MyComponent />} />

Parallax Effect

Using react-next-tilt (default)

  • This component is "parallax ready", meaning you don't need to change any settings for it to work.

  • You just need to set up your parallax effect in JSX/CSS and set it as the front/back element.

  • You can read this article to learn more about how to set up the 3D parallax effect.

Using react-next-parallax (type='parallax')

  • Follow the usage guide on react-next-parallax's readme.

  • Instead of placing your scene inside <Parallax></Parallax>, set it as the front/back element.

Props

All props are optional

In addition to these props, you can use:

  • Any valid HTMLDivElement props like className='', data-...='...', onMouseMove={...} etc. they will be applied to the container element.
  • Any of the react-next-tilt props like scale, disableScrollOnTouch, controlElement, etc.
  • Any of the react-next-parallax props like animationMode, animationReverse, offsetMultiplier, etc. (when type is set to 'parallax')

While you can flip the component by changing the flipped prop, it will cause the component to re-render and interrupts the animation. It is advised to use the flip() function exposed by the component's ref instead.

Events/Callbacks

The component has the following events/callbacks in addition to react-next-tilt events/callbacks:

Ref

The component's ref object contains the following properties in addition to react-next-tilt ref properties:

Ref Usage (ref function)

import { FlipTilt } from 'react-flip-tilt';

const MyComponent = () => {
  return (
    <FlipTilt
      ref={(ref) => {
        if (ref) {
          //do something with the ref
        }
      }}
      ...
    />
  );
};

Ref Usage (useEffect)

import { useRef, useEffect } from 'react';
import { FlipTilt, FlipTiltRef } from 'react-flip-tilt';

const MyComponent = () => {
  const ref = useRef<FlipTiltRef>(null);

  useEffect(() => {
    if (ref.current) {
      //do something with the ref
    }
  }, []);

  return <FlipTilt ref={ref} ... />;
};

Flip on Mount

import { useRef, useEffect } from 'react';
import { FlipTilt, FlipTiltRef } from 'react-flip-tilt';

const MyComponent = () => {
  const ref = useRef<FlipTiltRef | null>(null);

  useEffect(()=>{
    if (ref.current) {
    //do something else with the ref
    }
  },[]);

  return (
    <FlipTilt
      ref={async (r) => {
        if (r) {
          console.log(`isFlipped = ${r.isFlipped()}`);
          await r.flip();
          console.log(`isFlipped = ${r.isFlipped()}`);
          ref.current = r;
        }
      }}
      ...
    />
  );
};

Credits

Animated using framer-motion

Inspired by evolany.com

Author

Rashid Shamloo (github.com/rashidshamloo)

License

MIT