use alloc::{borrow::Cow, string::String};
use crate::Attribute;
impl<T: Into<Cow<'static, str>>> From<(&'static str, T)> for Attribute {
fn from((key, value): (&'static str, T)) -> Self {
Attribute::new(key, value)
}
}
pub fn id(id: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("id", id)
}
pub fn class<'a>(classes: impl IntoIterator<Item = &'a str>) -> Attribute {
let mut values = String::new();
let mut iter = classes.into_iter();
if let Some(value) = iter.next() {
values.push_str(value);
}
for value in iter {
values.push(' ');
values.push_str(value);
}
Attribute::new("class", values)
}
pub fn lang(lang: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("lang", lang)
}
#[derive(Debug, Clone)]
pub enum AnchorTarget {
Blank,
Self_,
Parent,
Top,
Frame(Cow<'static, str>),
}
pub fn target(target: AnchorTarget) -> Attribute {
Attribute::new(
"target",
match target {
AnchorTarget::Blank => "_blank".into(),
AnchorTarget::Self_ => "_self".into(),
AnchorTarget::Parent => "_parent".into(),
AnchorTarget::Top => "_top".into(),
AnchorTarget::Frame(name) => name,
},
)
}
pub fn target_blank() -> Attribute {
target(AnchorTarget::Blank)
}
pub fn href(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("href", value)
}
pub fn rel(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("rel", value)
}
pub fn src(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("src", value)
}
pub fn alt(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("alt", value)
}
pub fn width(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("width", value)
}
pub fn height(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("height", value)
}
pub fn width_int(value: i32) -> Attribute {
Attribute::new_int("width", value)
}
pub fn height_int(value: i32) -> Attribute {
Attribute::new_int("height", value)
}
pub fn cols(value: i32) -> Attribute {
Attribute::new_int("cols", value)
}
pub fn rows(value: i32) -> Attribute {
Attribute::new_int("rows", value)
}
pub fn type_(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("type", value)
}
pub fn type_text() -> Attribute {
Attribute::new("type", "text")
}
pub fn type_password() -> Attribute {
Attribute::new("type", "password")
}
pub fn type_number() -> Attribute {
Attribute::new("type", "number")
}
pub fn type_tel() -> Attribute {
Attribute::new("type", "tel")
}
pub fn type_file() -> Attribute {
Attribute::new("type", "file")
}
pub fn type_checkbox() -> Attribute {
Attribute::new("type", "checkbox")
}
pub fn type_radio() -> Attribute {
Attribute::new("type", "radio")
}
pub fn type_range() -> Attribute {
Attribute::new("type", "range")
}
pub fn type_email() -> Attribute {
Attribute::new("type", "email")
}
pub fn type_date() -> Attribute {
Attribute::new("type", "date")
}
pub fn type_month() -> Attribute {
Attribute::new("type", "month")
}
pub fn type_hidden() -> Attribute {
Attribute::new("type", "hidden")
}
pub fn type_reset() -> Attribute {
Attribute::new("type", "reset")
}
pub fn type_submit() -> Attribute {
Attribute::new("type", "submit")
}
pub fn integrity(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("integrity", value)
}
pub fn defer() -> Attribute {
Attribute::new_flag("defer")
}
pub fn async_() -> Attribute {
Attribute::new_flag("async")
}
pub fn crossorigin_anonymous() -> Attribute {
Attribute::new("crossorigin", "anonymous")
}
pub fn crossorigin_use_credentials() -> Attribute {
Attribute::new("crossorigin", "use-credentials")
}
pub fn download() -> Attribute {
Attribute::new_flag("download")
}
pub fn download_with_name(name: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("download", name)
}
pub fn charset(charset: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("charset", charset)
}
pub fn charset_utf_8() -> Attribute {
charset("UTF-8")
}
pub fn name(name: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("name", name)
}
pub fn content(content: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("content", content)
}
pub fn action(action: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("action", action)
}
pub fn method_get() -> Attribute {
Attribute::new("method", "get")
}
pub fn method_post() -> Attribute {
Attribute::new("method", "post")
}
pub fn for_(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("for", value)
}
pub fn value(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("value", value)
}
pub fn required() -> Attribute {
Attribute::new_flag("required")
}
pub fn pattern(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("pattern", value)
}
pub fn min(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("min", value)
}
pub fn max(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("max", value)
}
pub fn minlength(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("minlength", value)
}
pub fn maxlength(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("maxlength", value)
}
pub fn multiple() -> Attribute {
Attribute::new_flag("multiple")
}
pub fn placeholder(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("placeholder", value)
}