Skip to content

Commit be1a991

Browse files
authored
feat: Add Breadcrumb and Preload services with documentation and demos (#1395)
- Introduced BreadcrumbService to manage breadcrumb navigation dynamically. - Added PreloadService to show and hide loading overlays during operations. - Created documentation pages for both services detailing usage and setup. - Implemented demo components to showcase BreadcrumbService and PreloadService functionalities. - Updated home catalog to include new components and services. - Enhanced CSS styles for better UI consistency and accessibility. - Added statistics to appsettings for NuGet downloads, GitHub stars, and component count.
1 parent 44414e4 commit be1a991

13 files changed

Lines changed: 686 additions & 644 deletions

‎BlazorBootstrap.Demo.RCL/Components/Layout/MainLayout.razor.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ internal override IEnumerable<NavItem> GetNavItems()
114114
new (){ Id = "607", Text = "Scatter Chart", Href = DemoRouteConstants.Demos_URL_ScatterChart, IconName = IconName.GraphUpArrow, ParentId = "6", Match = NavLinkMatch.All },
115115

116116
new(){ Id = "7", Text = "Services", IconName = IconName.WrenchAdjustableCircleFill, IconColor = IconColor.Success },
117+
new (){ Id = "701", Text = "Breadcrumb Service", Href = DemoRouteConstants.Demos_URL_BreadcrumbService, IconName = IconName.SegmentedNav, ParentId = "7" },
117118
new (){ Id = "700", Text = "Modal Service", Href = DemoRouteConstants.Demos_URL_ModalService, IconName = IconName.WindowStack, ParentId = "7" },
119+
new (){ Id = "702", Text = "Preload Service", Href = DemoRouteConstants.Demos_URL_PreloadService, IconName = IconName.ArrowRepeat, ParentId = "7" },
118120

119121
new(){ Id = "19", Text = "Utilities", IconName = IconName.GearWideConnected, IconColor = IconColor.Info },
120122
new (){ Id = "1900", Text = "Color Utility", Href = DemoRouteConstants.Demos_URL_ColorUtils, IconName = IconName.Palette2, ParentId = "19" },
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@attribute [Route(pageUrl)]
2+
@layout DemosMainLayout
3+
4+
<DemosPageHeadSection PageUrl="@pageUrl"
5+
PageTitle="@pageTitle"
6+
PageDescription="@pageDescription"
7+
MetaTitle="@metaTitle"
8+
MetaDescription="@metaDescription"
9+
ImageUrl="@imageUrl" />
10+
11+
<DocsLink Href="@DemoRouteConstants.Docs_URL_BreadcrumbService" />
12+
13+
<div class="mt-3">Use Blazor BreadcrumbService to update the breadcrumb from any page or component in your app.</div>
14+
15+
<Section Size="HeadingSize.H2" Name="How it works" PageUrl="@pageUrl" Link="how-it-works">
16+
<div class="mb-3">
17+
<code>BreadcrumbService</code> sends a new list of items to every <code>Breadcrumb</code> component on the page that has no <code>Items</code> set by its parent.
18+
<br />
19+
<strong>How to use:</strong>
20+
<div class="content mb-2">
21+
<ol>
22+
<li>Add a <code>Breadcrumb</code> component without the <code>Items</code> parameter, usually in a layout.</li>
23+
<li>Inject <code>BreadcrumbService</code> in the page or component that knows the current location.</li>
24+
<li>Call <code>Notify(...)</code> with a <code>List&lt;BreadcrumbItem&gt;</code>. Set <code>IsCurrentPage</code> on the last item.</li>
25+
</ol>
26+
</div>
27+
Use the buttons to send a different trail to the breadcrumb.
28+
</div>
29+
<Demo Type="typeof(BreadcrumbService_Demo_01_Update_Breadcrumb_From_Code)" />
30+
</Section>
31+
32+
<Section Size="HeadingSize.H2" Name="How to setup" PageUrl="@pageUrl" Link="how-to-setup">
33+
<div class="mb-3">1. Add the <code>Breadcrumb</code> component in <code>MainLayout.razor</code> page as shown below.</div>
34+
<Demo Type="typeof(BreadcrumbService_Demo_02_Setup_Layout)" ShowCodeOnly="true" />
35+
36+
<div class="mb-3">2. Inject <code>BreadcrumbService</code>, then call the <code>Notify(...)</code> method as shown below.</div>
37+
<Demo Type="typeof(BreadcrumbService_Demo_03_Setup_Notify)" ShowCodeOnly="true" />
38+
</Section>
39+
40+
@code {
41+
private const string pageUrl = DemoRouteConstants.Demos_URL_BreadcrumbService;
42+
private const string pageTitle = "Blazor Breadcrumb Service";
43+
private const string pageDescription = "Use Blazor Bootstrap breadcrumb service to update the breadcrumb from any page or component in your app.";
44+
private const string metaTitle = "Blazor Breadcrumb Service";
45+
private const string metaDescription = "Use Blazor Bootstrap breadcrumb service to update the breadcrumb from any page or component in your app.";
46+
private const string imageUrl = DemoScreenshotSrcConstants.Demos_URL_BreadcrumbService;
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Breadcrumb />
2+
3+
<div class="d-flex flex-wrap gap-2 mt-3">
4+
<Button Color="ButtonColor.Primary" @onclick="ShowOrders">Orders</Button>
5+
<Button Color="ButtonColor.Primary" @onclick="ShowOrder">Order 1001</Button>
6+
<Button Color="ButtonColor.Primary" @onclick="ShowSettings">Settings</Button>
7+
</div>
8+
9+
@code {
10+
[Inject] BreadcrumbService BreadcrumbService { get; set; } = default!;
11+
12+
protected override void OnAfterRender(bool firstRender)
13+
{
14+
// The Breadcrumb subscribes when it initializes, so send the first trail after the first render.
15+
if (firstRender)
16+
ShowOrders();
17+
}
18+
19+
private void ShowOrders()
20+
{
21+
BreadcrumbService.Notify(new List<BreadcrumbItem>
22+
{
23+
new BreadcrumbItem { Text = "Home", Href = "/" },
24+
new BreadcrumbItem { Text = "Orders", IsCurrentPage = true }
25+
});
26+
}
27+
28+
private void ShowOrder()
29+
{
30+
BreadcrumbService.Notify(new List<BreadcrumbItem>
31+
{
32+
new BreadcrumbItem { Text = "Home", Href = "/" },
33+
new BreadcrumbItem { Text = "Orders", Href = DemoRouteConstants.Demos_URL_BreadcrumbService },
34+
new BreadcrumbItem { Text = "Order 1001", IsCurrentPage = true }
35+
});
36+
}
37+
38+
private void ShowSettings()
39+
{
40+
BreadcrumbService.Notify(new List<BreadcrumbItem>
41+
{
42+
new BreadcrumbItem { Text = "Home", Href = "/" },
43+
new BreadcrumbItem { Text = "Settings", IsCurrentPage = true }
44+
});
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@inherits LayoutComponentBase
2+
3+
...
4+
5+
... MainLayout.razor code goes here ...
6+
7+
...
8+
9+
<Breadcrumb />
10+
11+
@Body
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@code {
2+
[Inject] BreadcrumbService BreadcrumbService { get; set; } = default!;
3+
4+
protected override void OnInitialized()
5+
{
6+
BreadcrumbService.Notify(new List<BreadcrumbItem>
7+
{
8+
new BreadcrumbItem { Text = "Home", Href = "/" },
9+
new BreadcrumbItem { Text = "Orders", IsCurrentPage = true }
10+
});
11+
12+
base.OnInitialized();
13+
}
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@using BlazorBootstrap.Demo.RCL.Components.Pages.Demos.Preload
2+
3+
@attribute [Route(pageUrl)]
4+
@layout DemosMainLayout
5+
6+
<DemosPageHeadSection PageUrl="@pageUrl"
7+
PageTitle="@pageTitle"
8+
PageDescription="@pageDescription"
9+
MetaTitle="@metaTitle"
10+
MetaDescription="@metaDescription"
11+
ImageUrl="@imageUrl" />
12+
13+
<DocsLink Href="@DemoRouteConstants.Docs_URL_PreloadService" />
14+
15+
<div class="mt-3">Use Blazor PreloadService to show and hide a loading overlay from anywhere in your app.</div>
16+
17+
<Section Size="HeadingSize.H2" Name="How it works" PageUrl="@pageUrl" Link="how-it-works">
18+
<div class="mb-3">
19+
<code>PreloadService</code> shows the <code>Preload</code> overlay placed in your layout while work runs, then hides it.
20+
<br />
21+
<strong>How to use:</strong>
22+
<div class="content mb-2">
23+
<ol>
24+
<li>Inject <code>PreloadService</code> in the page or component that starts the work.</li>
25+
<li>Call <code>Show()</code> before the work starts. Pass a <code>SpinnerColor</code> and a loading text to change how the overlay looks.</li>
26+
<li>Call <code>Hide()</code> in a <code>finally</code> block, so the overlay closes even when the work fails.</li>
27+
</ol>
28+
</div>
29+
Each button shows the overlay for 2 seconds, standing in for a call to a service or API.
30+
</div>
31+
<Demo Type="typeof(PreloadService_Demo_01_Show_And_Hide_From_Code)" />
32+
</Section>
33+
34+
<Section Size="HeadingSize.H2" Name="How to setup" PageUrl="@pageUrl" Link="how-to-setup">
35+
<div class="mb-3">1. Add the <code>Preload</code> component in <code>MainLayout.razor</code> page as shown below.</div>
36+
<Demo Type="typeof(Preload_Demo_01_Global_Preload_For_Application_A)" ShowCodeOnly="true" />
37+
38+
<div class="mb-3">2. Inject <code>PreloadService</code>, then call the <code>Show()</code> and <code>Hide()</code> methods as shown below.</div>
39+
<Demo Type="typeof(Preload_Demo_01_Global_Preload_For_Application_B)" ShowCodeOnly="true" />
40+
</Section>
41+
42+
@code {
43+
private const string pageUrl = DemoRouteConstants.Demos_URL_PreloadService;
44+
private const string pageTitle = "Blazor Preload Service";
45+
private const string pageDescription = "Use Blazor Bootstrap preload service to show and hide a loading overlay from anywhere in your app.";
46+
private const string metaTitle = "Blazor Preload Service";
47+
private const string metaDescription = "Use Blazor Bootstrap preload service to show and hide a loading overlay from anywhere in your app.";
48+
private const string imageUrl = DemoScreenshotSrcConstants.Demos_URL_PreloadService;
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<div class="d-flex flex-wrap gap-2">
2+
<Button Color="ButtonColor.Primary" @onclick="ShowAsync">Show for 2 seconds</Button>
3+
<Button Color="ButtonColor.Secondary" @onclick="ShowWithLoadingTextAsync">Show with loading text</Button>
4+
<Button Color="ButtonColor.Dark" @onclick="ShowWithPrimarySpinnerAsync">Show with a primary spinner</Button>
5+
</div>
6+
7+
@code {
8+
[Inject] PreloadService PreloadService { get; set; } = default!;
9+
10+
private async Task ShowAsync()
11+
{
12+
try
13+
{
14+
PreloadService.Show();
15+
await Task.Delay(2000); // call the service/api
16+
}
17+
finally
18+
{
19+
PreloadService.Hide();
20+
}
21+
}
22+
23+
private async Task ShowWithLoadingTextAsync()
24+
{
25+
try
26+
{
27+
PreloadService.Show(SpinnerColor.Light, "Loading orders...");
28+
await Task.Delay(2000); // call the service/api
29+
}
30+
finally
31+
{
32+
PreloadService.Hide();
33+
}
34+
}
35+
36+
private async Task ShowWithPrimarySpinnerAsync()
37+
{
38+
try
39+
{
40+
PreloadService.Show(SpinnerColor.Primary);
41+
await Task.Delay(2000); // call the service/api
42+
}
43+
finally
44+
{
45+
PreloadService.Hide();
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)