kasturibuilds/generative-loaders
关于
Accessible React loading states for generative interfaces: streamed text, inline activity, and image generation.
设计与媒体实测星标增长
- 24小时
- +3
- 7天
- +11
- 15天
- +30
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Generative Loaders
Accessible React loading states designed for generative interfaces: sixteen animated text reveals, eighteen compact activity indicators, and twelve image-generation placeholders.
Live gallery · Documentation · npm · Report an issue
Install
npm install generative-loaders
The package supports React 18 and newer.
Quick start
Import the component you need and include the stylesheet once near your application root.
import { ImageLoader, InlineLoader, TextLoader } from "generative-loaders";
import "generative-loaders/styles.css";
export function GeneratingAnswer({ text }: { text: string }) {
return <TextLoader text={text} variant="decode" />;
}
export function PendingStatus() {
return <span><InlineLoader variant="orbit" /> Thinking…</span>;
}
export function PendingImage() {
return <ImageLoader variant="tiles" size={192} label="Generating product image" />;
}
Three primitives
| Component | Use it for | Included variants |
|---|---|---|
TextLoader |
Responses that grow as tokens or chunks arrive | 16 |
InlineLoader |
Buttons, status rows, and the wait before text arrives | 18 |
ImageLoader |
Reserved image frames while generation is in progress | 12 |
Streaming text
Pass the complete response received so far—not only the newest token. TextLoader keeps the existing prefix stable and animates only the newly appended suffix.
"use client";
import { useState } from "react";
import { TextLoader } from "generative-loaders";
import "generative-loaders/styles.css";
export function StreamingAnswer() {
const [text, setText] = useState("");
async function generate() {
setText("");
const response = await fetch("/api/generate", { method: "POST" });
if (!response.ok || !response.body) throw new Error("Generation failed");
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) break;
setText((current) => current + decoder.decode(value, { stream: true }));
}
}
return <TextLoader text={text} variant="cascade" />;
}
Variants
Text: decode, typewriter, skeleton, cascade, focus, wipe, flip, redact, line, terminal, wave, dissolve, slice, tracking, coalesce, fragments
Inline: glyph, matrix, orbit, ripple, signal, spark, rotor, pixel-drift, chomp, snake, fold, gravity, domino, aperture, dot-pulse, vortex, halo, count-up
Image: skeleton, bands, tiles, scan, pixel-grid, resolution, coalesce, diffusion, raster, bloom, focus, shutter
See every variant, speed control, and usage context in the live gallery.
API
TextLoader
| Prop | Type | Default |
|---|---|---|
text |
string |
required |
variant |
TextLoaderVariant |
required |
color |
CSS color string | "#111111" |
speed |
positive number | 1 |
paused |
boolean |
false |
className |
string |
— |
aria-label |
string |
normalized text |
InlineLoader accepts variant, size, color, speed, paused, className, and an optional accessible label.
ImageLoader accepts variant, size, color, radius, speed, paused, className, and label. Its default label is “Generating image.”
All prop and variant types are exported from the package root.
Accessibility and behavior
TextLoaderexposes received text through a polite live status while keeping decorative animation layers hidden from assistive technology.InlineLoaderavoids duplicate announcements when adjacent text already describes the activity; addlabelwhen it stands alone.- Every loader respects
prefers-reduced-motionand retains a meaningful static state. - Text updates are append-aware, so previously received content does not reanimate.
- Components render stable server markup and are safe to use in SSR applications.
- Invalid, zero, or negative speed values safely fall back to
1.
Development
This public repository contains the publishable npm package. The live website is maintained separately from the public package source.
npm install
npm test
Before opening a pull request, run:
npm test
npm run lint
npm pack --workspace generative-loaders --dry-run
See CONTRIBUTING.md for the full workflow. For help using the package, read the documentation or open an issue.
License
MIT © Kasturi Khanke and Generative Loaders contributors.
探索相关项目
加载中…