patternfly_yew/utils/
action.rs

1use yew::prelude::*;
2
3/// Definition of an action.
4#[derive(Clone, PartialEq, Default, Debug)]
5pub struct Action {
6    /// The label for the end user
7    pub label: String,
8    /// The callback to execute when the action is triggered
9    pub callback: Callback<()>,
10}
11
12impl Action {
13    pub fn new<S>(label: S, callback: Callback<()>) -> Self
14    where
15        S: ToString,
16    {
17        Self {
18            label: label.to_string(),
19            callback,
20        }
21    }
22}
23
24/// Allows converting something into an [`Action`] by providing a label.
25pub trait IntoAction {
26    fn into_action<S: ToString>(self, label: S) -> Action;
27}
28
29impl IntoAction for Callback<()> {
30    fn into_action<S>(self, label: S) -> Action
31    where
32        S: ToString,
33    {
34        Action::new(label, self)
35    }
36}