diff --git a/apps/docs/src/examples/toast.tsx b/apps/docs/src/examples/toast.tsx index 58652b66..6fd7c1e9 100644 --- a/apps/docs/src/examples/toast.tsx +++ b/apps/docs/src/examples/toast.tsx @@ -1,4 +1,5 @@ import { Toast, toaster } from "@kobalte/core"; +import { Accessor } from "solid-js"; import { CrossIcon } from "../components"; import style from "./toast.module.css"; @@ -115,16 +116,39 @@ export function MultipleRegionsExample() { ); } -function CustomProgress() { - const { remainingFraction } = Toast.useToastTime(); - return ; +function ToastTimeExampleToastBody() { + const { remainingTime, remainingFraction, elapsedTime, elapsedFraction } = + Toast.useToastTime(); + const format = (time: Accessor, fraction: Accessor) => ( + <> + {(time() / 1000).toFixed(1)}s ({Math.round(fraction() * 100)}%) + > + ); + return ( + <> + + + + Remaining time: {format(remainingTime, remainingFraction)} + + + Elapsed time: {format(elapsedTime, elapsedFraction)} + + + + + + + + > + ); } -export function CustomProgressExample() { +export function ToastTimeExample() { const showToast = () => { toaster.show((props) => ( - + )); }; diff --git a/apps/docs/src/routes/docs/core/components/toast.mdx b/apps/docs/src/routes/docs/core/components/toast.mdx index cd66ff5c..f609257a 100644 --- a/apps/docs/src/routes/docs/core/components/toast.mdx +++ b/apps/docs/src/routes/docs/core/components/toast.mdx @@ -1,9 +1,5 @@ import { Preview, TabsSnippets, Callout, Kbd } from "../../../../components"; -import { - BasicExample, - CustomProgressExample, - MultipleRegionsExample, -} from "../../../../examples/toast"; +import { BasicExample, MultipleRegionsExample, ToastTimeExample } from "../../../../examples/toast"; # Toast @@ -566,20 +562,42 @@ It should be used within `Toast.Root`, e. g. in a component that replaces `Toast ```tsx import { Toast, toaster } from "@kobalte/core"; -function CustomProgress() { - const { remainingFraction } = Toast.useToastTime(); - return ; +function ToastBody() { + const { remainingTime, remainingFraction, elapsedTime, elapsedFraction } = Toast.useToastTime(); + const format = (time: Accessor, fraction: Accessor) => ( + <> + {(time() / 1000).toFixed(1)}s ({Math.round(fraction() * 100)}%) + > + ); + return ( + <> + + + + Remaining time: {format(remainingTime, remainingFraction)} + + + Elapsed time: {format(elapsedTime, elapsedFraction)} + + + + + + + + > + ); } toaster.show(props => ( - + )); ``` - + ## API reference