use crate::{class::Class, format_class};
use dioxus::prelude::*;
use std::borrow::Cow;
use zino_core::JsonValue;
pub fn FixedWidthSpan<'a>(cx: Scope<'a, FixedWidthSpanProps<'a>>) -> Element {
let class = format_class!(cx, "is-inline-block");
let mut style = match &cx.props.width {
JsonValue::Number(value) => format!("width:{value}px;"),
JsonValue::String(value) => format!("width:{value};"),
_ => String::new(),
};
if let Some(alignment) = cx.props.align.as_deref() {
style.push_str("text-align:");
style.push_str(alignment);
}
render! {
span {
class: "{class}",
style: "{style}",
&cx.props.children
}
}
}
#[derive(Props)]
pub struct FixedWidthSpanProps<'a> {
#[props(into)]
pub class: Option<Class<'a>>,
#[props(into)]
pub width: JsonValue,
#[props(into)]
pub align: Option<Cow<'a, str>>,
children: Element<'a>,
}