Skip to content

usePageMotions

@hua-labs/hua/motion

bash
npm install @hua-labs/hua
tsx
import { usePageMotions } from "@hua-labs/hua/framework";

tsx
const motions = usePageMotions({
  hero: { type: "hero", entrance: "fadeIn", delay: 0 },
  title: { type: "title", entrance: "slideUp", delay: 200 },
  cta: { type: "button", entrance: "scaleIn", hover: true, delay: 400 },
});

return (
  <div>
    <div ref={motions.hero.ref} style={motions.hero.style}>Hero</div>
    <h1 ref={motions.title.ref} style={motions.title.style}>Title</h1>
    <button ref={motions.cta.ref} style={motions.cta.style}>CTA</button>
  </div>
);

config*Record<string, PageMotionElement>-Element configuration map (first positional argument)
config[id].type*"hero" | "title" | "button" | "card" | "text" | "image"-Element type for preset styles
config[id].entrance"fadeIn" | "slideUp" | "slideLeft" | "slideRight" | "scaleIn" | "bounceIn"-Entrance animation type
config[id].hoverboolean-Enable hover effects
config[id].clickboolean-Enable click effects
config[id].delaynumber0Animation delay in milliseconds
config[id].durationnumber700Animation duration in milliseconds

[elementId]MotionRefMotion ref for each configured element (ref, style, isVisible, isHovered, isClicked)
reset() => voidReset all motions to initial state