Skip to content

Commit 7de15fd

Browse files
authored
Update README.md
1 parent e74c7f0 commit 7de15fd

1 file changed

Lines changed: 154 additions & 6 deletions

File tree

README.md

Lines changed: 154 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Blazor Navigation Stack
23
[![NuGet (with prereleases)](https://img.shields.io/nuget/vpre/Blazor.NavigationStack.svg?logo=nuget)](https://www.nuget.org/packages/Blazor.NavigationStack)
34

@@ -33,8 +34,8 @@ PM> Install-Package Blazor.NavigationStack
3334
*Nuget package page can be found [here](https://www.nuget.org/packages/Blazor.NavigationStack).*
3435
## Basic Usage
3536
### Obtaining INavigationStack
36-
All operations on the Blazor navigation stack can be done through INavigationStack interface.
37-
INavigationStack interface can be obtained through many ways.
37+
All operations on the Blazor navigation stack can be done through `INavigationStack` interface.
38+
`INavigationStack` interface can be obtained through many ways.
3839
1. Through context
3940
``` razor
4041
<NavigationStack>
@@ -78,8 +79,8 @@ INavigationStack interface can be obtained through many ways.
7879
}
7980
```
8081
### Add a page to the stack
81-
+ Adding a page on top of the current one by calling INavigationStack.Push method.
82-
+ Remove the top most page by calling INavigationStack.Pop method
82+
+ Adding a page on top of the current one by calling `INavigationStack.Push` method.
83+
+ Remove the top most page by calling `INavigationStack.Pop` method
8384
``` razor
8485
void ReturnClicked() {
8586
_stack.Pop();
@@ -95,8 +96,8 @@ await _stack.Push(new StackPage() {
9596
});
9697
```
9798
### Add a page expecting a result
98-
+ Adding a page on top of the current one by calling INavigationStack.Push\<T> method.
99-
+ Setting a result and pop the cuurent page by calling INavigationStack.SetResult method.
99+
+ Adding a page on top of the current one by calling `INavigationStack.Push<T>` method.
100+
+ Setting a result and pop the cuurent page by calling `INavigationStack.SetResult` method.
100101

101102
ComponentWithStack.razor
102103
``` razor
@@ -126,4 +127,151 @@ StackPageComponent.razor
126127
}
127128
```
128129

130+
## Modifying Pushed Pages
131+
132+
In case a name or the menu of the current page need to be updated after it was push onto the stack, it can be done through `INavigationStack.SetName` and `INavigationStack.SetMenu` methods.
133+
134+
```csharp
135+
// Change the name of the current page
136+
NavigationStack?.SetName("Page Title");
137+
138+
// Set a custom menu to the curret page
139+
NavigationStack?.SetMenu(CustomMenuFragment);
140+
```
141+
129142
## Customization
143+
You can customize virtually every part of the Navigation Stack, including:
144+
- Overall layout
145+
- Header stack appearance
146+
- Individual header styling
147+
- Header separators
148+
- Menu appearance
149+
- Back button
150+
151+
152+
To customize the Navigation Stack, pass custom RenderFragments to the appropriate parameters of the NavigationStack component:
153+
154+
```cshtml
155+
<NavigationStack
156+
BaseName="Home"
157+
Layout="@CustomLayout"
158+
HeaderStack="@CustomHeaderStack"
159+
Header="@CustomHeader"
160+
HeaderSeparator="@CustomHeaderSeparator"
161+
Menu="@CustomMenu"
162+
Back="@CustomBack">
163+
<BaseContent>
164+
<!-- Your base content here -->
165+
</BaseContent>
166+
</NavigationStack>
167+
```
168+
### Overall Layout
169+
The layout controls the overall structure of the navigation stack:
170+
171+
```cshtml
172+
private RenderFragment<NavigationStack.LayoutContext> CustomLayout => context => {
173+
return @<div class="dark-layout">
174+
<div class="dark-header">
175+
<div class="header-left">
176+
@context.BackButton
177+
@context.HeaderStack
178+
</div>
179+
<div class="header-right">
180+
@context.MenuStack
181+
</div>
182+
</div>
183+
<div class="dark-content">
184+
@context.Content
185+
</div>
186+
</div>;
187+
};
188+
```
189+
190+
191+
The `LayoutContext` provides:
192+
- `BackButton`: Back navigation button
193+
- `HeaderStack`: Breadcrumbs/header navigation
194+
- `MenuStack`: Menu for the current page
195+
- `Content`: The main content area
196+
### Header
197+
Customize how navigation headers appear:
198+
199+
```cshtml
200+
private RenderFragment<NavigationStack.HeaderContext> CustomHeader => context => {
201+
return @<div class="@(context.IsActive ? "header-active" : "header-inactive")">
202+
@context.Name
203+
</div>;
204+
};
205+
```
206+
207+
208+
The `HeaderContext` provides:
209+
- `Name`: Title of the page
210+
- `IsActive`: Whether this is the currently active page
211+
212+
### Header Stack
213+
Change how the entire breadcrumb/header navigation appears:
214+
215+
```cshtml
216+
private RenderFragment<NavigationStack.HeaderStackContext> CustomHeaderStack => context => {
217+
return @<div class="header-stack">
218+
@{
219+
RenderFragment header = context.Headers.First();
220+
<div class="header-item">
221+
@header
222+
</div>
223+
}
224+
</div>;
225+
};
226+
```
227+
228+
229+
The `HeaderStackContext` provides:
230+
- `Headers`: Collection of header fragments to display
231+
### Header Separator
232+
Customize the separator between headers:
233+
234+
```cshtml
235+
private RenderFragment CustomHeaderSeparator => @<div class="separator-arrow">
236+
<span>→</span>
237+
</div>;
238+
```
239+
240+
### Menu
241+
Change how menu options are shown on each page:
242+
243+
```cshtml
244+
private RenderFragment<NavigationStack.MenuContext> CustomMenu => context => {
245+
return @<div class="menu-container">
246+
@foreach (var option in context.Options) {
247+
<div class="menu-item">
248+
@option
249+
</div>
250+
}
251+
</div>;
252+
};
253+
```
254+
255+
256+
The `MenuContext` provides:
257+
- `Options`: Collection of menu item fragments to display
258+
259+
### Back Button
260+
Change the appearance and behavior of the back button:
261+
262+
```cshtml
263+
private RenderFragment<NavigationStack.BackContext> CustomBack => context => {
264+
return @<button class="back-button" @onclick="context.Back">
265+
<span>◀</span> Back
266+
</button>;
267+
};
268+
```
269+
270+
271+
The `BackContext` provides:
272+
- `Back`: Action to perform `INavigationStack.Cancel`
273+
274+
275+
For a complete example, see the `Customize.razor` component which demonstrates a dark-themed custom navigation stack.
276+
277+

0 commit comments

Comments
 (0)