Expand description
<button/>
Examples found in repository?
src/dialog/alert.rs (line 77)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn comp_alert_modal<T, U, V>(options: AlertOptions, show: bool, on_read: U, on_close: V) -> Result<RespoNode<T>, String>
where
U: Fn(DispatchFn<T>) -> Result<(), String> + 'static,
V: Fn(DispatchFn<T>) -> Result<(), String> + 'static,
T: Clone + Debug,
{
let read = Rc::new(on_read);
let close = Rc::new(on_close);
let close2 = close.clone();
Ok(
RespoNode::new_component(
"alert-modal",
div()
.style(RespoStyle::default().position(CssPosition::Absolute).to_owned())
.children([if show {
div()
.class_list(&[ui_fullscreen(), ui_center(), css_backdrop()])
.style(options.backdrop_style)
.on_click(move |e, dispatch| -> Result<(), String> {
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
close(dispatch)?;
Ok(())
})
.children([div()
.class_list(&[ui_column(), ui_global(), css_modal_card()])
.style(RespoStyle::default().line_height(CssLineHeight::Px(32.0)).to_owned())
.style(options.card_style)
.on_click(move |e, _dispatch| -> Result<(), String> {
// nothing to do
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
Ok(())
})
.children([div()
.children([
span().inner_text(options.text.unwrap_or_else(|| "Alert!".to_owned())).to_owned(),
space(None, Some(8)),
div()
.class(ui_row_parted())
.children([
span(),
button()
.class_list(&[ui_button(), css_button(), BUTTON_NAME.to_owned()])
.inner_text(options.button_text.unwrap_or_else(|| "Read".to_owned()))
.on_click(move |_e, dispatch| -> Result<(), String> {
let d2 = dispatch.clone();
read(dispatch)?;
close2(d2)?;
Ok(())
})
.to_owned(),
])
.to_owned(),
])
.to_owned()])
.to_owned()])
.to_owned()
} else {
span().attribute("data-name", "placeholder").to_owned()
}])
.to_owned(),
)
.effect(&[show], effect_focus)
.effect(&[show], effect_modal_fade)
.share_with_ref(),
)
}More examples
src/dialog/confirm.rs (line 84)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
fn comp_confirm_modal<T, U, V>(options: ConfirmOptions, show: bool, on_confirm: U, on_close: V) -> Result<RespoNode<T>, String>
where
U: Fn(DispatchFn<T>) -> Result<(), String> + 'static,
V: Fn(DispatchFn<T>) -> Result<(), String> + 'static,
T: Clone + Debug,
{
let confirm = Rc::new(on_confirm);
let close = Rc::new(on_close);
let close2 = close.clone();
Ok(
RespoNode::new_component(
"confirm-modal",
div()
.style(RespoStyle::default().position(CssPosition::Absolute).to_owned())
.children([if show {
div()
.class_list(&[ui_fullscreen(), ui_center(), css_backdrop()])
.style(options.backdrop_style)
.on_click(move |e, dispatch| -> Result<(), String> {
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
close(dispatch)?;
Ok(())
})
.children([div()
.class_list(&[ui_column(), ui_global(), css_modal_card()])
.style(RespoStyle::default().line_height(CssLineHeight::Px(32.0)).to_owned())
.style(options.card_style)
.on_click(move |e, _dispatch| -> Result<(), String> {
// nothing to do
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
Ok(())
})
.children([div()
.children([
span()
.inner_text(options.text.unwrap_or_else(|| "Need confirmation...".to_owned()))
.to_owned(),
space(None, Some(8)),
div()
.class(ui_row_parted())
.children([
span(),
button()
.class_list(&[ui_button(), css_button(), BUTTON_NAME.to_owned()])
.inner_text(options.button_text.unwrap_or_else(|| "Confirm".to_owned()))
.on_click(move |_e, dispatch| -> Result<(), String> {
let d2 = dispatch.clone();
confirm(dispatch)?;
close2(d2)?;
Ok(())
})
.to_owned(),
])
.to_owned(),
])
.to_owned()])
.to_owned()])
.to_owned()
} else {
span().attribute("data-name", "placeholder").to_owned()
}])
.to_owned(),
)
.effect(&[show], effect_focus)
.effect(&[show], effect_modal_fade)
.share_with_ref(),
)
}src/dialog/prompt.rs (line 206)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
fn comp_prompt_modal<T, U, V>(
states: StatesTree,
options: PromptOptions,
show: bool,
on_submit: U,
on_close: V,
) -> Result<RespoNode<T>, String>
where
U: Fn(String, DispatchFn<T>) -> Result<(), String> + 'static,
V: Fn(DispatchFn<T>) -> Result<(), String> + 'static,
T: Clone + Debug + RespoAction,
{
let cursor = states.path();
let cursor2 = cursor.clone();
let cursor3 = cursor.clone();
let mut state: InputState = states.data.cast_or_default()?;
if let Some(text) = &options.initial_value {
state.draft = text.to_owned();
}
// respo::util::log!("State: {:?}", state);
let state2 = state.clone();
let submit = Rc::new(on_submit);
let close = Rc::new(on_close);
let close2 = close.clone();
let on_text_input = move |e, dispatch: DispatchFn<_>| -> Result<(), String> {
if let RespoEvent::Input { value, .. } = e {
dispatch.run_state(&cursor, InputState { draft: value, error: None })?;
}
Ok(())
};
let check_submit = move |text: &str, dispatch: DispatchFn<_>| -> Result<(), String> {
let dispatch2 = dispatch.clone();
let dispatch3 = dispatch.clone();
let dispatch4 = dispatch.clone();
respo::util::log!("validator: {:?}", &options.validator);
if let Some(validator) = &options.validator {
// let validator = validator.borrow();
let result = validator.run(text);
match result {
Ok(()) => {
submit(text.to_owned(), dispatch)?;
close2(dispatch3)?;
dispatch4.run_empty_state(&cursor2)?;
}
Err(message) => {
// dispatch.run_state(&cursor2, InputState { draft: text.to_owned() })?;
dispatch4.run_state(
&cursor2,
InputState {
draft: text.to_owned(),
error: Some(message),
},
)?;
}
}
} else {
submit(text.to_owned(), dispatch)?;
close2(dispatch2)?;
dispatch4.run_empty_state(&cursor2)?;
}
Ok(())
};
let mut input_el = if options.multilines {
textarea().class(ui_textarea()).to_owned()
} else {
input().class(ui_input()).to_owned()
};
Ok(
RespoNode::new_component(
"prompt-modal",
div()
.style(RespoStyle::default().position(CssPosition::Absolute).to_owned())
.children([if show {
div()
.class_list(&[ui_fullscreen(), ui_center(), css_backdrop()])
.style(options.backdrop_style)
.on_click(move |e, dispatch| -> Result<(), String> {
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
{
let dispatch = dispatch.clone();
close(dispatch)?;
}
dispatch.run_empty_state(&cursor3)?;
Ok(())
})
.children([div()
.class_list(&[ui_column(), ui_global(), css_modal_card()])
.style(RespoStyle::default().line_height(CssLineHeight::Px(32.0)).to_owned())
.style(options.card_style)
.style(options.input_style)
.on_click(move |e, _dispatch| -> Result<(), String> {
// nothing to do
if let RespoEvent::Click { original_event, .. } = e {
// stop propagation to prevent closing the modal
original_event.stop_propagation();
}
Ok(())
})
.children([div()
.children([
span()
.inner_text(options.text.unwrap_or_else(|| "Input your text:".to_owned()))
.to_owned(),
space(None, Some(8)),
div()
.children([input_el
.class_list(&[ui_input()])
.style(RespoStyle::default().width(CssSize::Percent(100.0)).to_owned())
.attribute("placeholder", "Content...")
.attribute("autoFocus", "autofocus")
.value(state.draft)
.on_input(on_text_input)
.to_owned()])
.to_owned(),
match &state.error {
Some(message) => div().class_list(&[css_error()]).inner_text(message).to_owned(),
None => span(),
},
space(None, Some(8)),
div()
.class(ui_row_parted())
.children([
span(),
button()
.class_list(&[ui_button(), css_button(), BUTTON_NAME.to_owned()])
.inner_text(options.button_text.unwrap_or_else(|| "Submit".to_owned()))
.on_click(move |_e, dispatch| -> Result<(), String> {
check_submit(&state2.draft, dispatch)?;
Ok(())
})
.to_owned(),
])
.to_owned(),
])
.to_owned()])
.to_owned()])
.to_owned()
} else {
span().attribute("data-name", "placeholder").to_owned()
}])
.to_owned(),
)
// .effect(&[show], effect_focus)
.effect(&[show], effect_modal_fade)
.share_with_ref(),
)
}