mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Add textarea demo to the showcase
This commit is contained in:
parent
2c4d6fb668
commit
53e24310fe
@ -14,3 +14,4 @@ game_of_life = { path = "sub/game_of_life" }
|
||||
large_table = { path = "sub/large_table" }
|
||||
mount_point = { path = "sub/mount_point" }
|
||||
npm_and_rest = { path = "sub/npm_and_rest" }
|
||||
textarea = { path = "sub/textarea" }
|
||||
|
||||
@ -11,6 +11,7 @@ extern crate game_of_life;
|
||||
extern crate large_table;
|
||||
extern crate mount_point;
|
||||
extern crate npm_and_rest;
|
||||
extern crate textarea;
|
||||
|
||||
use yew::prelude::*;
|
||||
use yew::services::console::ConsoleService;
|
||||
@ -30,6 +31,7 @@ use mount_point::Model as MountPoint;
|
||||
use npm_and_rest::Model as NpmAndRest;
|
||||
use npm_and_rest::gravatar::GravatarService;
|
||||
use npm_and_rest::ccxt::CcxtService;
|
||||
use textarea::Model as Textarea;
|
||||
|
||||
struct Context {
|
||||
console: ConsoleService,
|
||||
@ -107,6 +109,7 @@ enum Scene {
|
||||
LargeTable,
|
||||
MountPoint,
|
||||
NpmAndRest,
|
||||
Textarea,
|
||||
}
|
||||
|
||||
enum Msg {
|
||||
@ -145,6 +148,7 @@ impl Renderable<Context, Scene> for Scene {
|
||||
<button onclick=|_| Msg::SwitchTo(Scene::LargeTable),>{ "LargeTable" }</button>
|
||||
<button onclick=|_| Msg::SwitchTo(Scene::MountPoint),>{ "MountPoint" }</button>
|
||||
<button onclick=|_| Msg::SwitchTo(Scene::NpmAndRest),>{ "NpmAndRest" }</button>
|
||||
<button onclick=|_| Msg::SwitchTo(Scene::Textarea),>{ "Textarea" }</button>
|
||||
{ self.view_scene() }
|
||||
}
|
||||
}
|
||||
@ -203,6 +207,11 @@ impl Scene {
|
||||
<NpmAndRest: />
|
||||
}
|
||||
}
|
||||
Scene::Textarea => {
|
||||
html! {
|
||||
<Textarea: />
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,4 +4,4 @@ version = "0.1.0"
|
||||
authors = ["Andrew Straw <strawman@astraw.com>"]
|
||||
|
||||
[dependencies]
|
||||
yew = { path = "../.." }
|
||||
yew = { path = "../../../.." }
|
||||
|
||||
59
examples/showcase/sub/textarea/src/lib.rs
Normal file
59
examples/showcase/sub/textarea/src/lib.rs
Normal file
@ -0,0 +1,59 @@
|
||||
#[macro_use]
|
||||
extern crate yew;
|
||||
|
||||
use yew::prelude::*;
|
||||
|
||||
pub struct Model {
|
||||
value: String,
|
||||
}
|
||||
|
||||
pub enum Msg {
|
||||
GotInput(String),
|
||||
Clicked,
|
||||
}
|
||||
|
||||
impl<CTX> Component<CTX> for Model {
|
||||
type Msg = Msg;
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, _: &mut Env<CTX, Self>) -> Self {
|
||||
Model {
|
||||
value: "".into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Msg, _: &mut Env<CTX, Self>) -> ShouldRender {
|
||||
match msg {
|
||||
Msg::GotInput(new_value) => {
|
||||
self.value = new_value;
|
||||
}
|
||||
Msg::Clicked => {
|
||||
self.value = "blah blah blah".to_string();
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> Renderable<CTX, Model> for Model
|
||||
where
|
||||
CTX: 'static,
|
||||
{
|
||||
fn view(&self) -> Html<CTX, Self> {
|
||||
html! {
|
||||
<div>
|
||||
<div>
|
||||
<textarea rows=5,
|
||||
value=&self.value,
|
||||
oninput=|e: InputData| Msg::GotInput(e.value),
|
||||
placeholder="placeholder",>
|
||||
</textarea>
|
||||
<button onclick=|_| Msg::Clicked,>{ "change value" }</button>
|
||||
</div>
|
||||
<div>
|
||||
{&self.value}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,68 +1,12 @@
|
||||
#[macro_use]
|
||||
extern crate yew;
|
||||
extern crate textarea;
|
||||
|
||||
use yew::prelude::*;
|
||||
|
||||
struct Context {
|
||||
}
|
||||
|
||||
struct Model {
|
||||
value: String,
|
||||
}
|
||||
|
||||
enum Msg {
|
||||
GotInput(String),
|
||||
Clicked,
|
||||
}
|
||||
|
||||
impl Component<Context> for Model {
|
||||
type Msg = Msg;
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, _: &mut Env<Context, Self>) -> Self {
|
||||
Model {
|
||||
value: "".into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Msg, _: &mut Env<Context, Self>) -> ShouldRender {
|
||||
match msg {
|
||||
Msg::GotInput(new_value) => {
|
||||
self.value = new_value;
|
||||
}
|
||||
Msg::Clicked => {
|
||||
self.value = "blah blah blah".to_string();
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable<Context, Model> for Model {
|
||||
fn view(&self) -> Html<Context, Self> {
|
||||
html! {
|
||||
<div>
|
||||
<div>
|
||||
<textarea rows=5,
|
||||
value=&self.value,
|
||||
oninput=|e: InputData| Msg::GotInput(e.value),
|
||||
placeholder="placeholder",>
|
||||
</textarea>
|
||||
<button onclick=|_| Msg::Clicked,>{ "change value" }</button>
|
||||
</div>
|
||||
<div>
|
||||
{&self.value}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
use textarea::Model;
|
||||
|
||||
fn main() {
|
||||
yew::initialize();
|
||||
let context = Context {
|
||||
};
|
||||
let app: App<_, Model> = App::new(context);
|
||||
let app: App<_, Model> = App::new(());
|
||||
app.mount_to_body();
|
||||
yew::run_loop();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user