Home/Components/Loaders/IV Drip Loader - React Healthcare Loading Animation
Code · Live Preview
Componenttsx
"use client";

// src/components/DripLoader/DripLoader.tsx
import { motion, useReducedMotion } from "motion/react";
import { useId } from "react";

type DripLoaderProps = {
  className?: string;
  /** Width in px - height is always 1.5x the width */
  size?: number;
  /** Fluid color - use your clinic or brand color */
  color?: string;
  /** Drops per minute - higher = faster dripping */
  dripRate?: number;
  /**
   * Optional 0-100. When set, the bag drains as progress goes up
   * (0 = full bag, 100 = empty bag) and the label shows the percentage.
   */
  progress?: number;
  /** Gentle swing of the bag on its hook */
  sway?: boolean;
  /** Text under the loader. Pass an empty string to hide it */
  label?: string;
};

// viewBox is 120 x 180
const BAG =
  "M 36 14 H 84 Q 92 14 92 22 V 72 Q 92 84 81 90 L 67 97 H 53 L 39 90 Q 28 84 28 72 V 22 Q 28 14 36 14 Z";
const CHAMBER = "M 54 106 H 66 Q 70 106 70 110 V 136 Q 70 141 65 141 H 55 Q 50 141 50 136 V 110 Q 50 106 54 106 Z";
const TUBE = "M 60 141 V 160 Q 60 171 71 171 H 98";

// Liquid surface positions inside the bag (y)
const LEVEL_FULL = 24;
const LEVEL_EMPTY = 97;
// Level used in loop mode, and in reduced motion
const LEVEL_LOOP = 46;

const WAVE_AMP = 1.6;
const WAVELENGTH = 30;

// Drop: tip of the drip chamber, and the pool surface below it
const DROP_TIP = 112;
const POOL_TOP = 132;

function wavePath(wavelength: number, amp: number) {
  const start = -wavelength * 2;
  const end = 120 + wavelength * 2;
  let d = `M ${start} 0`;
  for (let x = start; x < end; x += wavelength) {
    d +=
      ` Q ${x + wavelength / 4} ${-amp} ${x + wavelength / 2} 0` +
      ` Q ${x + (wavelength * 3) / 4} ${amp} ${x + wavelength} 0`;
  }
  return `${d} L ${end} 120 L ${start} 120 Z`;
}

const WAVE = wavePath(WAVELENGTH, WAVE_AMP);

