Files
cosscom__coss/apps/ui/public/r/toast-promise.json
Volnei Munhoz d5a915e6d0 add biome
2025-11-13 19:19:31 -03:00

16 lines
1.6 KiB
JSON

{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "toast-promise",
"type": "registry:example",
"description": "Drive toasts from promise states",
"registryDependencies": ["@coss/toast"],
"files": [
{
"path": "registry/default/examples/toast-promise.tsx",
"content": "\"use client\"\n\nimport { Button } from \"@/registry/default/ui/button\"\nimport { toastManager } from \"@/registry/default/ui/toast\"\n\nexport default function ToastPromise() {\n return (\n <Button\n variant=\"outline\"\n onClick={() => {\n toastManager.promise(\n new Promise<string>((resolve, reject) => {\n const shouldSucceed = Math.random() > 0.3\n setTimeout(() => {\n if (shouldSucceed) {\n resolve(\"Data loaded successfully\")\n } else {\n reject(new Error(\"Failed to load data\"))\n }\n }, 2000)\n }),\n {\n loading: {\n title: \"Loading…\",\n description: \"The promise is loading.\",\n },\n success: (data: string) => ({\n title: \"This is a success toast!\",\n description: `Success: ${data}`,\n }),\n error: () => ({\n title: \"Something went wrong\",\n description: \"Please try again.\",\n }),\n }\n )\n }}\n >\n Run Promise\n </Button>\n )\n}\n",
"type": "registry:example"
}
],
"categories": ["toast", "button"]
}