Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

2.6 KB
Raw Blame
"use client";

import { Easing, interpolate } from "remotion";
import {
  drawnPathProps,
  type IconAnimationProps,
  useIconAnimation,
} from "@/lib/remocn-icons";

const DOOR_PATH = "M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8";
const HOUSE_PATH =
  "M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z";

const TIMINGS = {
  drawDurationInFrames: 14,
  actionDelayInFrames: 2,
  actionDurationInFrames: 22,
  loop: false,
} as const;

export function HomeIcon({
  animation = "both",
  loop,
  speed,
  size = 48,
  color = "currentColor",
  strokeWidth = 2,
  className,
}: IconAnimationProps) {
  const { drawProgress, scaleIn, actionProgress, actionFrame } =
    useIconAnimation({ animation, loop, speed }, TIMINGS);

  const acting = animation !== "draw" && actionFrame >= 0;

  const doorDraw = interpolate(actionProgress, [0.1, 0.5], [0, 1], {
    extrapolateLeft: "clamp",
    extrapolateRight: "clamp",
    easing: Easing.out(Easing.quad),
  });
  const pop = acting
    ? interpolate(actionProgress, [0.5, 0.7, 1], [1, 1.05, 1], {
        extrapolateLeft: "clamp",
        extrapolateRight: "clamp",
        easing: Easing.inOut(Easing.quad),
      })
    : 1;

  const doorProgress = animation === "draw" ? 1 : acting ? doorDraw : 0;

  const house = drawnPathProps(HOUSE_PATH, drawProgress);
  const door = drawnPathProps(DOOR_PATH, doorProgress);

  const scale = (0.85 + 0.15 * scaleIn) * pop;

  return (
    <svg
      className={className}
      width={size}
      height={size}
      viewBox="0 0 24 24"
      fill="none"
      stroke={color}
      strokeWidth={strokeWidth}
      strokeLinecap="round"
      strokeLinejoin="round"
      style={{
        overflow: "visible",
        transformOrigin: "center",
        transform: `scale(${scale})`,
      }}
    >
      <path
        d={HOUSE_PATH}
        strokeDasharray={house.strokeDasharray}
        strokeDashoffset={house.strokeDashoffset}
      />
      <path
        d={DOOR_PATH}
        strokeDasharray={door.strokeDasharray}
        strokeDashoffset={door.strokeDashoffset}
      />
    </svg>
  );
}

export function HomeIconStatic({
  size = 48,
  color = "currentColor",
  strokeWidth = 2,
  className,
}: {
  size?: number;
  color?: string;
  strokeWidth?: number;
  className?: string;
}) {
  return (
    <svg
      className={className}
      width={size}
      height={size}
      viewBox="0 0 24 24"
      fill="none"
      stroke={color}
      strokeWidth={strokeWidth}
      strokeLinecap="round"
      strokeLinejoin="round"
    >
      <path d={DOOR_PATH} />
      <path d={HOUSE_PATH} />
    </svg>
  );
}