Skip to content
Components58 / 118

Moonlight Header

A header cluster (notifications, a night-mode switch and a profile menu) that falls into moonlight together. Click it, or drag and throw the knob: it is a spring-driven body that glides into the moon's socket, which eclipses it into a thin glowing rim around a solid little moon, and at night the rim waxes and wanes as your cursor moves over it. Night spreads out of the moon across the page; the bell, name, separators and menu all turn over with it, and a Three.js beam of moonlight pours out of the moon down the page with dust drifting through it, leaning after your cursor while the dust parts around it. The bell rings on hover and the profile menu opens with a smooth staggered reveal.

Night modeSpring physicsDraggableThree.js moonbeamProfile menuGSAP
Click or drag the moonMove over it at night: the moon waxes and wanes

Tweak

LIVE

Header

Photo avatar (off: initials)

Unread notifications

Light

#9aa6ff

Beam and dust across the page

Page (demo only)

#f0f0fc
#22253b

Size

44px

Props

13 props
  • value"light" | "dark"
    Controlled theme.
  • defaultValue"light" | "dark"
    Initial theme when uncontrolled.default "light"
  • onValueChange(theme, origin) => void
    Called the moment it is switched, with the moon's screen position (spread the new theme from it).
  • applyToDocumentboolean
    Set data-theme and color-scheme on <html>; where supported, the new theme spreads out of the moon (View Transitions).default false
  • namestring
    The signed-in person's name.default "Alex Morgan"
  • avatarSrcstring
    Avatar image; initials are drawn when it's missing.
  • unreadnumber
    Unread notifications; a dot springs onto the bell above 0.default 0
  • onNotificationsClick() => void
    Bell click handler.
  • menu{ label; href?; onSelect? }[]
    Profile menu entries.default Profile, Settings, Sign out
  • moonlightstring
    Colour of the moon's rim, the beam and the dust.default "#9aa6ff"
  • beamboolean
    Cast the beam of moonlight across the page at night (it overflows, so don't clip its parents).default true
  • sizenumber
    Scale: the switch height in px; everything sizes from it.default 44
  • classNamestring
    Extra classes.