Skip to content

Rework Guide #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8093f71
Remove unneeded lifetimes
rMazeiks Jun 30, 2022
153a947
Merge branch 'master' of https://github.com/DioxusLabs/dioxus
rMazeiks Jul 1, 2022
a120108
Move getting started to Guide
rMazeiks Jul 1, 2022
04e6a5a
Clean up summary and getting started
rMazeiks Jul 1, 2022
4b15a5b
Shorten intro by moving stuff to individual platform docs
rMazeiks Jul 1, 2022
38c57a2
Make intro even shorter, summarize features
rMazeiks Jul 1, 2022
9a43d73
Further cleanup; move development-related docs to separate section
rMazeiks Jul 1, 2022
8a566d1
Rename directory; simplify intro
rMazeiks Jul 1, 2022
fabb606
Make `guide` a crate. Turn code samples into examples so that we can …
rMazeiks Jul 1, 2022
559991c
Rewrite "Describing the UI":
rMazeiks Jul 1, 2022
cd063e4
Move some "special attribute" samples to the `examples` directory
rMazeiks Jul 1, 2022
c50f6e8
Simplify introduction to components
rMazeiks Jul 1, 2022
77ba952
Simplify introduction to component props
rMazeiks Jul 1, 2022
ba91d55
Document Prop features; add code samples
rMazeiks Jul 1, 2022
7e782be
Simplify component children docs
rMazeiks Jul 1, 2022
a82b10a
Remove outdated doc draft
rMazeiks Jul 1, 2022
d94c76f
Interactivity: better introduction to events
rMazeiks Jul 2, 2022
5159d6b
Hooks: better introduction
rMazeiks Jul 2, 2022
429fea2
Remove outdated doc
rMazeiks Jul 2, 2022
eefcd73
Introducs use_ref
rMazeiks Jul 2, 2022
0667b3e
Simplify User Input chapter
rMazeiks Jul 2, 2022
c37c580
Document event handler props
rMazeiks Jul 2, 2022
0529658
Meme editor example
rMazeiks Jul 2, 2022
b6c97f1
Meme editor walkthrough
rMazeiks Jul 2, 2022
b63193b
Add dark mode example
rMazeiks Jul 2, 2022
8a36ac7
Guide for context; dark mode example
rMazeiks Jul 2, 2022
ac5c0d2
Delete outdated/rewritten docs
rMazeiks Jul 2, 2022
0e87b2d
Guide: custom hooks
rMazeiks Jul 2, 2022
a17e096
Guide: conditional rendering
rMazeiks Jul 3, 2022
13f725a
Guide: rendering lists
rMazeiks Jul 3, 2022
72ddd3e
Guide: rendering lists + keys
rMazeiks Jul 3, 2022
c6afad5
Delete re-written docs
rMazeiks Jul 3, 2022
84e451d
Move async docs
rMazeiks Jul 3, 2022
e01752c
Remove unused images
rMazeiks Jul 3, 2022
d6ab0d8
Restructure; temporarily remove some things from the guide
rMazeiks Jul 3, 2022
6210755
Examples: fix errors & most warnings
rMazeiks Jul 3, 2022
d46719e
Remove some unneeded guides (covered elsewhere)
rMazeiks Jul 3, 2022
c294289
Create chapter "publishing"
rMazeiks Jul 3, 2022
48d000f
Antipatterns in guide
rMazeiks Jul 4, 2022
50638bc
Document fragments
rMazeiks Jul 4, 2022
3211f0d
Remove core_reference examples which have been covered in the guide
rMazeiks Jul 4, 2022
a607a38
Document some best practices
rMazeiks Jul 4, 2022
6d5480d
Restructure: merge `components` and `describing ui`
rMazeiks Jul 4, 2022
e325c3c
Merge branch 'master' of https://github.com/DioxusLabs/dioxus into re…
rMazeiks Jul 4, 2022
68595ea
Add the "publishing" section
rMazeiks Jul 4, 2022
5509364
Move "Reusable Libraries" info to Best Practices
rMazeiks Jul 4, 2022
7b6470f
Add use_future example
rMazeiks Jul 4, 2022
c65fdf2
Only use `web_sys::console` if hot-reload is enabled
rMazeiks Jul 4, 2022
f8f527b
Simplify use_future example
rMazeiks Jul 4, 2022
e6657b4
Shorten `use_future` guide
rMazeiks Jul 4, 2022
e593e1a
Update guide on `cx.spawn`
rMazeiks Jul 4, 2022
370a5c9
Add removed content to __unused. Possibly this can be useful to inclu…
rMazeiks Jul 4, 2022
195d7e8
Document ability to interpolate arbitrary expressions
rMazeiks Jul 4, 2022
4507040
Merge branch 'master' of https://github.com/DioxusLabs/dioxus into re…
rMazeiks Jul 4, 2022
6a0879b
Move remaining infor from Reference to guide
rMazeiks Jul 4, 2022
19e9c3b
Delete reference book
rMazeiks Jul 4, 2022
7ce7e3e
Proofread guide
rMazeiks Jul 5, 2022
4837040
Proofread async guides
rMazeiks Jul 5, 2022
bd9faa3
JS handlers not supported yet?
rMazeiks Jul 5, 2022
956fbe9
Make examples compile (fix typos)
rMazeiks Jul 5, 2022
b0ef5d2
Silence warning
rMazeiks Jul 5, 2022
650cfa4
Update description
rMazeiks Jul 5, 2022
2bb66dd
Merge branch 'master' of https://github.com/DioxusLabs/dioxus into re…
rMazeiks Jul 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ members = [
"packages/native-core",
"packages/native-core-macro",
"packages/rsx-prelude",
"docs/guide",
]

