OsirionContentNavigation
OsirionContentNavigation renders a pair of links to the previous and next item, for example at the end of an
article or a documentation page. Give it the current item and it finds the neighbours in the same directory, or
pass the neighbours yourself.
Package Osirion.Blazor.Cms.Web, namespace Osirion.Blazor.Cms.Web.Components. Source on GitHub.
@using Osirion.Blazor.Cms.Domain.Entities
@using Osirion.Blazor.Cms.Domain.Enums
@using Osirion.Blazor.Cms.Domain.Repositories
@using Osirion.Blazor.Cms.Domain.Services
@using Osirion.Blazor.Cms.Web.Components
@inject IContentProviderManager Content
@* The post is picked from this site's own blog, and the component finds its neighbours in the same directory *@
@if (post is not null)
{
<OsirionContentNavigation Item="@post"
Variant="ContentNavigationVariant.Card"
ShowDescription="true"
PreviousLabel="Previous post"
NextLabel="Next post"
AriaLabel="Blog posts"
UrlGenerator="@(item => "/" + item.Url.TrimStart('/'))" />
}
@code {
private ContentItem? post;
protected override async Task OnInitializedAsync()
{
var posts = (await Content.GetContentByQueryAsync(new ContentQuery
{
Locale = "en",
Directory = "blog",
SortBy = SortField.Order,
SortDirection = SortDirection.Ascending
})).Where(item => !item.Path.EndsWith("_index.md", StringComparison.OrdinalIgnoreCase)).ToList();
// The second post has a neighbour on each side
post = posts.Count > 2 ? posts[1] : null;
}
}The demo takes the second blog post of this site's own content, so it has a neighbour on each side, and shows the card layout with descriptions.
Usage
@using Osirion.Blazor.Cms.Web.Components
<OsirionContentNavigation Item="@Item" />
The built-in ArticlePage uses <OsirionContentNavigation Item="Item" ShowDescription ShowPlaceholder />. A
documentation page with card links, root-relative URLs and its own labels:
@using Osirion.Blazor.Cms.Domain.Entities
@using Osirion.Blazor.Cms.Web.Components
<OsirionContentNavigation Item="@Item"
Variant="ContentNavigationVariant.Card"
ShowDescription="true"
PreviousLabel="Previous page"
NextLabel="Next page"
AriaLabel="Documentation pages"
UrlGenerator="@(item => $"/{item.Url.TrimStart('/')}")" />
@code {
[Parameter]
public ContentItem? Item { get; set; }
}
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
Item |
ContentItem? |
null |
The current item. Required: nothing renders without it, even when both neighbours are passed. A missing neighbour is looked up from it. |
PreviousItem |
ContentItem? |
null |
The previous item. When null, it is looked up from Item. |
NextItem |
ContentItem? |
null |
The next item. When null, it is looked up from Item. |
PreviousLabel |
string |
"Previous" |
The label above the previous item's title. |
NextLabel |
string |
"Next" |
The label above the next item's title. |
AriaLabel |
string |
"Content navigation" |
The accessible name of the nav element. |
ShowIcons |
bool |
true |
Whether the arrow icons are shown. |
PreviousIcon |
RenderFragment? |
null |
The icon of the previous link. A left chevron when not set and ShowIcons is true. |
NextIcon |
RenderFragment? |
null |
The icon of the next link. A right chevron when not set and ShowIcons is true. |
ShowDescription |
bool |
false |
Whether each neighbour's description is shown under its title. |
ShowPlaceholder |
bool |
false |
Whether an empty placeholder is rendered where a neighbour is missing, so the other link keeps its side. |
ShowNavigation |
bool |
true |
Whether the navigation renders. When false, nothing renders and the neighbours are not looked up. |
PreventDefault |
bool |
false |
Whether the links are stopped from navigating in an interactive render mode. Leave it false: the click callbacks are not raised, so a prevented link does nothing. |
Variant |
ContentNavigationVariant |
ContentNavigationVariant.Default |
The layout: Default, Compact or Card. It is written as a class on the nav. |
UrlGenerator |
Func<ContentItem, string>? |
null |
A function that builds each link. Without it, the link is the item's Url, a path without a leading slash that resolves against the page's address. |
TitleExtractor |
Func<ContentItem, string>? |
null |
A function that returns the text shown as each title. Without it, the item's Title, or Untitled. |
DescriptionExtractor |
Func<ContentItem, string>? |
null |
A function that returns the text shown as each description. Without it, the item's Description. |
OnPreviousClick |
EventCallback<ContentItem> |
- | A callback for a click on the previous link. Declared but never raised in 4.0. |
OnNextClick |
EventCallback<ContentItem> |
- | A callback for a click on the next link. Declared but never raised in 4.0. |
Theme |
ThemeMode |
ThemeMode.System |
The component's color mode. Light or Dark writes it to data-theme (data-bs-theme under Bootstrap) on the root element; System writes nothing. |
Class |
string? |
null |
Extra CSS classes for the component's root element. |
Style |
string? |
null |
An inline style for the component's root element. |
ContentNavigationVariant has Default, Compact and Card. Class goes on the nav, and other attributes on the
tag are added to it, Theme included. Style is accepted but not written.
Behavior
- When a neighbour is missing, the component queries the published items with the same locale whose directory has
the same name as
Item.Directory, sorted by theorderfront matter ascending. The items right before and afterItem(matched by path) become the neighbours. An item without a directory is compared with all items of its locale. Give the items of a directory distinctordervalues so the sequence is predictable. - Looked-up neighbours are kept inside the component, not in
PreviousItemandNextItem. WhenItemchanges the lookup runs again, and a neighbour you stop passing falls back to the lookup. - The
navrenders only whenItemis set and at least one neighbour exists. With one neighbour it gets theosirion-content-navigation-singleclass. - If the lookup fails, the error is logged through
ILoggerand only the neighbours you passed are shown. - An item's
Urlis a path without a leading slash, so the default link is relative to the page's base address. SetUrlGenerator, as the example does, to make it root-relative. - Titles and descriptions are written as text, so they are HTML-encoded. The links are plain anchors and need no script.
Styling
| Class | Element |
|---|---|
osirion-content-navigation |
The nav, plus your Class |
osirion-content-navigation-default, -compact, -card |
The variant, on the nav |
osirion-content-navigation-single |
Added when only one neighbour is shown |
osirion-content-previous, osirion-content-next |
The two links |
osirion-content-navigation-label |
The label and icon |
osirion-content-navigation-icon |
The icon wrapper |
osirion-content-navigation-title |
The neighbour's title |
osirion-content-navigation-description |
The neighbour's description |
osirion-content-navigation-placeholder |
The empty placeholder |
The links use --osirion-border-color, --osirion-background-primary, --osirion-text-primary and
--osirion-action-primary, with --osirion-focus-ring-color for keyboard focus. The card variant uses
--osirion-card-background, --osirion-card-border-color and --osirion-card-shadow.
Related
- ContentSeriesNavigation, previous and next links inside a series
- ContentBreadcrumbs
- CMS navigation components