Breadcrumb
Displays the path to the current resource using a hierarchy of links.
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage,
BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="#/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
// TODO
// <DropdownMenu>
// <DropdownMenuTrigger class="flex items-center gap-1">
// <BreadcrumbEllipsis class="h-4 w-4" />
// <span class="sr-only">{"Toggle menu"}</span>
// </DropdownMenuTrigger>
// <DropdownMenuContent align="start">
// <DropdownMenuItem>{"Documentation"}</DropdownMenuItem>
// <DropdownMenuItem>{"Themes"}</DropdownMenuItem>
// <DropdownMenuItem>{"GitHub"}</DropdownMenuItem>
// </DropdownMenuContent>
// </DropdownMenu>
<BreadcrumbEllipsis class="h-4 w-4" />
<span class="sr-only">{"Toggle menu"}</span>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink href="#/docs/components">{"Components"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage,
BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="#/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
// TODO
// <DropdownMenu>
// <DropdownMenuTrigger class="flex items-center gap-1">
// <BreadcrumbEllipsis class="h-4 w-4" />
// <span class="sr-only">{"Toggle menu"}</span>
// </DropdownMenuTrigger>
// <DropdownMenuContent align="start">
// <DropdownMenuItem>{"Documentation"}</DropdownMenuItem>
// <DropdownMenuItem>{"Themes"}</DropdownMenuItem>
// <DropdownMenuItem>{"GitHub"}</DropdownMenuItem>
// </DropdownMenuContent>
// </DropdownMenu>
<BreadcrumbEllipsis class="h-4 w-4" />
<span class="sr-only">{"Toggle menu"}</span>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink href="#/docs/components">{"Components"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Installation
The CLI is not yet available. For now, manually copy the component source into your project.
rust-shadcn-ui add breadcrumb
Usage
use yew::prelude::*;
use crate::components::ui::badge::{Badge, BadgeVariant};
#[component]
fn Usage() -> impl IntoView {
view! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink href="/components">{"Components"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Examples
Custom Separator
Use a custom component as children for <BreadcrumbSeparator />
to create a custom separator.
use lucide_yew::Slash;
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbSeparatorDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="#/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<Slash />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbLink href="#/components">{"Components"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<Slash />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
use radix_yew_icons::SlashIcon;
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbSeparatorDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="#/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbLink href="#/components">{"Components"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Dropdown
You can compose <BreadcrumbItem />
with a <DropdownMenu />
to create a dropdown in the breadcrumb.
use lucide_yew::{ChevronDown, Slash};
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbDropdown() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<Slash />
</BreadcrumbSeparator>
<BreadcrumbItem>
// TODO
// <DropdownMenu>
// <DropdownMenuTrigger class="flex items-center gap-1">
// {"Components"}
// <ChevronDown class="h-4 w-4" />
// </DropdownMenuTrigger>
// <DropdownMenuContent align="start">
// <DropdownMenuItem>{"Documentation"}</DropdownMenuItem>
// <DropdownMenuItem>{"Themes"}</DropdownMenuItem>
// <DropdownMenuItem>{"GitHub"}</DropdownMenuItem>
// </DropdownMenuContent>
// </DropdownMenu>
{"Components"}
<ChevronDown class="h-4 w-4" />
</BreadcrumbItem>
<BreadcrumbSeparator>
<Slash />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
use radix_yew_icons::{ChevronDownIcon, SlashIcon};
use yew::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[function_component]
pub fn BreadcrumbDropdown() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/">{"Home"}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
// TODO
// <DropdownMenu>
// <DropdownMenuTrigger class="flex items-center gap-1">
// {"Components"}
// <ChevronDown class="h-4 w-4" />
// </DropdownMenuTrigger>
// <DropdownMenuContent align="start">
// <DropdownMenuItem>{"Documentation"}</DropdownMenuItem>
// <DropdownMenuItem>{"Themes"}</DropdownMenuItem>
// <DropdownMenuItem>{"GitHub"}</DropdownMenuItem>
// </DropdownMenuContent>
// </DropdownMenu>
{"Components"}
<ChevronDownIcon class="h-4 w-4" />
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Collapsed
A <BreadcrumbEllipsis />
component is provided to show a collapsed state when the breadcrumb is too long.
use yew::prelude::*;
use yew_router::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbLinkChildProps,
BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[derive(Clone, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/docs/components")]
Components,
}
#[function_component]
pub fn BreadcrumbEllipsisDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Home"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbEllipsis />
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Components"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
use yew::prelude::*;
use yew_router::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbLinkChildProps,
BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
};
#[derive(Clone, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/docs/components")]
Components,
}
#[function_component]
pub fn BreadcrumbEllipsisDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Home"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbEllipsis />
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Components"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Link Component
To use a custom link component from your routing library, you can use the as_child
prop on <BreadcrumbLink />
.
use yew::prelude::*;
use yew_router::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbLinkChildProps, BreadcrumbList,
BreadcrumbPage, BreadcrumbSeparator,
};
#[derive(Clone, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/components")]
Components,
}
#[function_component]
pub fn BreadcrumbLinkDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Home"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Components"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
use yew::prelude::*;
use yew_router::prelude::*;
use crate::components::ui::breadcrumb::{
Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbLinkChildProps, BreadcrumbList,
BreadcrumbPage, BreadcrumbSeparator,
};
#[derive(Clone, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/components")]
Components,
}
#[function_component]
pub fn BreadcrumbLinkDemo() -> Html {
html! {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Home"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink
as_child={Callback::from(|BreadcrumbLinkChildProps {class, ..}| html! {
<Link<Route> classes={classes!(class)} to={Route::Home}>{"Components"}</Link<Route>>
})}
/>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>{"Breadcrumb"}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
}
Responsive
Here's an example of a responsive breadcrumb that composes <BreadcrumbItem />
with <BreadcrumbEllipsis />
, <DropdownMenu />
, and <Drawer />
.
It displays a dropdown on desktop and a drawer on mobile.
use yew::prelude::*;
// use crate::components::ui::breadcrumb::{
// Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage,
// BreadcrumbSeparator,
// };
#[function_component]
pub fn BreadcrumbResponsive() -> Html {
html! {
// TODO
}
}
use yew::prelude::*;
// use crate::default::components::ui::breadcrumb::{
// Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage,
// BreadcrumbSeparator,
// };
#[function_component]
pub fn BreadcrumbResponsive() -> Html {
html! {
// TODO
}
}