Spotlight
Highlight important content with a lighting effect
npm run add SpotlightUse the Spotlight component to highlight content such as updates, announcements, or releases with a visual effect. They guide users toward key content with a strong center of attention without overwhelming the layout. They can also improve aesthetics as the component adds depth, atmosphere, and a premium feel to interfaces.
<Spotlight className="spotlight"> <PromotionalCard ... className="promotional-card" /></Spotlight>
<style lang="scss"> @use 'webcoreui/config' as *;
.spotlight { min-height: 600px; height: 600px; }
.promotional-card { @include position(absolute, h-center, t20px); }</style>To use the Spotlight component, simply wrap the elements into the component that you want to highlight. The component will always take the full height of its container.
For demonstration purposes, in the example above, it’s explicitly set to 600px. The element inside the component can be positioned in any way you like. In this example, its positioned absolutely, centered on the horizontal axis and 20px from the top.
PromotionalCard component. Spotlight Size
The size of the spotlight can be changed with various props, including the following:
blurAmount: Sets the amount of blurring on the spotlight. Defaults to15px.radialMinWidth: Sets the minimum width of the animated radial gradient at the base of the spotlight. Defaults to40%.radialMaxWidth: Sets the maximum width of the animated radial gradient at the base of the spotlight. Defaults to50%.coneMinWidth: Sets the minimum width of the animated cone. Defaults to60%.coneMaxWidth: Sets the maximum width of the animated cone. Defaults to70%.
The gradients will grow and shrink between the minimum and maximum values.
<Spotlight radialMinWidth="60%" radialMaxWidth="70%" coneMinWidth="80%" coneMaxWidth="90%"> <PromotionalCard ... /></Spotlight>Particles
The flying particles can also be customized through the following three props:
particleAmount: Sets the amount of particles spawned at a set interval. Defaults to2.particleSize: Sets the base radius of each particle. This base is used to further randomize size. Defaults to3.particleDuration: Sets the time it takes for the animation to finish in seconds. Defaults to20.
<Spotlight particleAmount={10} particleSize={1} particleDuration={5}/>Colors
If you need to change colors to match your brand, you can update hte background and rgbColor props. The rgbColor prop expects a comma-separated list of RGB values in the following format:
<Spotlight background="#000" rgbColor="100, 155, 255"/>Configuration with CSS
If you would like to keep global component configuration in one place, you can also set the above props through the following CSS variables:
/* The following are default values: */html body { --w-spotlight-blur: 15px; --w-spotlight-animation-timing: ease-in-out; --w-spotlight-radial-min-width: 40%; --w-spotlight-radial-max-width: 50%; --w-spotlight-cone-min-width: 60%; --w-spotlight-cone-max-width: 70%; --w-spotlight-background: radial-gradient(circle at center, #000 0%, #111 100%); --w-spotlight-color: 255, 255, 255;}API
type SpotlightProps = { blurAmount?: number animationTiming?: string radialMinWidth?: string radialMaxWidth?: string coneMinWidth?: string coneMaxWidth?: string background?: string rgbColor?: string particleAmount?: number particleSize?: number particleDuration?: number className?: string}| Prop | Default | Purpose |
|---|---|---|
blurAmount | 15px | Sets the amount of blur effect on the spotlight. |
animationTiming | ease-in-out | Sets the animation easing of the spotlight. |
radialMinWidth | 40% | Sets the minimum width of the animated radial gradient. |
radialMaxWidth | 50% | Sets the maximum width of the animated radial gradient. |
coneMinWidth | 60% | Sets the minimum width of the animated cone. |
coneMaxWidth | 70% | Sets the maximum width of the animated cone. |
background | radial-gradient(#000, #111) | Sets the background color of the component. |
rgbColor | 255, 255, 255 | Sets the RGB color of the spotlight and particles. |
particleAmount | 2 | Sets the amount of particles spawned at a set interval. |
particleSize | 3 | Sets the base radius of each particle. Particles can randomly have a smaller or larger size based off this value. |
particleDuration | 20 | Sets the time it takes for the particles to finish animation. |
className | - | Pass additional CSS classes for the component. |
