rsx_usage.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //! A tour of the rsx! macro
  2. //! ------------------------
  3. //!
  4. //! This example serves as an informal quick reference of all the things that the rsx! macro can do.
  5. //!
  6. //! A full in-depth reference guide is available at: https://www.notion.so/rsx-macro-basics-ef6e367dec124f4784e736d91b0d0b19
  7. //!
  8. //! ## Topics
  9. //!
  10. //!
  11. //!
  12. //! ### Elements
  13. //! - Create any element from its tag
  14. //! - Accept compile-safe attributes for each tag
  15. //! - Display documentation for elements
  16. //! - Arguments instead of String
  17. //! - Text
  18. //! - Inline Styles
  19. //!
  20. //! ## General Concepts
  21. //! - Iterators
  22. //! - Keys
  23. //! - Match statements
  24. //! - Conditional Rendering
  25. //!
  26. //! ### Events
  27. //! - Handle events with the "onXYZ" syntax
  28. //! - Closures can capture their environment with the 'a lifetime
  29. //!
  30. //!
  31. //! ### Components
  32. //! - Components can be made by specifying the name
  33. //! - Components can be referenced by path
  34. //! - Components may have optional parameters
  35. //! - Components may have their properties specified by spread syntax
  36. //! - Components may accept child nodes
  37. //! - Components that accept "onXYZ" get those closures bump allocated
  38. //!
  39. //! ### Fragments
  40. //! - Allow fragments using the built-in `Fragment` component
  41. //! - Accept a list of vnodes as children for a Fragment component
  42. //! - Allow keyed fragments in iterators
  43. //! - Allow top-level fragments
  44. //!
  45. fn main() {
  46. dioxus::webview::launch(Example);
  47. }
  48. use baller::Baller;
  49. use dioxus_core::prelude::*;
  50. static Example: FC<()> = |ctx| {
  51. ctx.render(rsx! {
  52. div {
  53. // Elements
  54. // ==============
  55. // Components
  56. // ==============
  57. // Can accept any paths
  58. crate::baller::Baller {}
  59. baller::Baller { }
  60. // Can take properties
  61. Taller { a: "asd" }
  62. // Can take optional properties
  63. Taller { a: "asd" }
  64. // Can pass in props directly
  65. Taller { a: "asd" /* ..{props}*/ }
  66. // Can take children
  67. Taller { a: "asd", div {} }
  68. }
  69. })
  70. };
  71. mod baller {
  72. use super::*;
  73. pub struct BallerProps {}
  74. pub fn Baller(ctx: Context<()>) -> VNode {
  75. todo!()
  76. }
  77. }
  78. #[derive(Debug, PartialEq, Props)]
  79. pub struct TallerProps {
  80. a: &'static str,
  81. }
  82. pub fn Taller(ctx: Context<TallerProps>) -> VNode {
  83. let b = true;
  84. todo!()
  85. }