Skip to content

Instantly share code, notes, and snippets.

@StarKnightt
Created February 19, 2026 15:01
Show Gist options
  • Select an option

  • Save StarKnightt/a8d5c7cb87424e80555bc847cece79b0 to your computer and use it in GitHub Desktop.

Select an option

Save StarKnightt/a8d5c7cb87424e80555bc847cece79b0 to your computer and use it in GitHub Desktop.
Prompt to build an interactive liquid distortion effect component for React/Next.js using shadcn, Tailwind CSS & Three.js

You are given a task to integrate an existing React component in the codebase.

The codebase should support:

  • shadcn project structure
  • Tailwind CSS
  • TypeScript

If it doesn't, provide instructions on how to setup the project via shadcn CLI, install Tailwind or TypeScript.

Determine the default path for components and styles. If the default path for components is not /components/ui, provide instructions on why it's important to create this folder.

Copy-paste this component to the /components/ui folder:

liquid-effect-animation.tsx

"use client"

import { useEffect, useRef, useCallback } from "react"

interface LiquidEffectAnimationProps {
  text?: string[]
  subText?: string
  tagline?: string
  backgroundColor?: string
  textColor?: string
}

export function LiquidEffectAnimation({
  text,
  subText,
  tagline,
  backgroundColor = "#fafafa",
  textColor = "#1d1d1f",
}: LiquidEffectAnimationProps) {
  const canvasRef = useRef<HTMLCanvasElement>(null)

  const generateTextImage = useCallback(() => {
    const dpr = window.devicePixelRatio || 1
    const offscreen = document.createElement("canvas")
    const w = window.innerWidth
    const h = window.innerHeight
    offscreen.width = w * dpr
    offscreen.height = h * dpr
    const ctx = offscreen.getContext("2d")
    if (!ctx) return null

    ctx.scale(dpr, dpr)

    ctx.fillStyle = backgroundColor
    ctx.fillRect(0, 0, w, h)

    ctx.globalCompositeOperation = "multiply"

    const glow1 = ctx.createRadialGradient(w * 0.5, h * 0.1, 0, w * 0.5, h * 0.1, w * 0.6)
    glow1.addColorStop(0, "rgba(220, 225, 240, 0.6)")
    glow1.addColorStop(1, "rgba(250, 250, 250, 1)")
    ctx.fillStyle = glow1
    ctx.fillRect(0, 0, w, h)

    const glow2 = ctx.createRadialGradient(w * 0.5, h * 0.95, 0, w * 0.5, h * 0.95, w * 0.5)
    glow2.addColorStop(0, "rgba(240, 230, 220, 0.4)")
    glow2.addColorStop(1, "rgba(250, 250, 250, 1)")
    ctx.fillStyle = glow2
    ctx.fillRect(0, 0, w, h)

    ctx.globalCompositeOperation = "source-over"

    ctx.fillStyle = textColor
    ctx.globalAlpha = 0.35
    const subFontSize = Math.max(11, w * 0.009)
    ctx.font = `600 ${subFontSize}px -apple-system, "SF Pro Display", "Helvetica Neue", Arial, sans-serif`
    ctx.textAlign = "center"
    ctx.letterSpacing = "0.25em"
    if (subText) {
      ctx.fillText(subText.toUpperCase(), w / 2, h / 2 - w * 0.095)
    }

    ctx.globalAlpha = 1
    ctx.letterSpacing = "-0.04em"
    const fontSize = Math.min(w * 0.13, h * 0.19)
    ctx.font = `700 ${fontSize}px -apple-system, "SF Pro Display", "Helvetica Neue", Arial, sans-serif`
    ctx.textAlign = "center"
    ctx.textBaseline = "middle"

    const lineHeight = fontSize * 1.08
    const totalHeight = (text?.length || 0) * lineHeight
    const startY = h / 2 - totalHeight / 2 + lineHeight / 2

    text?.forEach((line, i) => {
      ctx.fillStyle = textColor
      ctx.globalAlpha = 1
      ctx.fillText(line, w / 2, startY + i * lineHeight)
    })

    ctx.globalAlpha = 0.12
    ctx.fillStyle = textColor
    const dividerY = startY + (text?.length || 0) * lineHeight + w * 0.018
    ctx.fillRect(w / 2 - 30, dividerY, 60, 0.5)

    if (tagline) {
      ctx.globalAlpha = 0.3
      ctx.letterSpacing = "0.02em"
      const tagFontSize = Math.max(11, w * 0.01)
      ctx.font = `400 ${tagFontSize}px -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif`
      ctx.fillText(tagline, w / 2, dividerY + w * 0.025)
    }

    return offscreen.toDataURL("image/png")
  }, [text, subText, tagline, backgroundColor, textColor])

  useEffect(() => {
    if (!canvasRef.current) return

    const dataUrl = generateTextImage()
    if (!dataUrl) return

    const script = document.createElement("script")
    script.type = "module"
    script.textContent = `
      import LiquidBackground from 'https://cdn.jsdelivr.net/npm/threejs-components@0.0.30/build/backgrounds/liquid1.min.js';

      const canvas = document.getElementById('liquid-canvas');
      if (canvas) {
        const app = LiquidBackground(canvas);
        app.loadImage('${dataUrl}');
        app.liquidPlane.material.metalness = 0.35;
        app.liquidPlane.material.roughness = 0.45;
        app.liquidPlane.uniforms.displacementScale.value = 2;
        app.setRain(false);
        window.__liquidApp = app;
      }
    `
    document.body.appendChild(script)

    return () => {
      if (window.__liquidApp && window.__liquidApp.dispose) {
        window.__liquidApp.dispose()
      }
      if (script.parentNode) {
        script.parentNode.removeChild(script)
      }
    }
  }, [generateTextImage])

  return (
    <div className="fixed inset-0 m-0 w-full h-full touch-none overflow-hidden">
      <canvas
        ref={canvasRef}
        id="liquid-canvas"
        className="fixed inset-0 w-full h-full"
      />
    </div>
  )
}

declare global {
  interface Window {
    __liquidApp?: any
  }
}
demo.tsx

import { LiquidEffectAnimation } from "@/components/ui/liquid-effect-animation";

export default function DemoPage() {
  return (
    <LiquidEffectAnimation
      text={["Liquid", "Effect"]}
      subText="Interactive UI Component"
      tagline="Built with Three.js  •  React  •  Tailwind CSS"
      backgroundColor="#fafafa"
      textColor="#1d1d1f"
    />
  );
}

Credits: The liquid distortion effect is powered by threejs-components (https://github.com/klevron/threejs-components) by Kevin Levron (@soju22).

Implementation Guidelines

  1. Analyze the component structure and identify all required dependencies
  2. Review the component's arguments and state
  3. Identify any required context providers or hooks and install them
  4. Questions to Ask
    • What data/props will be passed to this component?
    • Are there any specific state management requirements?
    • Are there any required assets (images, icons, etc.)?
    • What is the expected responsive behavior?
    • What is the best place to use this component in the app?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment