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

v0.4.3

Published

A Performant Customizable Tilt Component for React

Downloads

658

Readme

install size npm bundle size npm downloads Known Vulnerabilities

Table of Contents

Features

  • Easy to use
  • Zero dependencies
  • Highly customizable
  • Touch and Gyroscope support
  • Two customizable glare effects (spot/line)
  • Parallax ready
  • "Scale on Hover/Touch" support
  • "Shadow on Hover/Touch" support
  • "Disable Scroll on Touch" support
  • "Full-Page Listening" support
  • "Control Element" support
  • No jittery movement around the edges
  • Built with performance in mind (requestAnimationFrame(), will-change, and other optimizations)
  • 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

Installation

$ npm install react-next-tilt

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

import { Tilt } from 'react-next-tilt';

Usage

Basic Usage

Place the element/component you want the tilt effect to be applied to inside of <Tilt></Tilt>.

<Tilt>
  <img src="path/to/image.jpg" />
</Tilt>

You can place any element/component inside of <Tilt></Tilt> (doesn't have to be an image)

Parallax Effect

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 place it inside of <Tilt></Tilt>

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

⚠️ Setting lineGlareMixBlendMode and/or spotGlareMixBlendMode properties to anything other than "normal" will break the parallax effect.

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.

While you can tilt the component to a given angle by adjusting the initial angles, it will cause the component to re-render. It is advised to use the tilt() function exposed by the component's ref instead.

Events/Callbacks

Ref

The component's ref object contains these properties:

Ref functions don't re-render the component.

Ref Usage (ref function)

import { Tilt } from 'react-next-tilt';

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

Ref Usage (useEffect)

import { useRef, useEffect } from 'react';
import { Tilt, TiltRef } from 'react-next-tilt';

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

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

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

Tilt on Mount

import { useRef, useEffect } from 'react';
import { Tilt, TiltRef } from 'react-next-tilt';

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

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

  return (
    <Tilt
      ref={(r) => {
        if (r) {
          console.log(`angle = ${JSON.stringify(r.angle())}`);
          r.tilt({ angleX: 10, angleY: 10 });
          console.log(`angle = ${JSON.stringify(r.angle())}`);
          ref.current = r;
        }
      }}
      ...
    >
      ...
    </Tilt>
  );
};

Author

Rashid Shamloo (github.com/rashidshamloo)

License

MIT