// Label - Form label component
pub struct Label {
text: string,
for_id: string,
required: bool,
class: string,
}
impl Label {
pub fn new(text: string) -> Label {
Label {
text,
for_id: String::new(),
required: false,
class: String::new(),
}
}
pub fn for_id(for_id: string) -> Label {
self.for_id = for_id
self
}
pub fn required(required: bool) -> Label {
self.required = required
self
}
pub fn class(class: string) -> Label {
self.class = class
self
}
pub fn render() -> string {
let mut html = String::new()
html.push_str("<label class=\"wj-label ")
html.push_str(self.class.as_str())
html.push_str("\" style=\"font-weight: 500; font-size: 14px; color: #374151; display: block; margin-bottom: 4px;\"")
if !self.for_id.is_empty() {
html.push_str(" for=\"")
html.push_str(self.for_id.as_str())
html.push('"')
}
html.push('>')
html.push_str(self.text.as_str())
if self.required {
html.push_str("<span style=\"color: #ef4444; margin-left: 4px;\">*</span>")
}
html.push_str("</label>")
html
}
}