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-dvd-screensaver

v0.1.1

Published

DVD-era nostalgia in React

Downloads

4,283

Readme

React DVD Screensaver

TypeScript

DVD-era nostalgia in React.

Demo

Try the project on Stackblitz

npm i react-dvd-screensaver

Use hook

To add a DVD screensaver effect to your React components, you can use the useDvdScreensaver hook. This hook provides you with references for both the parent (container) and the child (moving element), along with the number of times the child has hit the edges of the container.

import { useDvdScreensaver } from 'react-dvd-screensaver'

...

const { containerRef, elementRef } = useDvdScreensaver();

return (
  <div ref={containerRef}>
    <MyScreensaverComponent ref={elementRef} />
  </div>
)

Pass the ref objects for parent and child to their respective components. Just remember to set the dimensions for both of them, where the childRef component naturally is smaller than the parent so there is room for it to move around.

| Hook returns following:|| | ------------- | ------------- | |parentRef: refObject| Ref of the parent container component| |elementRef: refObject| Ref of the element to animate| |impactCount: number| Number of times the element has hit the container edges|

Hook Options

The hook accepts the following parameters:

| Option | Type | Description | | ------------- | -------|-----| |speed| number | Speed of the animation | |freezeOnHover| boolean | Whether to pause the animation on hover | |hoverCallback| Function | Callback function triggered on hover |

Component

For easier implementation, you can also use the DvdScreensaver component to wrap any child component with the DVD screensaver effect.

import { DvdScreensaver } from 'react-dvd-screensaver'

...

return (
  <div className="screensaver-container">
    <DvdScreensaver>
      <MyScreensaverComponent />
    </DvdScreensaver>
  </div>
)

The component inherits the parent container's dimensions by default, but you can also specify dimensions or styling directly via props.

Props

| Prop | Type | Description | | ------------- | ------| -----| |className| string | Optional CSS class for the container | |freezeOnHover| boolean | Pause animation when hovered | |height| number | Optional height for the container | |width| number | Optional width for the container | |hoverCallback|Function | Callback function triggered on hover | |impactCallback|(count: number) => void|Callback function triggered on impact with edges | |speed|number`| Speed of the animation |

License

MIT