rsx_usage.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. use dioxus_core::prelude::*;
  2. fn main() {}
  3. // include as much as you might accept
  4. struct ButtonProps<'a> {
  5. onhover: Option<&'a dyn Fn()>,
  6. // // A list of any attrs
  7. // attrs: AttrList<'a>,
  8. }
  9. fn CustomButton(ctx: Context, props: ButtonProps) -> DomTree {
  10. let onfocus = move |evt: ()| log::debug!("Focused");
  11. ctx.render(rsx! {
  12. button {
  13. // ..props.attrs,
  14. class: "abc123",
  15. style: { a: 2, b: 3, c: 4 },
  16. onclick: move |evt| {
  17. log::info("hello world");
  18. },
  19. onfocus,
  20. onhover: props.onhover,
  21. Custom1 { a: 123 }
  22. Custom2 { a: 456, "abc", h1 {"1"}, h2 {"2"} }
  23. Custom3 { a: "sometext goes here" }
  24. Custom4 { onclick: |evt| log::info("click") }
  25. }
  26. })
  27. }
  28. // h1 {
  29. // tag: "type", abc: 123, class: "big small wide short",
  30. // "title1"
  31. // "title1"
  32. // "title1"
  33. // "title"
  34. // }
  35. // h1 ("title") {
  36. // tag: "type",
  37. // abc: 123,
  38. // class: "big small wide short",
  39. // }
  40. // // <button
  41. // // class="inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
  42. // // onclick={move |_| set_name("jill")}
  43. // // onclick={move |_| set_name("jill")}
  44. // // >
  45. // // "Jill!"
  46. // // </button>
  47. // button { "Jill!",
  48. // class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
  49. // onclick: move |_| set_name("jill"),
  50. // onclick: move |_| set_name("jill"),
  51. // }
  52. // button {
  53. // class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
  54. // onclick: move |_| set_name("jill"),
  55. // onclick: move |_| set_name("jill"),
  56. // // this is valid
  57. // "Jill!",
  58. // // this is also valid
  59. // {"Jill!"}
  60. // }
  61. // h1 { "Text", class: "inline-block py-4 px-8 mr-6 leading-none" }
  62. // // <h1 class="inline-block py-4 px-8 mr-6 leading-none">
  63. // // "Text"
  64. // // </h1>
  65. // h1 {
  66. // div {
  67. // h1 {}
  68. // h2 {}
  69. // Brick {}
  70. // p {}
  71. // p {
  72. // tag: "type",
  73. // abc: 123,
  74. // enabled: true,
  75. // class: "big small wide short",
  76. // a { "abcder" },
  77. // h2 { "whatsup", class: "abc-123" },
  78. // CustomComponent { a: 123, b: 456, key: "1" },
  79. // }
  80. // div { class: "big small wide short",
  81. // div {},
  82. // div {},
  83. // div {},
  84. // div {},
  85. // }
  86. // }
  87. // }
  88. // h2 {}
  89. // h3 {}
  90. // "abcd123"