tofile.rs 5.1 KB

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