htmx_components/server/
yc_control.rs1use super::html_element::HtmlElement;
2use rscx::{component, html, props};
3use rscx_web_macros::{html_element, spread_attrs};
4
5#[html_element]
6pub struct YcControlProps {
7 #[builder(setter(into), default)]
8 control: String,
9
10 #[builder(default)]
11 children: String,
12}
13
14#[component]
15pub fn YcControl(props: YcControlProps) -> String {
16 html! {
17 <HtmlElement
18 attrs=spread_attrs!(props).set("data-yc-control", props.control)
19 >
20 {props.children}
21 <script>"YcControls.attach(document.currentScript.parentElement);"</script>
22 </HtmlElement>
23 }
24}
25
26#[html_element]
27pub struct ToggleProps {
28 #[builder(default)]
29 children: String,
30}
31
32#[component]
33pub fn Toggle(props: ToggleProps) -> String {
34 html! {
35 <YcControl
36 control="toggle"
37 attrs=spread_attrs!(props)
38 >
39 {props.children}
40 </YcControl>
41 }
42}
43
44#[props]
45pub struct YcControlJsApiProps {
46 #[builder(setter(into))]
47 call: String,
48}
49
50#[component]
51pub fn YcControlJsApi(props: YcControlJsApiProps) -> String {
52 html! {
53 <script>
54 {format!(
55 r#"
56 (function(callerScript) {{
57 YcControls.onReady(function() {{
58 YcControls.{};
59 }});
60 }}(document.currentScript));
61 "#,
62 props.call,
63 )}
64 </script>
65 }
66}