export function DripLoader({
  className = "",
  size = 100,
  color = "#0EA5E9",
  dripRate = 40,
  progress,
  sway = true,
  label = "Loading",
}: DripLoaderProps) {
  const uid = useId().replace(/:/g, "");
  const reduce = useReducedMotion();
  const isProgress = typeof progress === "number";

  const clamped = isProgress ? Math.min(100, Math.max(0, progress)) : 0;
  const level = isProgress
    ? LEVEL_FULL + (clamped / 100) * (LEVEL_EMPTY - LEVEL_FULL)
    : LEVEL_LOOP;
  const bagEmpty = isProgress && clamped >= 100;

  // One drop cycle in seconds (40 drops/min = 1.5s)
  const dropTime = 60 / Math.min(120, Math.max(10, dripRate));
  const dripping = !reduce && !bagEmpty;

  const a11y = isProgress
    ? {
        role: "progressbar",
        "aria-valuemin": 0,
        "aria-valuemax": 100,
        "aria-valuenow": Math.round(clamped),
        "aria-label": label || "Loading",
      }
    : { role: "status", "aria-label": label || "Loading" };

  return (
    <div className={`flex flex-col items-center gap-3 ${className}`} {...a11y}>
      <div className="relative" style={{ width: size, aspectRatio: "2 / 3", maxWidth: "100%" }}>
        <svg viewBox="0 0 120 180" className="h-full w-full overflow-visible" fill="none" aria-hidden="true">
          <defs>
            <clipPath id={`bag-${uid}`}>
              <path d={BAG} />
            </clipPath>
            <clipPath id={`chamber-${uid}`}>
              <path d={CHAMBER} />
            </clipPath>
            <linearGradient id={`depth-${uid}`} x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stopColor="#000" stopOpacity={0} />
              <stop offset="100%" stopColor="#000" stopOpacity={0.22} />
            </linearGradient>
          </defs>

          {/* Tube, drawn first so the bag swings over it */}
          <path d={TUBE} stroke="currentColor" strokeOpacity={0.25} strokeWidth={5} strokeLinecap="round" />
          <path d={TUBE} stroke={color} strokeOpacity={0.35} strokeWidth={2.4} strokeLinecap="round" />
          {/* Fluid moving through the tube */}
          {dripping && (
            <motion.path
              d={TUBE}
              stroke={color}
              strokeWidth={2.4}
              strokeLinecap="round"
              strokeDasharray="2 6"
              initial={{ strokeDashoffset: 0 }}
              animate={{ strokeDashoffset: -16 }}
              transition={{ duration: dropTime, ease: "linear", repeat: Infinity }}
            />
          )}
          {/* Roller clamp */}
          <rect x={54} y={148} width={12} height={8} rx={2.5} fill="currentColor" fillOpacity={0.12} stroke="currentColor" strokeOpacity={0.4} strokeWidth={1.5} />

          {/* Everything that hangs from the hook */}
          <motion.g
            style={{ originX: 0.5, originY: 0 }}
            animate={sway && !reduce ? { rotate: [-1.5, 1.5, -1.5] } : { rotate: 0 }}
            transition={sway && !reduce ? { duration: 4, ease: "easeInOut", repeat: Infinity } : { duration: 0 }}
          >
            {/* Hook */}
            <circle cx={60} cy={7} r={4} stroke="currentColor" strokeOpacity={0.4} strokeWidth={2} />
            <path d="M 60 11 V 14" stroke="currentColor" strokeOpacity={0.4} strokeWidth={2} />

            {/* Bag body */}
            <path d={BAG} fill="currentColor" fillOpacity={0.04} />

            {/* Fluid in the bag */}
            <g clipPath={`url(#bag-${uid})`}>
              <motion.g
                initial={{ y: level }}
                animate={{ y: level }}
                transition={reduce ? { duration: 0 } : { type: "spring", stiffness: 50, damping: 16 }}
              >
                <motion.path
                  d={WAVE}
                  fill={color}
                  fillOpacity={0.85}
                  stroke="#fff"
                  strokeOpacity={0.4}
                  strokeWidth={1}
                  initial={{ x: 0 }}
                  animate={reduce ? { x: 0 } : { x: [0, -WAVELENGTH] }}
                  transition={reduce ? { duration: 0 } : { duration: 2.2, ease: "linear", repeat: Infinity }}
                />
              </motion.g>
              <rect x={20} y={14} width={80} height={86} fill={`url(#depth-${uid})`} />
            </g>

            {/* Printed label with a medical cross */}
            <rect x={36} y={30} width={26} height={24} rx={3} fill="#fff" fillOpacity={0.9} />
            <path d="M 49 35 V 45 M 44 40 H 54" stroke={color} strokeWidth={3} strokeLinecap="round" />
            <path d="M 41 50 H 57" stroke="#94A3B8" strokeWidth={1.5} strokeLinecap="round" />

            {/* Measurement marks */}
            {[28, 40, 52, 64, 76].map((y, i) => (
              <path
                key={y}
                d={`M ${i % 2 ? 82 : 78} ${y} H 87`}
                stroke="currentColor"
                strokeOpacity={0.35}
                strokeWidth={1.5}
                strokeLinecap="round"
              />
            ))}

            {/* Bag outline and shine */}
            <path d={BAG} stroke="currentColor" strokeOpacity={0.45} strokeWidth={2.5} strokeLinejoin="round" />
            <path d="M 33 26 V 66" stroke="#fff" strokeOpacity={0.35} strokeWidth={3} strokeLinecap="round" />

            {/* Port between bag and chamber */}
            <rect x={56} y={97} width={8} height={9} rx={1.5} fill="currentColor" fillOpacity={0.25} />

            {/* Drip chamber */}
            <path d={CHAMBER} fill="currentColor" fillOpacity={0.04} />
            <g clipPath={`url(#chamber-${uid})`}>
              {/* Small pool at the bottom */}
              <rect x={48} y={POOL_TOP} width={24} height={12} fill={color} fillOpacity={0.85} />

              {/* Ripple when a drop lands */}
              {dripping && (
                <motion.ellipse
                  cx={60}
                  cy={POOL_TOP}
                  ry={1.2}
                  fill="none"
                  stroke="#fff"
                  strokeWidth={1}
                  initial={{ rx: 0, opacity: 0 }}
                  animate={{ rx: [0, 0, 8], opacity: [0, 0.9, 0] }}
                  transition={{ duration: dropTime, times: [0, 0.74, 1], ease: "easeOut", repeat: Infinity }}
                />
              )}

              {/* The drop: grows at the tip, stretches, falls */}
              {dripping ? (
                <motion.ellipse
                  cx={60}
                  fill={color}
                  initial={{ cy: DROP_TIP, rx: 0, ry: 0 }}
                  animate={{
                    cy: [DROP_TIP, DROP_TIP + 1, DROP_TIP + 1.5, POOL_TOP, POOL_TOP],
                    rx: [0, 2.4, 2.2, 2, 0],
                    ry: [0, 2.6, 3.4, 2.2, 0],
                  }}
                  transition={{
                    duration: dropTime,
                    times: [0, 0.5, 0.58, 0.74, 0.76],
                    ease: ["easeOut", "easeIn", "easeIn", "linear"],
                    repeat: Infinity,
                  }}
                />
              ) : (
                !bagEmpty && <ellipse cx={60} cy={DROP_TIP + 1} rx={2.2} ry={2.6} fill={color} />
              )}
            </g>
            <path d={CHAMBER} stroke="currentColor" strokeOpacity={0.45} strokeWidth={2} />
            {/* Drip tip */}
            <path d="M 60 106 V 110" stroke="currentColor" strokeOpacity={0.45} strokeWidth={2} strokeLinecap="round" />
          </motion.g>
        </svg>
      </div>

      {label && (
        <motion.span
          aria-hidden="true"
          className="text-sm font-medium text-neutral-500 tabular-nums dark:text-neutral-400"
          animate={reduce || isProgress ? {} : { opacity: [0.45, 1, 0.45] }}
          transition={{ duration: 1.6, repeat: Infinity, ease: "easeInOut" }}
        >
          {isProgress ? `${label} ${Math.round(clamped)}%` : label}
        </motion.span>
      )}
    </div>
  );
}

