AnimationUpdated in v15

Spotlight Card

A card with a soft highlight that follows the pointer.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrSpotlight, WrSpotlightCard } from 'ngwr/bits/spotlight-card';

@Component({ imports: [WrSpotlight, WrSpotlightCard] })
export class MyComponent {}
Angular adaptation of an effect by David Haz / reactbits.dev.

Playground

Cursor-tracked spotlight

Move the pointer across this card.

<wr-spotlight-card>
  <h3>Cursor-tracked spotlight</h3>
  <p>Move the pointer across this card.</p>
</wr-spotlight-card>

Customize

Spotlight Color
Radius (%)
80 %

Directive variant ([wrSpotlight])

[wrSpotlight] writes the pointer position to --wr-spotlight-x and -y; paint it with your own gradient.

import { WrSpotlight } from 'ngwr/bits/spotlight-card';

<div wrSpotlight class="card">…</div>

// Then in your CSS:
// background: radial-gradient(
//   400px circle at var(--wr-spotlight-x, 50%) var(--wr-spotlight-y, 50%),
//   color-mix(in srgb, var(--wr-color-primary) 15%, transparent),
//   transparent 60%
// );
Hover me — [wrSpotlight] writes CSS vars; the gradient does the rest.

API

NameDescriptionTypeDefault
radiusWhere the spotlight fades out (% of the gradient).number80
spotlightColorHighlight colour. Unset, it follows the theme.string | nullnull
[wrSpotlight]Writes --wr-spotlight-x / -y (in %) on any element. Pair with a gradient in your CSS.directive—
[wrSpotlight].resetX / .resetYDefault coordinates when no pointer is over the host.string'50%'

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/bits/spotlight-card's own element.

VariableDefaultDeclared on
--wr-spotlight-card-bordervar(--wr-border-base).wr-spotlight-card
--wr-spotlight-card-paddingvar(--wr-space-xl).wr-spotlight-card
--wr-spotlight-card-radiusvar(--wr-border-radius-lg).wr-spotlight-card
--wr-spotlight-colorlight-dark(color-mix(in srgb, var(--wr-color-on-surface) 15%, transparent), color-mix(in srgb, var(--wr-color-on-surface) 22%, transparent)).wr-spotlight-card
--wr-spotlight-x50%.wr-spotlight-card
--wr-spotlight-y50%.wr-spotlight-card

See also