Skip to content

Instantly share code, notes, and snippets.

@autarch
Created January 10, 2022 05:54
Show Gist options
  • Select an option

  • Save autarch/639ad12d83f5fbec4739cea5482fa2b4 to your computer and use it in GitHub Desktop.

Select an option

Save autarch/639ad12d83f5fbec4739cea5482fa2b4 to your computer and use it in GitHub Desktop.
#[inline_props]
pub(crate) fn MenuItem(
cx: Scope,
text: &'static str,
href: &'static str,
title: &'static str,
) -> Element {
let location = use_route(&cx).current_location();
let is_active = location.path() == *href;
let mut classes: Vec<_> = vec![
// These first two styles are for the hamburger view, where the items
// are stacked vertically. Then we override for a large screen to get
// a side-by-side layout.
"block",
"mt-4",
"lg:inline-block",
"lg:mt-0",
"mr-8",
"p-2",
"rounded",
];
if is_active {
classes.push("text-slate-50 bg-blue-500");
} else {
classes.push("text-slate-100");
}
cx.render(rsx! {
Link {
class: classes.join(" "),
to: href.to_string(),
title: title.to_string(),
"{text}",
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment