[][src]Struct ybc::ModalCloser

pub struct ModalCloser { /* fields omitted */ }

An agent used for being able to close Modal & ModalCard instances by ID.

If custom modal closing functionality is need for your modal instance, the following pattern is recommended.

First, in your component which is using this modal, configure a ModalCloser dispatcher.

use yew::agent::Dispatcher;
use yew::prelude::*;
// .. snip ..
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
    let bridge = ModalCloser::dispatcher();
    Self{link, props, bridge}
}

Next, in your component's view method, setup a callback to handle your component's close event.

let closer = self.link.callback(|_| ModalCloseMsg("modal-0".into()));
// ... snip ...
<ModalCard
    id="modal-0"
    // ... snip ...
    footer=html!{
        <Button onclick=Some(closer)>{"Close"}</Button>
    }
/>

Finally, in your component's update method, send the ModalCloseMsg over to the agent which will forward the message to the modal to cause it to close.

fn update(&mut self, msg: Self::Message) -> ShouldRender {
    self.bridge.send(msg);
    true
}

This pattern allows you to communicate with a modal by its given ID, allowing you to close the modal from anywhere in your application.

Trait Implementations

impl Agent for ModalCloser[src]

type Reach = Context<Self>

Reach capability of the agent.

type Message = ()

Type of an input message.

type Input = ModalCloseMsg

Incoming message type.

type Output = ModalCloseMsg

Outgoing message type.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Bridged for T where
    T: Agent,
    <T as Agent>::Reach: Discoverer,
    <<T as Agent>::Reach as Discoverer>::Agent == T, 
[src]

impl<T> Dispatched for T where
    T: Agent,
    <T as Agent>::Reach: Discoverer,
    <T as Agent>::Reach: Dispatchable,
    <<T as Agent>::Reach as Discoverer>::Agent == T, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> NeqAssign<U> for T where
    T: BorrowMut<U>,
    U: PartialEq<U>, 
[src]

impl<T, U> NeqAssignBy<U> for T where
    T: BorrowMut<U>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.