1
0

input.rs 2.3 KB

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