animated-toast-promise-demo
jolyui-ui/animated-toast-promise-demoFreeExample
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/animated-toast-promise-demo.jsonSource
1"use client";23import { useState } from "react";4import {5 AnimatedToastProvider,6 usePromiseToast,7} from "@/registry/default/ui/animated-toast";89function PromiseToastDemoContent() {10 const promiseToast = usePromiseToast();11 const [result, setResult] = useState<string>("");1213 const simulateAsyncOperation = (shouldSucceed: boolean): Promise<string> => {14 return new Promise((resolve, reject) => {15 setTimeout(() => {16 if (shouldSucceed) {17 resolve("Operation completed successfully!");18 } else {19 reject(new Error("Operation failed!"));20 }21 }, 2000);22 });23 };2425 const handleSuccess = async () => {26 try {27 const data = await promiseToast({28 promise: simulateAsyncOperation(true),29 loading: "Processing your request...",30 success: (result) => `Success: ${result}`,31 error: (err) => `Error: ${err.message}`,32 });33 setResult(data);34 } catch (_error) {35 // Error already handled by toast36 }37 };3839 const handleError = async () => {40 try {41 const data = await promiseToast({42 promise: simulateAsyncOperation(false),43 loading: "Processing your request...",44 success: (result) => `Success: ${result}`,45 error: (err) => `Error: ${err.message}`,46 });47 setResult(data);48 } catch (_error) {49 // Error already handled by toast50 }51 };5253 return (54 <div className="p-8">55 <p className="mb-4 text-muted-foreground">56 Click buttons to simulate async operations with toast feedback.57 </p>5859 <div className="mb-4 flex flex-wrap gap-4">60 <button61 onClick={handleSuccess}62 className="rounded-md bg-green-500 px-4 py-2 text-white transition-colors hover:bg-green-600"63 >64 Simulate Success65 </button>66 <button67 onClick={handleError}68 className="rounded-md bg-red-500 px-4 py-2 text-white transition-colors hover:bg-red-600"69 >70 Simulate Error71 </button>72 </div>7374 {result && (75 <div className="rounded-md bg-muted p-4">76 <p className="font-medium text-sm">Result:</p>77 <p className="text-muted-foreground text-sm">{result}</p>78 </div>79 )}80 </div>81 );82}8384export default function AnimatedToastPromiseDemo() {85 return (86 <AnimatedToastProvider position="top-center">87 <PromiseToastDemoContent />88 </AnimatedToastProvider>89 );90}
What it pulls in
npm packages
Other registry items
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-box-demoai-prompt-box-demo | jolyui/ui | Examples | Free | no deps | |
| ai-prompt-box-loading-demoai-prompt-box-loading-demo | jolyui/ui | Examples | Free | no deps | |
| animated-beam-bidirectional-demoanimated-beam-bidirectional-demo | jolyui/ui | Examples | Free | 1 dep | |
| animated-beam-curved-demoanimated-beam-curved-demo | jolyui/ui | Examples | Free | 1 dep | |
| animated-beam-demoanimated-beam-demo | jolyui/ui | Examples | Free | 1 dep | |
| animated-beam-multiple-demoanimated-beam-multiple-demo | jolyui/ui | Examples | Free | 1 dep | |
| animated-table-basic-demoanimated-table-basic-demo | jolyui/ui | Examples | Free | no deps | |
| animated-table-column-demoanimated-table-column-demo | jolyui/ui | Examples | Free | no deps |