[dev-dependencies]
Expand Down
12 changes: 12 additions & 0 deletions docs/guide/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "dioxus-guide"
version = "0.0.1"
edition = "2021"
description = "Dioxus guide, including testable examples"
license = "MIT/Apache-2.0"

[dev-dependencies]
dioxus = { path = "../..", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] }
serde = { version = "1.0.138", features=["derive"] }
reqwest = { version = "0.11.11", features = ["json"] }
tokio = { version = "1.19.2" , features=[]}
2 changes: 1 addition & 1 deletion docs/guide/book.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[book]
title = "Dioxus Documentation"
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
description = "Get started with Dioxus, a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust"
authors = ["Jonathan Kelley"]
language = "en"

Expand Down
1 change: 1 addition & 0 deletions docs/guide/examples/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some of these examples (e.g. web) cannot be run. The code samples are here mostly so that we can easily check that they compile using `cargo test`.
71 changes: 71 additions & 0 deletions docs/guide/examples/anti_patterns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#![allow(non_snake_case, unused)]

//! This example shows what *not* to do

use std::collections::HashMap;

use dioxus::prelude::*;

fn main() {}

fn AntipatternNestedFragments(cx: Scope<()>) -> Element {
// ANCHOR: nested_fragments
// ❌ Don't unnecessarily nest fragments
let _ = cx.render(rsx!(
Fragment {
Fragment {
Fragment {
Fragment {
Fragment {
div { "Finally have a real node!" }
}
}
}
}
}
));

// ✅ Render shallow structures
cx.render(rsx!(
div { "Finally have a real node!" }
))
// ANCHOR_END: nested_fragments
}

#[derive(PartialEq, Props)]
struct NoKeysProps {
data: HashMap<u32, String>,
}

fn AntipatternNoKeys(cx: Scope<NoKeysProps>) -> Element {
// ANCHOR: iter_keys
let data: &HashMap<_, _> = &cx.props.data;

// ❌ No keys
cx.render(rsx! {
ul {
data.values().map(|value| rsx!(
li { "List item: {value}" }
))
}
});

// ❌ Using index as keys
cx.render(rsx! {
ul {
cx.props.data.values().enumerate().map(|(index, value)| rsx!(
li { key: "{index}", "List item: {value}" }
))
}
});

// ✅ Using unique IDs as keys:
cx.render(rsx! {
ul {
cx.props.data.iter().map(|(key, value)| rsx!(
li { key: "{key}", "List item: {value}" }
))
}
})
// ANCHOR_END: iter_keys
}
17 changes: 17 additions & 0 deletions docs/guide/examples/boolean_attribute.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

