Image Generation
Installation
npx shadcn@latest add https://uibrik.com/r/image-generation.jsonAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Set up squircle corners
Needs
@squircle/core,@squircle/tailwindcssand a few lines of CSS. See squircle setup.Copy the source into your project
components/uibrik/image-generation/ImageGeneration.tsx"use client"; import { useState } from "react"; import DitherGrid from "./DitherGrid"; import GeneratingStatus from "./GeneratingStatus"; import { cn } from "@/lib/utils"; export type ImageGenerationProps = { /** The generated picture. */ src: string; /** The request shown as a chat bubble above the card. Empty hides it. */ prompt?: string; /** Square size of the dither field in px. */ cell?: number; /** Seconds of pure dither before the picture starts to appear. */ delay?: number; /** Seconds for the reveal band to travel top to bottom. */ sweep?: number; /** Band height as a share of the card. */ band?: number; /** Card width in px; the picture is 2:3. */ width?: number; /** Called once the picture is fully revealed. */ onDone?: () => void; className?: string; }; /** A chat-style image request whose placeholder dithers into the finished picture. */ export function ImageGeneration({ src, prompt = "Generate an image of beautiful mountains", cell = 6, delay = 1.5, sweep = 3.2, band = 0.22, width = 320, onDone, className, }: ImageGenerationProps) { const [done, setDone] = useState(false); return ( <div className={cn("flex w-140 max-w-full flex-col gap-4", className)}> {prompt && ( <p className="ml-auto squircle-mask squircle-2xl bg-neutral-100 px-3 py-2 text-xl font-medium tracking-tight text-zinc-600 dark:bg-neutral-900 dark:text-zinc-300"> {prompt} </p> )} <div className="flex flex-col gap-1.5"> <div className="w-fit squircle-mask squircle-4xl bg-neutral-100 p-3 dark:bg-neutral-900"> {/* drop-shadow, not shadow-md: the squircle mask would clip a box-shadow */} <div className="drop-shadow-md"> <div className="relative aspect-2/3 overflow-hidden squircle-mask squircle-3xl" style={{ width }} > <DitherGrid src={src} cell={cell} delay={delay} sweep={sweep} band={band} className="size-full" onDone={() => { setDone(true); onDone?.(); }} /> </div> </div> </div> <GeneratingStatus done={done} /> </div> </div> ); }
Adds the files to
components/uibrik/image-generation. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/image-generation.Props
ImageGeneration- prompt
- Type string
- "Generate an image of beautiful mountains"
- Request shown above the card. Empty hides it.
- cell
- Type number
- 6
- Square size of the dither field.
- delay
- Type number
- 1.5
- Pure dither before the picture starts to appear.
- sweep
- Type number
- 3.2
- How long the reveal band takes to travel down.
- band
- Type number
- 0.22
- Band height as a share of the card.
- width
- Type number
- 320
- Card width; the picture is 2:3.
- srcrequired
- Type string
- –
- The generated picture.
- onDone
- Type () => void
- –
- Called once the picture is fully revealed.
- className
- Type string
- –
- Classes for the wrapper.