input.rs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. use dioxus_core as dioxus;
  2. use dioxus_core::prelude::*;
  3. use dioxus_web::WebsysRenderer;
  4. fn main() {
  5. // wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  6. console_error_panic_hook::set_once();
  7. log::info!("hello world");
  8. wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
  9. }
  10. static App: FC<()> = |cx| {
  11. let (val, set_val) = use_state(&cx, || "asd".to_string());
  12. cx.render(rsx! {
  13. div { class: "max-w-lg max-w-xs bg-blue-800 shadow-2xl rounded-lg mx-auto text-center py-12 mt-4 rounded-xl"
  14. div { class: "container py-5 max-w-md mx-auto"
  15. h1 { class: "text-gray-200 text-center font-extrabold -mt-3 text-3xl",
  16. "Text Input Example"
  17. }
  18. div { class: "mb-4"
  19. input {
  20. placeholder: "Username"
  21. class: "shadow appearance-none rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
  22. id: "username"
  23. type: "text"
  24. value: "{val}"
  25. oninput: move |evet| set_val(evet.value())
  26. }
  27. p { "Val is: {val}" }
  28. }
  29. }
  30. }
  31. })
  32. };
  33. static Example: FC<()> = |cx| {
  34. cx.render(rsx! {
  35. div { class: "max-w-lg max-w-xs bg-blue-800 shadow-2xl rounded-lg mx-auto text-center py-12 mt-4 rounded-xl"
  36. div { class: "container py-5 max-w-md mx-auto"
  37. h1 { class: "text-gray-200 text-center font-extrabold -mt-3 text-3xl",
  38. "Text Input Example"
  39. }
  40. UserInput {}
  41. }
  42. }
  43. })
  44. };
  45. static UserInput: FC<()> = |cx| {
  46. let (val, set_val) = use_state(&cx, || "asd".to_string());
  47. rsx! { in cx,
  48. div { class: "mb-4"
  49. input { class: "shadow appearance-none rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
  50. placeholder: "Username"
  51. id: "username"
  52. type: "text"
  53. oninput: move |evet| set_val(evet.value())
  54. }
  55. p { "Val is: {val}" }
  56. }
  57. }
  58. };