material_dioxus/dialog/
dialog_action.rs

1use dioxus::prelude::*;
2use std::fmt;
3
4/// Dialog action type.
5#[derive(Clone, PartialEq)]
6pub enum ActionType {
7    /// Binds `to slot` of `primaryAction`
8    Primary,
9    /// Binds `to slot` of `secondaryAction`
10    Secondary,
11}
12
13impl ActionType {
14    pub fn as_str(&self) -> &'static str {
15        match self {
16            ActionType::Primary => "primaryAction",
17            ActionType::Secondary => "secondaryAction",
18        }
19    }
20}
21
22impl fmt::Display for ActionType {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        write!(f, "{}", self.as_str())
25    }
26}
27
28/// Props for [`MatDialogAction`]
29#[derive(Props)]
30pub struct ActionProps<'a> {
31    pub action_type: ActionType,
32    #[props(into)]
33    pub action: Option<String>,
34    pub children: Element<'a>,
35}
36
37/// Defines actions for [`MatDialog`][crate::MatDialog].
38///
39/// The passed children are wrapped in a `span` with the required attributes
40/// set.
41#[allow(non_snake_case)]
42pub fn MatDialogAction<'a>(cx: Scope<'a, ActionProps<'a>>) -> Element<'a> {
43    render! {
44        span {
45            slot: "{cx.props.action_type}",
46            "dialogAction": optional_string_attr!(cx.props.action),
47            &cx.props.children
48        }
49    }
50}