use super::traits::Renderable
pub struct ChatInput {
placeholder: string,
value: string,
disabled: bool,
multiline: bool,
rows: i32,
}
impl ChatInput {
pub fn new() -> ChatInput {
ChatInput {
placeholder: String::from("Type a message..."),
value: String::from(""),
disabled: false,
multiline: true,
rows: 3,
}
}
pub fn placeholder(self, placeholder: string) -> ChatInput {
self.placeholder = placeholder
self
}
pub fn value(self, value: string) -> ChatInput {
self.value = value
self
}
pub fn disabled(self, disabled: bool) -> ChatInput {
self.disabled = disabled
self
}
pub fn multiline(self, multiline: bool) -> ChatInput {
self.multiline = multiline
self
}
pub fn rows(self, rows: i32) -> ChatInput {
self.rows = rows
self
}
}
impl Renderable for ChatInput {
pub fn render(self) -> string {
let disabled_attr = if self.disabled { " disabled" } else { "" }
let input_html = if self.multiline {
format!(
"<textarea class='wj-chat-input-field' placeholder='{}' rows='{}'{}>{}</textarea>",
self.placeholder,
self.rows,
disabled_attr,
self.value
)
} else {
format!(
"<input type='text' class='wj-chat-input-field' placeholder='{}' value='{}'{}/>",
self.placeholder,
self.value,
disabled_attr
)
}
format!(
"<div class='wj-chat-input'>
{}
<button class='wj-chat-send-button'{}>
<span>➤</span>
</button>
</div>",
input_html,
disabled_attr
)
}
}