Socket
Socket
Sign inDemoInstall

react-dvd-screensaver

Package Overview
Dependencies
5
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-dvd-screensaver

DVD-era nostalgia in React


Version published
Maintainers
1
Install size
11.7 kB
Created

Readme

Source

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: refObjectRef of the parent container component
elementRef: refObjectRef of the element to animate
impactCount: numberNumber of times the element has hit the container edges

Hook Options

The hook accepts the following parameters:

OptionTypeDescription
speednumberSpeed of the animation
freezeOnHoverbooleanWhether to pause the animation on hover
hoverCallbackFunctionCallback 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

PropTypeDescription
classNamestringOptional CSS class for the container
freezeOnHoverbooleanPause animation when hovered
heightnumberOptional height for the container
widthnumberOptional width for the container
`hoverCallbackFunctionCallback function triggered on hover
impactCallback(count: number) => voidCallback function triggered on impact with edges
speednumberSpeed of the animation

License

MIT

Keywords

FAQs

Last updated on 16 Mar 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc