Skip to content

Commit 729b3df

Browse files
Add project files.
1 parent 71e46ae commit 729b3df

37 files changed

+1490
-0
lines changed

Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<BlazorVersion>0.9.0-preview3-19154-02</BlazorVersion>
4+
<ReleaseVersion>0.1.0-beta-1</ReleaseVersion>
5+
</PropertyGroup>
6+
</Project>

PreRenderComponent.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28701.123
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PreRenderSample", "samples\PreRenderSample\PreRenderSample.csproj", "{2E4F3542-4961-4E7C-A2C1-08ECB60E0DB0}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PreRenderComponent", "src\PreRenderComponent\PreRenderComponent.csproj", "{B2C7F70E-20C6-408C-9B9B-B666329A52CA}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52F0AAE9-E7F6-45FA-A519-6E2BB787D53D}"
11+
ProjectSection(SolutionItems) = preProject
12+
Directory.Build.props = Directory.Build.props
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Release|Any CPU = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{2E4F3542-4961-4E7C-A2C1-08ECB60E0DB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{2E4F3542-4961-4E7C-A2C1-08ECB60E0DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{2E4F3542-4961-4E7C-A2C1-08ECB60E0DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{2E4F3542-4961-4E7C-A2C1-08ECB60E0DB0}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{B2C7F70E-20C6-408C-9B9B-B666329A52CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{B2C7F70E-20C6-408C-9B9B-B666329A52CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{B2C7F70E-20C6-408C-9B9B-B666329A52CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{B2C7F70E-20C6-408C-9B9B-B666329A52CA}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {7700E729-05DE-4658-BE65-F1B65913F88C}
36+
EndGlobalSection
37+
EndGlobal

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# PreRenderComponent
2+
3+
Provides a CascadingValue exposing whether the app is in PreRendering or not.
4+
5+
## Usage
6+
7+
Install the nuget https://nuget.org/packages/PreRenderComponent
8+
9+
Add references to Components/_ViewImports.cshtml
10+
11+
```
12+
@using PreRenderComponent
13+
@addTagHelper *, PreRenderComponent
14+
```
15+
16+
Wrap the Router component in PreRenderCascade in the App.razor file
17+
18+
```
19+
<PreRenderCascade>
20+
<Router AppAssembly="typeof(Startup).Assembly" />
21+
</PreRenderCascade>
22+
```
23+
24+
Consume the CascadingValue in your own pages/components
25+
26+
```
27+
@if (IsPreRendering)
28+
{
29+
<button class="btn btn-dark" onclick="@IncrementCount" disabled>Don't Click me</button>
30+
}
31+
else
32+
{
33+
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
34+
}
35+
36+
37+
@functions {
38+
[CascadingParameter(Name = "PreRendering")]
39+
protected bool IsPreRendering { get; set; }
40+
}
41+
```
42+
43+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@*
2+
The Router component displays whichever component has a @page
3+
directive matching the current URI.
4+
*@
5+
<PreRenderCascade>
6+
<Router AppAssembly="typeof(Startup).Assembly" />
7+
</PreRenderCascade>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page "/counter"
2+
To see the Pre-Rendering in effect, open the browser dev tools and set the network speed to slow, then refresh.
3+
4+
<h1>Counter</h1>
5+
6+
<p>Current count: @currentCount</p>
7+
8+
@if (IsPreRendering)
9+
{
10+
<button class="btn btn-dark" onclick="@IncrementCount" disabled>Don't Click me</button>
11+
}
12+
else
13+
{
14+
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
15+
}
16+
17+
@functions {
18+
[CascadingParameter(Name = "PreRendering")] protected bool IsPreRendering { get; set; }
19+
20+
int currentCount = 0;
21+
22+
void IncrementCount()
23+
{
24+
currentCount++;
25+
}
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@page "/fetchdata"
2+
@using PreRenderSample.Services
3+
@inject WeatherForecastService ForecastService
4+
5+
<h1>Weather forecast</h1>
6+
7+
<p>This component demonstrates fetching data from a service.</p>
8+
9+
@if (forecasts == null)
10+
{
11+
<p><em>Loading...</em></p>
12+
}
13+
else
14+
{
15+
<table class="table">
16+
<thead>
17+
<tr>
18+
<th>Date</th>
19+
<th>Temp. (C)</th>
20+
<th>Temp. (F)</th>
21+
<th>Summary</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
@foreach (var forecast in forecasts)
26+
{
27+
<tr>
28+
<td>@forecast.Date.ToShortDateString()</td>
29+
<td>@forecast.TemperatureC</td>
30+
<td>@forecast.TemperatureF</td>
31+
<td>@forecast.Summary</td>
32+
</tr>
33+
}
34+
</tbody>
35+
</table>
36+
}
37+
38+
@functions {
39+
WeatherForecast[] forecasts;
40+
41+
protected override async Task OnInitAsync()
42+
{
43+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
44+
}
45+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
6+
7+
To see the Pre-Rendering in effect, open the browser dev tools and set the network speed to slow, then refresh.
8+
9+
Also check out the Counter page for another example.
10+
11+
@if (IsPreRendering)
12+
{
13+
<h2>Warming up the engine...</h2>
14+
}
15+
@functions {
16+
[CascadingParameter(Name = "PreRendering")] protected bool IsPreRendering { get; set; }
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@layout MainLayout
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">PreRenderSample</a>
3+
<button class="navbar-toggler" onclick="@ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" onclick="@ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>
25+
</ul>
26+
</div>
27+
28+
@functions {
29+
bool collapseNavMenu = true;
30+
31+
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
32+
33+
void ToggleNavMenu()
34+
{
35+
collapseNavMenu = !collapseNavMenu;
36+
}
37+
}

0 commit comments

Comments
 (0)