1
0

input.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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<()> = |ctx| {
  11. let (val, set_val) = use_state(&ctx, || "asd".to_string());
  12. ctx.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| {
  26. log::debug!("Value is {:#?}", evet);
  27. set_val(evet.value);
  28. }
  29. }
  30. p { "Val is: {val}" }
  31. }
  32. }
  33. }
  34. })
  35. };
  36. static Example: FC<()> = |ctx| {
  37. ctx.render(rsx! {
  38. 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"
  39. div { class: "container py-5 max-w-md mx-auto"
  40. h1 { class: "text-gray-200 text-center font-extrabold -mt-3 text-3xl",
  41. "Text Input Example"
  42. }
  43. UserInput {}
  44. }
  45. }
  46. })
  47. };
  48. static UserInput: FC<()> = |ctx| {
  49. let (val, set_val) = use_state(&ctx, || "asd".to_string());
  50. rsx!{ in ctx,
  51. div { class: "mb-4"
  52. input { class: "shadow appearance-none rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
  53. placeholder: "Username"
  54. id: "username"
  55. type: "text"
  56. oninput: move |evet| {
  57. log::debug!("Value is {:#?}", evet);
  58. set_val(evet.value);
  59. }
  60. }
  61. p { "Val is: {val}" }
  62. }
  63. }
  64. };