mirror of
https://github.com/yewprint/yewprint
synced 2024-11-22 03:23:03 +00:00
Added text component (#7)
This commit is contained in:
parent
768cb68384
commit
bd93ee3048
3 changed files with 95 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
pub mod controls;
|
||||
pub mod text;
|
||||
|
|
93
src/forms/text.rs
Normal file
93
src/forms/text.rs
Normal 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>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue