demo.rs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //! Basic example that renders a simple VNode to the browser.
  2. use dioxus::events::on::MouseEvent;
  3. use dioxus_core as dioxus;
  4. use dioxus_core::prelude::*;
  5. use dioxus_hooks::*;
  6. use dioxus_html as dioxus_elements;
  7. // use wasm_timer;
  8. use std::future::Future;
  9. use std::{pin::Pin, time::Duration};
  10. use dioxus::prelude::*;
  11. use dioxus_html::SvgAttributes;
  12. use dioxus_web::*;
  13. fn main() {
  14. // Setup logging
  15. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  16. console_error_panic_hook::set_once();
  17. // Run the app
  18. dioxus_web::launch(App, |c| c)
  19. }
  20. pub static App: FC<()> = |cx| {
  21. cx.render(rsx!(
  22. div { class: "overflow-hidden"
  23. link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel:"stylesheet" }
  24. Header {}
  25. // Entry {}
  26. Hero {}
  27. Hero {}
  28. Hero {}
  29. Hero {}
  30. Hero {}
  31. }
  32. ))
  33. };
  34. pub static Header: FC<()> = |cx| {
  35. cx.render(rsx! {
  36. div {
  37. header { class: "text-gray-400 bg-gray-900 body-font"
  38. div { class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center"
  39. a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0"
  40. StacksIcon {}
  41. span { class: "ml-3 text-xl" "Hello Dioxus!"}
  42. }
  43. nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center"
  44. a { class: "mr-5 hover:text-white" "First Link"}
  45. a { class: "mr-5 hover:text-white" "Second Link"}
  46. a { class: "mr-5 hover:text-white" "Third Link"}
  47. a { class: "mr-5 hover:text-white" "Fourth Link"}
  48. }
  49. button {
  50. class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0"
  51. "Button"
  52. RightArrowIcon {}
  53. }
  54. }
  55. }
  56. }
  57. })
  58. };
  59. pub static Hero: FC<()> = |cx| {
  60. //
  61. cx.render(rsx! {
  62. section{ class: "text-gray-400 bg-gray-900 body-font"
  63. div { class: "container mx-auto flex px-5 py-24 md:flex-row flex-col items-center"
  64. div { class: "lg:flex-grow md:w-1/2 lg:pr-24 md:pr-16 flex flex-col md:items-start md:text-left mb-16 md:mb-0 items-center text-center"
  65. h1 { class: "title-font sm:text-4xl text-3xl mb-4 font-medium text-white"
  66. br { class: "hidden lg:inline-block" }
  67. "Dioxus Sneak Peek"
  68. }
  69. p {
  70. class: "mb-8 leading-relaxed"
  71. "Dioxus is a new UI framework that makes it easy and simple to write cross-platform apps using web
  72. technologies! It is functional, fast, and portable. Dioxus can run on the web, on the desktop, and
  73. on mobile and embedded platforms."
  74. }
  75. div { class: "flex justify-center"
  76. button {
  77. class: "inline-flex text-white bg-indigo-500 border-0 py-2 px-6 focus:outline-none hover:bg-indigo-600 rounded text-lg"
  78. "Learn more"
  79. }
  80. button {
  81. class: "ml-4 inline-flex text-gray-400 bg-gray-800 border-0 py-2 px-6 focus:outline-none hover:bg-gray-700 hover:text-white rounded text-lg"
  82. "Build an app"
  83. }
  84. }
  85. }
  86. div { class: "lg:max-w-lg lg:w-full md:w-1/2 w-5/6"
  87. img { class: "object-cover object-center rounded" alt: "hero" src: "https://i.imgur.com/oK6BLtw.png"
  88. referrerpolicy:"no-referrer"
  89. }
  90. }
  91. }
  92. }
  93. })
  94. };
  95. pub static Entry: FC<()> = |cx| {
  96. //
  97. cx.render(rsx! {
  98. section{ class: "text-gray-400 bg-gray-900 body-font"
  99. div { class: "container mx-auto flex px-5 py-24 md:flex-row flex-col items-center"
  100. textarea {
  101. }
  102. }
  103. }
  104. })
  105. };
  106. pub static StacksIcon: FC<()> = |cx| {
  107. cx.render(rsx!(
  108. svg {
  109. // xmlns: "http://www.w3.org/2000/svg"
  110. fill: "none"
  111. stroke: "currentColor"
  112. stroke_linecap: "round"
  113. stroke_linejoin: "round"
  114. stroke_width: "2"
  115. // class: "w-10 h-10 text-white p-2 bg-indigo-500 rounded-full"
  116. viewBox: "0 0 24 24"
  117. path { d: "M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"}
  118. }
  119. ))
  120. };
  121. pub static RightArrowIcon: FC<()> = |cx| {
  122. cx.render(rsx!(
  123. svg {
  124. fill: "none"
  125. stroke: "currentColor"
  126. stroke_linecap: "round"
  127. stroke_linejoin: "round"
  128. stroke_width: "2"
  129. // class: "w-4 h-4 ml-1"
  130. viewBox: "0 0 24 24"
  131. path { d: "M5 12h14M12 5l7 7-7 7"}
  132. }
  133. ))
  134. };