Added text component (#7)

This commit is contained in:
Valentine-mario 2020-09-23 17:04:27 +01:00 committed by GitHub
parent 768cb68384
commit bd93ee3048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 1 deletions

View file

@ -86,7 +86,7 @@ Roadmap
- [ ] [Spinner](https://blueprintjs.com/docs/#core/components/spinner)
- [ ] [Tabs](https://blueprintjs.com/docs/#core/components/tabs)
- [ ] [Tag](https://blueprintjs.com/docs/#core/components/tag)
- [ ] [Text](https://blueprintjs.com/docs/#core/components/text)
- [x] [Text](https://blueprintjs.com/docs/#core/components/text)
- [x] [Tree](https://blueprintjs.com/docs/#core/components/tree)
- depends on: Collapse, Icon
- [ ] [FormGroup](https://blueprintjs.com/docs/#core/components/form-group)

View file

@ -1 +1,2 @@
pub mod controls;
pub mod text;

93
src/forms/text.rs Normal file
View file

@ -0,0 +1,93 @@
use yew::prelude::*;
pub struct Text {
props: Props,
}
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
pub value: String,
#[prop_or_default]
pub oninput:Callback<InputData>
}
impl Component for Text {
type Message = ();
type Properties = Props;
fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Text { props }
}
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
true
}
fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props != props {
self.props = props;
true
} else {
false
}
}
fn view(&self) -> Html {
html! {
<label class="bp3-text">
<textarea
placeholder="enter text"
oninput=self.props.oninput.clone()
value=&self.props.value
/>
</label>
}
}
}
#[cfg(feature = "dev")]
pub mod doc {
use super::*;
pub struct TextDoc {
props: Props,
}
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
pub value: String,
pub oninput:Callback<InputData>
}
impl Component for TextDoc {
type Message = ();
type Properties = Props;
fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
TextDoc { props }
}
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
true
}
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
true
}
fn view(&self) -> Html {
html! {
<div>
<Text
oninput=self.props.oninput.clone()
value=self.props.value
label="Dark theme"
/>
</div>
}
}
}
}