Breadcrumb
A trail of links to the current page.
<breadcrumb.Breadcrumb>
<breadcrumb.BreadcrumbList>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/docs")}>Docs</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbPage>Breadcrumb</breadcrumb.BreadcrumbPage>
</breadcrumb.BreadcrumbItem>
</breadcrumb.BreadcrumbList>
</breadcrumb.Breadcrumb>Installation
Run the command in the app module.
gx add breadcrumbThe command also installs icons.
The command writes these files.
| File | Path in the app |
|---|---|
Breadcrumb.gx |
ui/breadcrumb/Breadcrumb.gx |
BreadcrumbList.gx |
ui/breadcrumb/BreadcrumbList.gx |
BreadcrumbItem.gx |
ui/breadcrumb/BreadcrumbItem.gx |
BreadcrumbLink.gx |
ui/breadcrumb/BreadcrumbLink.gx |
BreadcrumbPage.gx |
ui/breadcrumb/BreadcrumbPage.gx |
BreadcrumbSeparator.gx |
ui/breadcrumb/BreadcrumbSeparator.gx |
BreadcrumbEllipsis.gx |
ui/breadcrumb/BreadcrumbEllipsis.gx |
Breadcrumb.fixtures.go |
ui/breadcrumb/Breadcrumb.fixtures.go |
BreadcrumbEllipsis.fixtures.go |
ui/breadcrumb/BreadcrumbEllipsis.fixtures.go |
BreadcrumbItem.fixtures.go |
ui/breadcrumb/BreadcrumbItem.fixtures.go |
BreadcrumbLink.fixtures.go |
ui/breadcrumb/BreadcrumbLink.fixtures.go |
BreadcrumbList.fixtures.go |
ui/breadcrumb/BreadcrumbList.fixtures.go |
BreadcrumbPage.fixtures.go |
ui/breadcrumb/BreadcrumbPage.fixtures.go |
BreadcrumbSeparator.fixtures.go |
ui/breadcrumb/BreadcrumbSeparator.fixtures.go |
Install icons first.
Copy each file to its path in the app. Change each import of a registry package to the path of that package in the app.
package breadcrumb
props {
// Class adds classes to the root element.
Class string = ""
// Children is the content of the breadcrumb: one BreadcrumbList.
Children gx.Node
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<nav aria-label="breadcrumb" data-slot="breadcrumb" class={p.Class} {...p.Attrs}>{p.Children}</nav>package breadcrumb
props {
// Class adds classes to the root element.
Class string = ""
// Children is the content of the list: the items and the separators between them.
Children gx.Node
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<ol data-slot="breadcrumb-list" class={gx.Cx("flex flex-wrap items-center gap-1.5 text-sm break-words text-muted-foreground sm:gap-2.5", p.Class)} {...p.Attrs}>{p.Children}</ol>package breadcrumb
props {
// Class adds classes to the root element.
Class string = ""
// Children is the content of the item: a BreadcrumbLink, a BreadcrumbPage or a
// BreadcrumbEllipsis.
Children gx.Node
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<li data-slot="breadcrumb-item" class={gx.Cx("inline-flex items-center gap-1.5", p.Class)} {...p.Attrs}>{p.Children}</li>package breadcrumb
props {
// Href is the URL of the link.
Href gx.URL
// Class adds classes to the root element.
Class string = ""
// Children is the link label.
Children gx.Node
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<a href={p.Href} data-slot="breadcrumb-link" class={gx.Cx("transition-colors hover:text-foreground", p.Class)} {...p.Attrs}>{p.Children}</a>package breadcrumb
props {
// Class adds classes to the root element.
Class string = ""
// Children is the label of the current page.
Children gx.Node
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<span data-slot="breadcrumb-page" role="link" aria-disabled="true" aria-current="page" class={gx.Cx("font-normal text-foreground", p.Class)} {...p.Attrs}>{p.Children}</span>package breadcrumb
import "github.com/alternayte/gx/registry/icons"
props {
// Class adds classes to the root element.
Class string = ""
// Children is the content of the separator. A nil value renders a chevron icon.
Children gx.Node = nil
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<li data-slot="breadcrumb-separator" role="presentation" aria-hidden="true" class={gx.Cx("[&>svg]:size-3.5", p.Class)} {...p.Attrs}>
if p.Children != nil {
{p.Children}
} else {
<icons.ChevronRight />
}
</li>package breadcrumb
import "github.com/alternayte/gx/registry/icons"
props {
// Class adds classes to the root element.
Class string = ""
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<span data-slot="breadcrumb-ellipsis" role="presentation" aria-hidden="true" class={gx.Cx("flex size-9 items-center justify-center", p.Class)} {...p.Attrs}>
<icons.Ellipsis class="size-4" />
<span class="sr-only">More</span>
</span>package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbFixtures = gx.Fixtures[BreadcrumbProps]{
"Trail": {Children: BreadcrumbList(BreadcrumbListProps{Children: gx.Frag(
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbLink(BreadcrumbLinkProps{Href: gx.URL("/"), Children: gx.Text("Home")})}),
BreadcrumbSeparator(BreadcrumbSeparatorProps{}),
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbLink(BreadcrumbLinkProps{Href: gx.URL("/docs"), Children: gx.Text("Docs")})}),
BreadcrumbSeparator(BreadcrumbSeparatorProps{}),
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbPage(BreadcrumbPageProps{Children: gx.Text("Breadcrumb")})}),
)})},
"Ellipsis": {Children: BreadcrumbList(BreadcrumbListProps{Children: gx.Frag(
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbLink(BreadcrumbLinkProps{Href: gx.URL("/"), Children: gx.Text("Home")})}),
BreadcrumbSeparator(BreadcrumbSeparatorProps{}),
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbEllipsis(BreadcrumbEllipsisProps{})}),
BreadcrumbSeparator(BreadcrumbSeparatorProps{}),
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbPage(BreadcrumbPageProps{Children: gx.Text("Breadcrumb")})}),
)})},
"CustomSeparator": {Children: BreadcrumbList(BreadcrumbListProps{Children: gx.Frag(
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbLink(BreadcrumbLinkProps{Href: gx.URL("/"), Children: gx.Text("Home")})}),
BreadcrumbSeparator(BreadcrumbSeparatorProps{Children: gx.Text("/")}),
BreadcrumbItem(BreadcrumbItemProps{Children: BreadcrumbPage(BreadcrumbPageProps{Children: gx.Text("Breadcrumb")})}),
)})},
}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbEllipsisFixtures = gx.Fixtures[BreadcrumbEllipsisProps]{"Default": {}}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbItemFixtures = gx.Fixtures[BreadcrumbItemProps]{"Empty": {}}
// BreadcrumbItemWrap renders the item inside a list, as a page uses it.
func BreadcrumbItemWrap(n gx.Node) gx.Node {
return BreadcrumbList(BreadcrumbListProps{Children: n})
}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbLinkFixtures = gx.Fixtures[BreadcrumbLinkProps]{"Link": {Href: gx.URL("/"), Children: gx.Text("Home")}}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbListFixtures = gx.Fixtures[BreadcrumbListProps]{"Empty": {}}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbPageFixtures = gx.Fixtures[BreadcrumbPageProps]{"Page": {Children: gx.Text("Page")}}package breadcrumb
import "github.com/alternayte/gx"
var BreadcrumbSeparatorFixtures = gx.Fixtures[BreadcrumbSeparatorProps]{"Default": {}}
// BreadcrumbSeparatorWrap renders the separator inside a list, as a page
// uses it.
func BreadcrumbSeparatorWrap(n gx.Node) gx.Node {
return BreadcrumbList(BreadcrumbListProps{Children: n})
}The theme must define these tokens: --foreground, --muted-foreground.
Usage
<breadcrumb.Breadcrumb>
<breadcrumb.BreadcrumbList>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbPage>Products</breadcrumb.BreadcrumbPage>
</breadcrumb.BreadcrumbItem>
</breadcrumb.BreadcrumbList>
</breadcrumb.Breadcrumb>BreadcrumbSeparator shows a chevron. Pass a child to show another icon or a character.
BreadcrumbEllipsis shows the ellipsis icon for a collapsed middle.
Examples
Breadcrumb: Trail
<breadcrumb.Breadcrumb>
<breadcrumb.BreadcrumbList>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/docs")}>Docs</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbPage>Breadcrumb</breadcrumb.BreadcrumbPage>
</breadcrumb.BreadcrumbItem>
</breadcrumb.BreadcrumbList>
</breadcrumb.Breadcrumb>Breadcrumb: Ellipsis
<breadcrumb.Breadcrumb>
<breadcrumb.BreadcrumbList>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem><breadcrumb.BreadcrumbEllipsis /></breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator />
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbPage>Breadcrumb</breadcrumb.BreadcrumbPage>
</breadcrumb.BreadcrumbItem>
</breadcrumb.BreadcrumbList>
</breadcrumb.Breadcrumb>Breadcrumb: Custom separator
<breadcrumb.Breadcrumb>
<breadcrumb.BreadcrumbList>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>
</breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbSeparator>/</breadcrumb.BreadcrumbSeparator>
<breadcrumb.BreadcrumbItem>
<breadcrumb.BreadcrumbPage>Breadcrumb</breadcrumb.BreadcrumbPage>
</breadcrumb.BreadcrumbItem>
</breadcrumb.BreadcrumbList>
</breadcrumb.Breadcrumb>BreadcrumbEllipsis: Default
<breadcrumb.BreadcrumbEllipsis />BreadcrumbItem: Empty
<breadcrumb.BreadcrumbItem children={gx.Frag()} />BreadcrumbLink: Link
<breadcrumb.BreadcrumbLink href={gx.URL("/")}>Home</breadcrumb.BreadcrumbLink>BreadcrumbList: Empty
<breadcrumb.BreadcrumbList children={gx.Frag()} />BreadcrumbPage: Page
<breadcrumb.BreadcrumbPage>Page</breadcrumb.BreadcrumbPage>BreadcrumbSeparator: Default
<breadcrumb.BreadcrumbSeparator />API reference
A tag sets a prop by its name with a lower-case first letter: Class is class.
breadcrumb.Breadcrumb
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
Required | Children is the content of the breadcrumb: one BreadcrumbList. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbEllipsis
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbItem
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
Required | Children is the content of the item: a BreadcrumbLink, a BreadcrumbPage or a BreadcrumbEllipsis. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbLink
| Prop | Type | Default | Description |
|---|---|---|---|
Href |
gx.URL |
Required | Href is the URL of the link. |
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
Required | Children is the link label. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbList
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
Required | Children is the content of the list: the items and the separators between them. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbPage
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
Required | Children is the label of the current page. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
breadcrumb.BreadcrumbSeparator
| Prop | Type | Default | Description |
|---|---|---|---|
Class |
string |
"" |
Class adds classes to the root element. |
Children |
gx.Node |
nil |
Children is the content of the separator. A nil value renders a chevron icon. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
Do and do not
Do
- End the trail with
BreadcrumbPage. - Use
BreadcrumbEllipsisfor a collapsed middle.
Don't
- Do not use a breadcrumb for primary navigation.
- Do not link the current page.
Keyboard
| Key | Action |
|---|---|
| None | The component is static. |