MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / AlertDialogRoot

Function AlertDialogRoot

primitives/src/alert_dialog.rs:81–115  ·  view source on GitHub ↗
(props: AlertDialogRootProps)

Source from the content-addressed store, hash-verified

79/// - `data-state`: Indicates if the alert dialog is open or closed. It can be either "open" or "closed".
80#[component]
81pub fn AlertDialogRoot(props: AlertDialogRootProps) -> Element {
82 let labelledby = use_unique_id().to_string();
83 let describedby = use_unique_id().to_string();
84 let mut open_signal = use_signal(|| props.default_open);
85 let set_open = use_callback(move |v: bool| {
86 open_signal.set(v);
87 props.on_open_change.call(v);
88 });
89 let open = use_memo(move || (props.open)().unwrap_or_else(&*open_signal));
90 use_context_provider(|| AlertDialogCtx {
91 open,
92 set_open,
93 labelledby,
94 describedby,
95 });
96
97 let id = use_unique_id();
98 let id = use_id_or(id, props.id);
99 let render_element = use_animated_open(id, open);
100
101 rsx! {
102 document::Script {
103 src: FOCUS_TRAP_JS,
104 defer: true
105 }
106 if render_element() {
107 div {
108 id,
109 "data-state": if open() { "open" } else { "closed" },
110 ..props.attributes,
111 {props.children}
112 }
113 }
114 }
115}
116
117/// The props for the [`AlertDialogContent`] component.
118#[derive(Props, Clone, PartialEq)]

Callers

nothing calls this directly

Calls 3

use_unique_idFunction · 0.85
use_id_orFunction · 0.85
use_animated_openFunction · 0.85

Tested by

no test coverage detected