Struct patternfly_yew::Toast

source ·
pub struct Toast {
    pub title: String,
    pub type: Type,
    pub timeout: Option<Duration>,
    pub body: Html,
    pub actions: Vec<Action>,
}
Expand description

Toasts are small alerts that get shown on the top right corner of the page.

A toast can be triggered by every component. The toast fill get sent to an agent, the Toaster. The toaster will delegate displaying the toast to an instance of a ToastViewer component.

In order for Toasts to be displayed your application must have exactly one ToastViewer before creating the first Toast.

For example:

pub struct App{
};
pub enum Msg {
  Toast(Toast),
}
type Message = Msg;

fn update(&mut self, _: &Context<Self>, msg: Self::Message) -> bool {
  match msg {
    Msg::Toast(toast) => {
      ToastDispatcher::new().toast(toast);
      false
    }
  }
}

fn view(&self, ctx: &Context<Self>) -> Html {
 html!{
    <>
      <ToastViewer/>
      <div>
        <button onclick={ctx.link().callback(|_|{
            Msg::Toast("Toast Title".into())
        })}>
          { "Click me" }  
        </button>
      </div>
    </>
  }
}

Fields§

§title: String§type: Type§timeout: Option<Duration>

The timeout when the toast will be removed automatically.

If no timeout is set, the toast will get a close button.

§body: Html§actions: Vec<Action>

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Allows to convert a string into a toast by using the string as title.

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

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

Convert self to a value of a Properties struct.
Convert self to a value of a Properties struct.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.