Skip to content

Commit 9ee598e

Browse files
committed
adding simple blazor component example
1 parent c4d906d commit 9ee598e

11 files changed

Lines changed: 92 additions & 3 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview9.19424.4" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview9.19424.4" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.JSInterop;
2+
using System.Threading.Tasks;
3+
4+
namespace RazorClassLibrary_CSharp
5+
{
6+
public class ExampleJsInterop
7+
{
8+
public static ValueTask<string> Prompt(IJSRuntime jsRuntime, string message)
9+
{
10+
// Implemented in exampleJsInterop.js
11+
return jsRuntime.InvokeAsync<string>(
12+
"exampleJsFunctions.showPrompt",
13+
message);
14+
}
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
<p>Current count: @currentCount</p>
3+
4+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
5+
6+
@code {
7+
int currentCount = 0;
8+
9+
void IncrementCount()
10+
{
11+
currentCount++;
12+
}
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@using Microsoft.AspNetCore.Components.Web
378 Bytes
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is to show how a library package may provide JavaScript interop features
2+
// wrapped in a .NET API
3+
4+
window.exampleJsFunctions = {
5+
showPrompt: function (message) {
6+
return prompt(message, 'Type anything here');
7+
}
8+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
This file is to show how CSS and other static resources (such as images) can be
3+
used from a library project/package.
4+
*/
5+
6+
.my-component {
7+
border: 2px dashed red;
8+
padding: 1em;
9+
margin: 1em 0;
10+
background-image: url('background.png');
11+
}

presentations/aspnetcore3-whatsnew/aspnetcore3-whatsnew.sln

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8EBD1D42-5
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureTests", "test\FeatureTests\FeatureTests.csproj", "{03C93B42-CCE6-41EB-A3D9-07F7D38C0A24}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple", "src\Simple\Simple.csproj", "{B5DAE22D-0780-40D0-8235-701361C4E10C}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Simple", "src\Simple\Simple.csproj", "{B5DAE22D-0780-40D0-8235-701361C4E10C}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorComponents", "BlazorComponents\BlazorComponents.csproj", "{1539C377-573E-4699-B772-731C1E4D6F6B}"
2123
EndProject
2224
Global
2325
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -101,6 +103,18 @@ Global
101103
{B5DAE22D-0780-40D0-8235-701361C4E10C}.Release|x64.Build.0 = Release|Any CPU
102104
{B5DAE22D-0780-40D0-8235-701361C4E10C}.Release|x86.ActiveCfg = Release|Any CPU
103105
{B5DAE22D-0780-40D0-8235-701361C4E10C}.Release|x86.Build.0 = Release|Any CPU
106+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
108+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|x64.ActiveCfg = Debug|Any CPU
109+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|x64.Build.0 = Debug|Any CPU
110+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|x86.ActiveCfg = Debug|Any CPU
111+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Debug|x86.Build.0 = Debug|Any CPU
112+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|x64.ActiveCfg = Release|Any CPU
115+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|x64.Build.0 = Release|Any CPU
116+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|x86.ActiveCfg = Release|Any CPU
117+
{1539C377-573E-4699-B772-731C1E4D6F6B}.Release|x86.Build.0 = Release|Any CPU
104118
EndGlobalSection
105119
GlobalSection(SolutionProperties) = preSolution
106120
HideSolutionNode = FALSE
@@ -112,6 +126,7 @@ Global
112126
{CE14203A-E6FB-47FB-A43B-4330DABE629B} = {C877ED0F-80CA-441F-A0F5-37EFED8DD82B}
113127
{03C93B42-CCE6-41EB-A3D9-07F7D38C0A24} = {8EBD1D42-5032-4738-A1ED-7147D993B07B}
114128
{B5DAE22D-0780-40D0-8235-701361C4E10C} = {C877ED0F-80CA-441F-A0F5-37EFED8DD82B}
129+
{1539C377-573E-4699-B772-731C1E4D6F6B} = {C877ED0F-80CA-441F-A0F5-37EFED8DD82B}
115130
EndGlobalSection
116131
GlobalSection(ExtensibilityGlobals) = postSolution
117132
SolutionGuid = {A3894733-0D19-4E87-AF47-D3EA15BA9D08}

presentations/aspnetcore3-whatsnew/src/Simple/Pages/Index.cshtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
}
66

77
<h1>Index</h1>
8+
<div>Hello, from Razor Pages!</div>
9+
<div>
810

11+
@(await Html.RenderComponentAsync<BlazorComponents.Greetings>(RenderMode.ServerPrerendered))
12+
13+
</div>
14+
<script src="/_framework/blazor.server.js"></script>

presentations/aspnetcore3-whatsnew/src/Simple/Simple.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview9-19453-02" />
1616
</ItemGroup>
1717

18+
<ItemGroup>
19+
<ProjectReference Include="..\..\BlazorComponents\BlazorComponents.csproj" />
20+
</ItemGroup>
21+
1822
</Project>

0 commit comments

Comments
 (0)