use super::{
BuilderCxFn, BuilderFn, ControlRenderData, GetterVanityControlData, VanityControlBuilder,
VanityControlData,
};
use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle};
use leptos::prelude::{AnyView, Signal};
use std::sync::Arc;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum HeadingLevel {
#[default]
H1,
H2,
H3,
H4,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct HeadingData {
pub level: HeadingLevel,
}
impl<FD: FormToolData> VanityControlData<FD> for HeadingData {
fn render_control<FS: FormStyle>(
fs: &FS,
_fd: leptos::prelude::RwSignal<FD>,
control: ControlRenderData<FS, Self>,
value_getter: Option<Signal<String>>,
) -> AnyView {
fs.heading(control, value_getter)
}
}
impl<FD: FormToolData> GetterVanityControlData<FD> for HeadingData {}
impl<FD: FormToolData> FormBuilder<FD> {
pub fn heading(self, builder: impl BuilderFn<VanityControlBuilder<FD, HeadingData>>) -> Self {
self.new_vanity(builder)
}
pub fn heading_cx(
self,
builder: impl BuilderCxFn<VanityControlBuilder<FD, HeadingData>, FD::Context>,
) -> Self {
self.new_vanity_cx(builder)
}
}
impl<FD: FormToolData> VanityControlBuilder<FD, HeadingData> {
pub fn title(mut self, title: impl ToString) -> Self {
let title = title.to_string();
self.getter = Some(Arc::new(move |_| title.clone()));
self
}
pub fn h1(mut self) -> Self {
self.data.level = HeadingLevel::H1;
self
}
pub fn h2(mut self) -> Self {
self.data.level = HeadingLevel::H2;
self
}
pub fn h3(mut self) -> Self {
self.data.level = HeadingLevel::H3;
self
}
pub fn h4(mut self) -> Self {
self.data.level = HeadingLevel::H4;
self
}
}