/ web / src / content / docs.rs
docs.rs
 1  use dioxus::prelude::*;
 2  use lucide_dioxus::{Check, Copy};
 3  use ui::components::button::{Button, ButtonSize, ButtonVariant};
 4  use wasm_bindgen::JsCast;
 5  
 6  // This module does not exist in the git repo - it is auto-generated at build time.
 7  pub mod router;
 8  
 9  #[component]
10  fn SandBoxFrame(url: String) -> Element {
11      rsx! {
12          iframe {
13              class: "border rounded-md border-border shadow-sm",
14              width: "800",
15              height: "450",
16              src: "{url}?embed=1",
17              "allowfullscreen": true,
18          }
19      }
20  }
21  
22  #[component]
23  fn DemoFrame(children: Element) -> Element {
24      rsx! {
25          div {
26              class: "bg-background border border-border rounded-lg shadow p-6 my-6 overflow-visible text-foreground",
27              {children}
28          }
29      }
30  }
31  
32  #[component]
33  fn CodeBlock(contents: String, #[props(default)] light_contents: Option<String>, name: Option<String>) -> Element {
34      let mut copied = use_signal(|| false);
35      let code_id = use_hook(|| format!("code-{:x}", {
36          let mut hash: u64 = 5381;
37          for byte in contents.bytes() { hash = hash.wrapping_mul(33).wrapping_add(byte as u64); }
38          hash
39      }));
40      let code_id_for_click = code_id.clone();
41  
42      rsx! {
43          div {
44              class: "rounded-lg border border-border shadow-sm mb-6 overflow-hidden",
45              div {
46                  class: "bg-card flex justify-between items-center p-2 text-xs font-mono rounded-t-lg",
47                  div {
48                      class: "text-card-foreground",
49                      if let Some(path) = name {
50                          "src/{path}"
51                      }
52                  }
53                  Button {
54                      variant: ButtonVariant::Ghost,
55                      size: ButtonSize::Small,
56                      on_click: move |_| {
57                          let id = code_id_for_click.clone();
58                          if let Some(el) = web_sys::window()
59                              .and_then(|w| w.document())
60                              .and_then(|d| d.get_element_by_id(&id))
61                              .and_then(|el| el.dyn_into::<web_sys::HtmlElement>().ok())
62                          {
63                              let text = el.inner_text();
64                              if let Some(window) = web_sys::window() {
65                                  let _ = window.navigator().clipboard().write_text(&text);
66                                  copied.set(true);
67                              }
68                          }
69                      },
70                      if copied() {
71                          div { class: "flex gap-1 text-green-500 items-center",
72                              Check { class: "w-4 h-4" }
73                              "Copied!"
74                          }
75                      }
76                      else {
77                          Copy { class: "w-4 h-4" }
78                      }
79                  }
80              }
81              div { id: "{code_id}", class: "codeblock text-xs bg-[#0d0d0d] p-4 overflow-auto", dangerous_inner_html: contents }
82          }
83      }
84  }