use tablo_ui::{input as ui_input, select as ui_select, switch as ui_switch};
use topcoat::{context::Cx, view::*};
pub(super) fn toggle<'a>(cx: &'a Cx, name: &str, label: String, checked: bool) -> BoxView<'a> {
let name = name.to_string();
view! {
<input type="hidden" name=(name.clone()) value="false">
ui_switch(
attrs: attributes! {
name=(name)
value="true"
checked=(checked)
aria-label=(label)
}
)
}
.boxed()
}
pub(super) fn select<'a>(
cx: &'a Cx,
name: &str,
label: String,
selected: String,
options: Vec<(String, String)>,
) -> BoxView<'a> {
let name = name.to_string();
view! {
ui_select(
attrs: attributes! { name=(name) aria-label=(label) class="min-w-32" },
for (value, text) in options {
<option value=(value.clone()) selected=(value == selected)>
(text)
</option>
}
)
}
.boxed()
}
pub(super) struct TextInput<'n> {
pub(super) name: &'n str,
pub(super) label: String,
pub(super) value: String,
pub(super) input_type: &'static str,
pub(super) step: Option<&'static str>,
}
pub(super) fn text_input<'a>(cx: &'a Cx, input: TextInput<'_>) -> BoxView<'a> {
let name = input.name.to_string();
view! {
ui_input(
attrs: attributes! {
type=(input.input_type)
name=(name)
value=(input.value)
step=(input.step)
aria-label=(input.label)
class="h-8 min-w-24"
}
)
}
.boxed()
}