Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stianlarsen/react-light-beam

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stianlarsen/react-light-beam

A customizable React component that creates a light beam effect using conic gradients. Supports dark mode and various customization options.

  • 1.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@stianlarsen/react-light-beam

🚀 New Feature Alert!

We've added a new prop: scrollElement. This allows you to specify which element should have the scroll listener attached, giving you greater flexibility in using the LightBeam component!

npm version

A customizable React component that creates a light beam effect using conic gradients. The component is fully responsive and supports both light and dark modes. Ideal for adding dynamic and engaging visual elements to your web applications.

Preview

LightBeam Component

A preview of @stianlarsen/react-light-beam

Installation

npm install @stianlarsen/react-light-beam

or

yarn add @stianlarsen/react-light-beam

Usage

import { LightBeam } from "@stianlarsen/react-light-beam";
import "your-css-file.css"; // Include the necessary styles

const App = () => {
  return (
    <div className="your-container-class">
      <LightBeam
        id="unique-lightbeam"
        className="your-lightbeam-class"
        colorDarkmode="rgba(255, 255, 255, 0.8)"
        colorLightmode="rgba(0, 0, 0, 0.2)"
        fullWidth={0.8}
        maskLightByProgress={true}
        invert={false}
        scrollElement={window} // New prop to specify scroll element
      />
      <YourContentHere />
    </div>
  );
};

export default App;

Props

Prop NameTypeDefault ValueDescription
idstringundefinedOptional string representing a unique ID for the LightBeam container.
classNamestringundefinedOptional string representing custom classes to be added to the LightBeam container.
colorLightmodestringrgba(0,0,0, 0.5)Optional string representing the color of the light beam in light mode.
colorDarkmodestringrgba(255, 255, 255, 0.5)Optional string representing the color of the light beam in dark mode.
fullWidthnumber1.0Optional number between 0 and 1 representing the maximum width the light beam can reach.
maskLightByProgressbooleanfalseIf true, the mask-image's linear gradient will start with the chosen color at 0% and the transparent part starting at 50%. As the user scrolls, it will dynamically change to have the transparent part at 95%, reducing the glow effect. If false, it will default to linear-gradient(to bottom, chosenColor 25%, transparent 95%).
invertbooleanfalseOptional boolean to invert the scroll progress calculation.
scrollElementEventTarget or undefinedwindowOptional prop for which element to attach the scroll listener to. This could be the window, document.body, or any other scrollable element.
onLoadedundefined or () => voidundefinedOptional function to run when the component has mounted

Default Configuration

The component comes with the following default styles:

.react__light__beam {
  height: 500px;
  width: 100vw;
  transition: all 0.5s ease;
  will-change: auto;
}

These default styles ensure that the component is immediately visible when added to your application. However, for more effective use, you might want to customize its position and behavior.

For best results, it's recommended to position the LightBeam component as an absolutely positioned element within a relatively positioned container. This allows the light beam to cast light downwards over your content, creating a more dynamic and engaging visual effect.

Example:

<div className="container">
  <LightBeam className="lightBeam" />
</div>

And in your CSS or SCSS:

.container {
  position: relative;
  z-index: 1;

  .lightBeam {
    position: absolute;
    inset: 0;
    width: 100vw;
    height: 100%; // Important: Ensure the beam covers the entire height
    z-index: -1;
    margin-top: -300px; // Adjust as needed to position the light beam above the content
  }
}

Dark Mode Support

The component automatically adjusts between light and dark modes based on the user's system preferences. You can pass different colors for light and dark modes using the colorLightmode and colorDarkmode props.

Example

<LightBeam
  id="lightbeam-example"
  className="custom-lightbeam"
  colorDarkmode="rgba(255, 255, 255, 0.8)"
  colorLightmode="rgba(0, 0, 0, 0.2)"
  fullWidth={0.5}
  maskLightByProgress={true}
  invert={true}
  scrollElement={document.body} // Example usage of the new scrollElement prop
/>

License

MIT © Stian Larsen

Keywords

FAQs

Package last updated on 24 Oct 2024

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc