cut out a number of changes from the hr PR (#2580)

This commit is contained in:
Jonathan Kelley 2024-07-02 17:09:57 -07:00 committed by GitHub
parent 9bf46968cd
commit b30810e486
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 89 additions and 18 deletions

View file

@ -28,7 +28,7 @@ fn app() -> Element {
link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet" } link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet" }
header { header {
i { class: "material-icons icon-menu", "menu" } i { class: "material-icons icon-menu", "menu" }
h1 { "Files: ", {files.read().current()} } h1 { "Files: " {files.read().current()} }
span { } span { }
i { class: "material-icons", onclick: move |_| files.write().go_up(), "logout" } i { class: "material-icons", onclick: move |_| files.write().go_up(), "logout" }
} }

View file

@ -54,7 +54,7 @@ fn app() -> Element {
id: "directory-upload", id: "directory-upload",
checked: enable_directory_upload, checked: enable_directory_upload,
oninput: move |evt| enable_directory_upload.set(evt.checked()), oninput: move |evt| enable_directory_upload.set(evt.checked()),
}, }
} }
div { div {

View file

@ -41,8 +41,8 @@ fn Decrement() -> Element {
#[component] #[component]
fn Display() -> Element { fn Display() -> Element {
rsx! { rsx! {
p { "Count: ", "{COUNT}" } p { "Count: {COUNT}" }
p { "Doubled: ", "{DOUBLED_COUNT}" } p { "Doubled: {DOUBLED_COUNT}" }
} }
} }

View file

@ -20,7 +20,7 @@ fn app() -> Element {
// Add some cute animations if the radio is playing! // Add some cute animations if the radio is playing!
div { class: if state.read().is_playing { "bounce" }, div { class: if state.read().is_playing { "bounce" },
"The radio is... ", {state.read().is_playing()}, "!" "The radio is... " {state.read().is_playing()} "!"
} }
button { id: "play", onclick: move |_| state.write().reduce(PlayerAction::Pause), "Pause" } button { id: "play", onclick: move |_| state.write().reduce(PlayerAction::Pause), "Pause" }

View file

@ -79,7 +79,7 @@ fn app() -> Element {
} }
div { div {
// pass simple rust expressions in // pass simple rust expressions in
class: lazy_fmt, class: "{lazy_fmt}",
id: format_args!("attributes can be passed lazily with std::fmt::Arguments"), id: format_args!("attributes can be passed lazily with std::fmt::Arguments"),
class: "asd", class: "asd",
class: "{asd}", class: "{asd}",
@ -97,7 +97,7 @@ fn app() -> Element {
{rsx!(p { "More templating!" })}, {rsx!(p { "More templating!" })},
// Iterators // Iterators
{(0..10).map(|i| rsx!(li { "{i}" }))}, {(0..10).map(|i| rsx!(li { "{i}" }))}
// Iterators within expressions // Iterators within expressions
{ {
@ -117,7 +117,7 @@ fn app() -> Element {
// Conditional rendering // Conditional rendering
// Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals. // Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals.
// You can convert a bool condition to rsx! with .then and .or // You can convert a bool condition to rsx! with .then and .or
{true.then(|| rsx!(div {}))}, {true.then(|| rsx!(div {}))}
// Alternatively, you can use the "if" syntax - but both branches must be resolve to Element // Alternatively, you can use the "if" syntax - but both branches must be resolve to Element
if false { if false {
@ -135,7 +135,7 @@ fn app() -> Element {
}} }}
// returning "None" without a diverging branch is a bit noisy... but rare in practice // returning "None" without a diverging branch is a bit noisy... but rare in practice
{None as Option<()>}, {None as Option<()>}
// can also just use empty fragments // can also just use empty fragments
Fragment {} Fragment {}
@ -176,8 +176,8 @@ fn app() -> Element {
// Spreading can also be overridden manually // Spreading can also be overridden manually
Taller { Taller {
..TallerProps { a: "ballin!", children: VNode::empty() }, a: "not ballin!",
a: "not ballin!" ..TallerProps { a: "ballin!", children: VNode::empty() }
} }
// Can take children too! // Can take children too!

View file

@ -12,17 +12,17 @@ fn app() -> Element {
rsx!( rsx!(
div { div {
// Use Map directly to lazily pull elements // Use Map directly to lazily pull elements
{(0..10).map(|f| rsx! { "{f}" })}, {(0..10).map(|f| rsx! { "{f}" })}
// Collect into an intermediate collection if necessary, and call into_iter // Collect into an intermediate collection if necessary, and call into_iter
{["a", "b", "c", "d", "e", "f"] {["a", "b", "c", "d", "e", "f"]
.into_iter() .into_iter()
.map(|f| rsx! { "{f}" }) .map(|f| rsx! { "{f}" })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter()}, .into_iter()}
// Use optionals // Use optionals
{Some(rsx! { "Some" })}, {Some(rsx! { "Some" })}
// use a for loop where the body itself is RSX // use a for loop where the body itself is RSX
for name in 0..10 { for name in 0..10 {

View file

@ -225,7 +225,7 @@ fn ListFooter(
match active_todo_count() { match active_todo_count() {
1 => "item", 1 => "item",
_ => "items", _ => "items",
}, }
" left" " left"
} }
} }

View file

@ -4,8 +4,8 @@ macro_rules! twoway {
// doc attrs // doc attrs
$( #[doc = $doc:expr] )* $( #[doc = $doc:expr] )*
$name:ident, $name:ident
)* ),*
) => { ) => {
$( $(
$( #[doc = $doc] )* $( #[doc = $doc] )*
@ -51,4 +51,6 @@ twoway![
letsome, letsome,
fat_exprs, fat_exprs,
nested, nested,
staged,
misplaced
]; ];

View file

@ -38,5 +38,9 @@ rsx! {
// todo some work in here // todo some work in here
class: "hello world" class: "hello world"
} }
div {
div {}
}
} }
} }

View file

@ -12,7 +12,11 @@ pub(crate) fn Nav() -> Element {
let mut sidebar = SHOW_SIDEBAR.write(); let mut sidebar = SHOW_SIDEBAR.write();
*sidebar = !*sidebar; *sidebar = !*sidebar;
}, },
MaterialIcon { name: "menu", size: 24, color: MaterialIconColor::Dark } MaterialIcon {
name: "menu",
size: 24,
color: MaterialIconColor::Dark
}
} }
div { class: "flex z-50 md:flex-1 px-2", LinkList {} } div { class: "flex z-50 md:flex-1 px-2", LinkList {} }

View file

@ -0,0 +1,35 @@
pub(crate) fn Nav() -> Element {
rsx! {
SearchModal {}
header {
class: "sticky top-0 z-30 bg-white dark:text-gray-200 dark:bg-ideblack border-b dark:border-stone-700 h-16 bg-opacity-80 backdrop-blur-sm",
class: if HIGHLIGHT_NAV_LAYOUT() { "border border-orange-600 rounded-md" },
div { class: "lg:py-2 px-2 max-w-screen-2xl mx-auto flex items-center justify-between text-sm leading-6 h-16",
button {
class: "bg-gray-100 rounded-lg p-2 mr-4 lg:hidden my-3 h-10 flex items-center text-lg z-[100]",
class: if !SHOW_DOCS_NAV() { "hidden" },
onclick: move |_| {
let mut sidebar = SHOW_SIDEBAR.write();
*sidebar = !*sidebar;
},
MaterialIcon {
name: "menu",
size: 24,
color: MaterialIconColor::Dark
}
}
div { class: "flex z-50 md:flex-1 px-2", LinkList {} }
}
}
}
}
#[component]
fn SidebarSection(chapter: &'static SummaryItem<BookRoute>) -> Element {
let link = chapter.maybe_link()?;
let sections = link.nested_items.iter().map(|chapter| {
rsx! {
SidebarChapter { chapter }
}
});
}

View file

@ -0,0 +1,26 @@
rsx! {
div {}
div { "hi" }
div { class: "helo", "hi" }
div { class: "helo", glass: "123", "hi" }
div { {some_expr} }
div {
{
POSTS.iter().enumerate().map(|(id, post)| rsx! {
BlogPostItem { post, id }
})
}
}
div { class: "123123123123123123123123123123123123",
{some_really_long_expr_some_really_long_expr_some_really_long_expr_some_really_long_expr_}
}
div { class: "-my-8 divide-y-2 divide-gray-100",
{POSTS.iter().enumerate().map(|(id, post)| rsx! { BlogPostItem { post: post, id: id } })}
}
}