feat(toast): add Toast.useToastTime #375
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds
Toast.useToastTime
, which can be used to access the elapsed and remaining time (or fraction of the duration) that a toast has been / will stay open for.The code is extracted from/inspired by
Toast.ProgressFill
and I adjustedToast.ProgressFill
to use the new API.Motivation
I use daisyUI to style kobalte components. daisyUI provides a progress component (component means set of css classes here), that i would like to use with kobalte's toast system.
The problem is that daisyUI uses a native
progress
element, while kobalte uses twodiv
s (Toast.ProgressTrack
andToast.ProgressFill
) and relies on a css variable to show the current value. Sadly, I don't think there is a direct way to use the css variable to populate thevalue
attribute of theprogress
element. I could try to use a hiddenToast.ProgressFill
, listen to changes of its--kb-toast-progress-fill-width
variable and apply the value to thevalue
property of theprogress
element, but that sounds like ugly code and poor performance.Since I see no other way to get the value I need from kobalte, I propose to add this API. If there is a way I didn't see, please let me know :)
Docs
The custom
progress
element in the new example forToast.useToastTime
is currently unstyled, which doesn't fit nicely into the rest of the docs. I'm unsure whether we should add some styles to make it fit better or leave it as-is to show that it really is a raw/nativeprogress
element.