Skip to main content

Toaster

Struct Toaster 

Source
pub struct Toaster<S> { /* private fields */ }
Expand description

The corner of the page that shows the toasts in the list toasts.

It is a landmark region named “Notifications” holding an aria-live="polite" list, so a screen reader reads a toast when it is added, after what it is reading. Each toast has a button that removes it. A toast stays until it is dismissed, unless Toaster::dismiss_after sets a time, because a visitor who reads slowly or uses a magnifier can miss a notice that leaves by itself (WCAG 2.2.1).

The region sits in the page rather than in the top layer, so an open modal dialog covers it and makes it inert until the dialog closes.

use hypersig::Signals;
use hypersig_ui::{Toast, Toaster};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct App {
    toasts: Vec<Toast>,
}

let toaster = Toaster::new(App::toasts()).render();
let html = toaster.render();
assert!(html.contains(r#"aria-label="Notifications""#));
assert!(html.contains(r#"aria-live="polite""#));

Implementations§

Source§

impl<S> Toaster<S>

Source

pub fn new(toasts: Sig<S, Vec<Toast>>) -> Self

A region that shows toasts, newest last.

Source

pub fn label(self, label: impl Into<String>) -> Self

Names the region for assistive technology, in place of “Notifications”.

Source

pub fn dismiss_after(self, delay: Duration) -> Self

Removes each toast delay after it appears.

The time runs while the pointer or focus is on the toast, so give it long enough to read the longest toast twice.

Source

pub fn render(self) -> El<S>

The region and its list.

Trait Implementations§

Source§

impl<S: Debug> Debug for Toaster<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> From<Toaster<S>> for El<S>

Source§

fn from(toaster: Toaster<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Toaster<S>> for Node<S>

Source§

fn from(toaster: Toaster<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Toaster<S>

§

impl<S> RefUnwindSafe for Toaster<S>

§

impl<S> Send for Toaster<S>

§

impl<S> Sync for Toaster<S>

§

impl<S> Unpin for Toaster<S>

§

impl<S> UnsafeUnpin for Toaster<S>

§

impl<S> UnwindSafe for Toaster<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.