use std::rc::Rc;
use crabshell_reactive::Signal;
use crate::cx::Cx;
use crate::input::Handler;
use crate::prop::IntoProp;
use crate::style::Style;
use crate::text_input::InputProps;
use crate::widgets::{Common, Element, ElementKind, Widget, visibility_methods};
pub struct TextArea {
input: InputProps,
common: Common,
}
impl TextArea {
pub fn new(text: Signal<String>) -> TextArea {
TextArea {
input: InputProps {
text,
placeholder: None,
password: None,
focus: None,
on_accept: None,
multiline: true,
wrap: None,
},
common: Common::default(),
}
}
pub fn placeholder(mut self, text: impl IntoProp<String>) -> TextArea {
self.input.placeholder = Some(text.into_prop());
self
}
pub fn focus(mut self, focus: impl IntoProp<bool>) -> TextArea {
self.input.focus = Some(focus.into_prop());
self
}
pub fn wrap(mut self, wrap: impl IntoProp<bool>) -> TextArea {
self.input.wrap = Some(wrap.into_prop());
self
}
pub fn on_accept(mut self, handler: impl Fn(&Cx, &str) + 'static) -> TextArea {
self.input.on_accept = Some(Rc::new(Handler::new(handler)));
self
}
pub fn style(mut self, style: impl IntoProp<Style>) -> TextArea {
self.common.style = Some(style.into_prop());
self
}
visibility_methods!();
}
impl Widget for TextArea {
fn into_element(self: Box<Self>) -> Element {
Element {
name: "TextArea",
common: self.common,
kind: ElementKind::Input(Box::new(self.input)),
children: Vec::new(),
}
}
}