export default DripLoader;
// Component Source: https://codekk.dev
DesktopSandpackTailwind v4

Component details

Overview, install command, dependencies, and project links.

An IV drip loader for React built with TypeScript, Motion, SVG, and Tailwind CSS v4, designed for doctors, clinics, hospitals, diagnostic labs, pharmacies, and health apps. An IV bag hangs from its hook and swings gently from side to side. Inside the bag, the fluid surface moves with a soft wave. Below it, a drop slowly forms at the tip of the drip chamber, stretches as it gets heavy, falls, and lands in the small pool with a ripple. The fluid then flows down the tube past the roller clamp, shown by small dashes moving along the line. The bag has a printed label with a medical cross, measurement marks, and a glass shine, so it reads as an IV bag at any size. The color prop sets the fluid, drop, and cross to any brand color, and the dripRate prop sets how many drops fall per minute, so 30 feels calm and 80 feels busy. The sway prop turns the swing on or off. The optional progress prop turns the loader into a real progress indicator: the bag drains smoothly with spring motion as progress goes up, the label shows the percentage, and the wrapper switches to role="progressbar" with proper ARIA values. At 100% the bag is empty and the dripping stops. This is useful for report uploads, appointment booking, and payment steps. The outline uses currentColor, so it adapts to light or dark themes. Clip and gradient IDs come from React's useId, so multiple loaders can share a page without conflicts. When prefers-reduced-motion is enabled, the bag stops swinging, the waves and dripping stop, and a still drop stays at the tip. "use client" is included, so it works in Vite, Create React App, and Next.js. Tags iv-drip-loader healthcare medical-loader react-loader loading-animation liquid-animation drip-animation progress-bar doctor-website hospital clinic react typescript motion framer-motion tailwind-css accessible

Install

terminal
npm
npm create vite@latest my-app -- --template react-ts cd my-app npm install motion npm run dev

Dependencies

motion
Added Nov 25, 2026

Discussion

Feedback, implementation tips, and usage notes.

0 threads

Comments

Sign in to join the conversation