1
0

rsx_usage.rs 3.1 KB

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