Skip to content

Commit

Permalink
Add shared blazor project
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Apr 1, 2024
1 parent 960f1a3 commit 5b8f73f
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sources/Clients.Admin.Web/Clients.Admin.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Clients.Identity.Blazor.Shared\Clients.Identity.Blazor.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<RootNamespace>MadWorldNL.Clients.Identity.Blazor.Shared</RootNamespace>
<AssemblyName>$(RootNamespace)</AssemblyName>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.2"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Clients.Identity.Api.Contracts\Clients.Identity.Api.Contracts.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions sources/Clients.Identity.Blazor.Shared/Component1.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="my-component">
This component is defined in the <strong>Clients.Identity.Blazor.Shared</strong> library.
</div>
6 changes: 6 additions & 0 deletions sources/Clients.Identity.Blazor.Shared/Component1.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.my-component {
border: 2px dashed red;
padding: 1em;
margin: 1em 0;
background-image: url('background.png');
}
36 changes: 36 additions & 0 deletions sources/Clients.Identity.Blazor.Shared/ExampleJsInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.JSInterop;

namespace Clients.Identity.Blazor.Shared;

// This class provides an example of how JavaScript functionality can be wrapped
// in a .NET class for easy consumption. The associated JavaScript module is
// loaded on demand when first needed.
//
// This class can be registered as scoped DI service and then injected into Blazor
// components for use.

public class ExampleJsInterop : IAsyncDisposable
{
private readonly Lazy<Task<IJSObjectReference>> moduleTask;

public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/Clients.Identity.Blazor.Shared/exampleJsInterop.js").AsTask());
}

public async ValueTask<string> Prompt(string message)
{
var module = await moduleTask.Value;
return await module.InvokeAsync<string>("showPrompt", message);
}

public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}
1 change: 1 addition & 0 deletions sources/Clients.Identity.Blazor.Shared/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@using Microsoft.AspNetCore.Components.Web
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This is a JavaScript module that is loaded on demand. It can export any number of
// functions, and may import other JavaScript modules if required.

export function showPrompt(message) {
return prompt(message, 'Type anything here');
}
7 changes: 7 additions & 0 deletions sources/MadWorldNL.Identity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{F11E5F
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Identity.Api.Contracts", "Clients.Identity.Api.Contracts\Clients.Identity.Api.Contracts.csproj", "{6EE2F699-9915-4D62-96DB-5361C5094193}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Identity.Blazor.Shared", "Clients.Identity.Blazor.Shared\Clients.Identity.Blazor.Shared.csproj", "{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -75,6 +77,7 @@ Global
{F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{7F925140-B483-461E-9740-646E40771F4E} = {F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}
{6EE2F699-9915-4D62-96DB-5361C5094193} = {F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}
{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA} = {F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2B04007E-B2D9-4E8B-82D2-C553CD5F3DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -121,5 +124,9 @@ Global
{6EE2F699-9915-4D62-96DB-5361C5094193}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Release|Any CPU.Build.0 = Release|Any CPU
{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20A178D0-8AA7-4DAE-A866-E8BFB4F362FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit 5b8f73f

Please sign in to comment.