fn App(cx: Scope) -> Element {
// ANCHOR: boolean_attribute
cx.render(rsx! {
div {
hidden: "false",
"hello"
}
})
// ANCHOR_END: boolean_attribute
}
27 changes: 27 additions & 0 deletions docs/guide/examples/component_borrowed_props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

// ANCHOR: App
fn App(cx: Scope) -> Element {
let hello = "Hello Dioxus!";

cx.render(rsx!(TitleCard { title: hello }))
}
// ANCHOR_END: App

// ANCHOR: TitleCard
#[derive(Props)]
struct TitleCardProps<'a> {
title: &'a str,
}

fn TitleCard<'a>(cx: Scope<'a, TitleCardProps<'a>>) -> Element {
cx.render(rsx! {
h1 { "{cx.props.title}" }
})
}
// ANCHOR_END: TitleCard
36 changes: 36 additions & 0 deletions docs/guide/examples/component_children.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ANCHOR: all
#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

fn App(cx: Scope) -> Element {
// ANCHOR: Clickable_usage
cx.render(rsx! {
Clickable {
href: "https://www.youtube.com/watch?v=C-M2hs3sXGo",
"How to " i {"not"} " be seen"
}
})
// ANCHOR_END: Clickable_usage
}

// ANCHOR: Clickable
#[derive(Props)]
struct ClickableProps<'a> {
href: &'a str,
children: Element<'a>,
}

fn Clickable<'a>(cx: Scope<'a, ClickableProps<'a>>) -> Element {
cx.render(rsx!(
a {
href: "{cx.props.href}",
class: "fancy-button",
&cx.props.children
}
))
}
// ANCHOR_END: Clickable
37 changes: 37 additions & 0 deletions docs/guide/examples/component_children_inspect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ANCHOR: all
#![allow(non_snake_case, unused)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

fn App(cx: Scope) -> Element {
// ANCHOR: Clickable_usage
cx.render(rsx! {
Clickable {
href: "https://www.youtube.com/watch?v=C-M2hs3sXGo",
"How to " i {"not"} " be seen"
}
})
// ANCHOR_END: Clickable_usage
}

#[derive(Props)]
struct ClickableProps<'a> {
href: &'a str,
children: Element<'a>,
}

// ANCHOR: Clickable
fn Clickable<'a>(cx: Scope<'a, ClickableProps<'a>>) -> Element {
match cx.props.children {
Some(VNode::Text(_)) => {
todo!("render some stuff")
}
_ => {
todo!("render some other stuff")
}
}
}
// ANCHOR_END: Clickable
36 changes: 36 additions & 0 deletions docs/guide/examples/component_element_props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ANCHOR: all
#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

fn App(cx: Scope) -> Element {
// ANCHOR: Clickable_usage
cx.render(rsx! {
Clickable {
href: "https://www.youtube.com/watch?v=C-M2hs3sXGo",
body: cx.render(rsx!("How to " i {"not"} " be seen")),
}
})
// ANCHOR_END: Clickable_usage
}

// ANCHOR: Clickable
#[derive(Props)]
struct ClickableProps<'a> {
href: &'a str,
body: Element<'a>,
}

fn Clickable<'a>(cx: Scope<'a, ClickableProps<'a>>) -> Element {
cx.render(rsx!(
a {
href: "{cx.props.href}",
class: "fancy-button",
&cx.props.body
}
))
}
// ANCHOR_END: Clickable
34 changes: 34 additions & 0 deletions docs/guide/examples/component_owned_props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
dioxus::desktop::launch(App);
}

// ANCHOR: App
fn App(cx: Scope) -> Element {
cx.render(rsx! {
Likes {
score: 42,
},
})
}
// ANCHOR_END: App

// ANCHOR: Likes
// Remember: Owned props must implement `PartialEq`!
#[derive(PartialEq, Props)]
struct LikesProps {
score: i32,
}

fn Likes(cx: Scope<LikesProps>) -> Element {
cx.render(rsx! {
div {
"This post has ",
b { "{cx.props.score}" },
" likes"
}
})
}
// ANCHOR_END: Likes
Loading