From 5b8f73f51eea5cddc52e72d5f813cae9c775955f Mon Sep 17 00:00:00 2001 From: Oscar Veldman Date: Mon, 1 Apr 2024 11:12:02 +0200 Subject: [PATCH] Add shared blazor project --- .../Clients.Admin.Web.csproj | 4 ++ .../Clients.Identity.Blazor.Shared.csproj | 20 ++++++++++ .../Component1.razor | 3 ++ .../Component1.razor.css | 6 +++ .../ExampleJsInterop.cs | 36 ++++++++++++++++++ .../_Imports.razor | 1 + .../wwwroot/background.png | Bin 0 -> 378 bytes .../wwwroot/exampleJsInterop.js | 6 +++ sources/MadWorldNL.Identity.sln | 7 ++++ 9 files changed, 83 insertions(+) create mode 100644 sources/Clients.Identity.Blazor.Shared/Clients.Identity.Blazor.Shared.csproj create mode 100644 sources/Clients.Identity.Blazor.Shared/Component1.razor create mode 100644 sources/Clients.Identity.Blazor.Shared/Component1.razor.css create mode 100644 sources/Clients.Identity.Blazor.Shared/ExampleJsInterop.cs create mode 100644 sources/Clients.Identity.Blazor.Shared/_Imports.razor create mode 100644 sources/Clients.Identity.Blazor.Shared/wwwroot/background.png create mode 100644 sources/Clients.Identity.Blazor.Shared/wwwroot/exampleJsInterop.js diff --git a/sources/Clients.Admin.Web/Clients.Admin.Web.csproj b/sources/Clients.Admin.Web/Clients.Admin.Web.csproj index 9545eba..2bb1d05 100644 --- a/sources/Clients.Admin.Web/Clients.Admin.Web.csproj +++ b/sources/Clients.Admin.Web/Clients.Admin.Web.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/sources/Clients.Identity.Blazor.Shared/Clients.Identity.Blazor.Shared.csproj b/sources/Clients.Identity.Blazor.Shared/Clients.Identity.Blazor.Shared.csproj new file mode 100644 index 0000000..2ec713d --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/Clients.Identity.Blazor.Shared.csproj @@ -0,0 +1,20 @@ + + + + MadWorldNL.Clients.Identity.Blazor.Shared + $(RootNamespace) + + + + + + + + + + + + + + + diff --git a/sources/Clients.Identity.Blazor.Shared/Component1.razor b/sources/Clients.Identity.Blazor.Shared/Component1.razor new file mode 100644 index 0000000..e216aff --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/Component1.razor @@ -0,0 +1,3 @@ +
+ This component is defined in the Clients.Identity.Blazor.Shared library. +
\ No newline at end of file diff --git a/sources/Clients.Identity.Blazor.Shared/Component1.razor.css b/sources/Clients.Identity.Blazor.Shared/Component1.razor.css new file mode 100644 index 0000000..c6afca4 --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/Component1.razor.css @@ -0,0 +1,6 @@ +.my-component { + border: 2px dashed red; + padding: 1em; + margin: 1em 0; + background-image: url('background.png'); +} diff --git a/sources/Clients.Identity.Blazor.Shared/ExampleJsInterop.cs b/sources/Clients.Identity.Blazor.Shared/ExampleJsInterop.cs new file mode 100644 index 0000000..be8e28a --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/ExampleJsInterop.cs @@ -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> moduleTask; + + public ExampleJsInterop(IJSRuntime jsRuntime) + { + moduleTask = new(() => jsRuntime.InvokeAsync( + "import", "./_content/Clients.Identity.Blazor.Shared/exampleJsInterop.js").AsTask()); + } + + public async ValueTask Prompt(string message) + { + var module = await moduleTask.Value; + return await module.InvokeAsync("showPrompt", message); + } + + public async ValueTask DisposeAsync() + { + if (moduleTask.IsValueCreated) + { + var module = await moduleTask.Value; + await module.DisposeAsync(); + } + } +} \ No newline at end of file diff --git a/sources/Clients.Identity.Blazor.Shared/_Imports.razor b/sources/Clients.Identity.Blazor.Shared/_Imports.razor new file mode 100644 index 0000000..c3615ef --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/_Imports.razor @@ -0,0 +1 @@ +@using Microsoft.AspNetCore.Components.Web \ No newline at end of file diff --git a/sources/Clients.Identity.Blazor.Shared/wwwroot/background.png b/sources/Clients.Identity.Blazor.Shared/wwwroot/background.png new file mode 100644 index 0000000000000000000000000000000000000000..e15a3bde6e2bdb380df6a0b46d7ed00bdeb0aaa8 GIT binary patch literal 378 zcmeAS@N?(olHy`uVBq!ia0vp^x**KK1SGdsl%54rjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwr2>%=KS^ie7oTIEF;HpS|GCbyPusHSqiXaCu3qf)82(9Gq&mZq2{Kq}M*X&MWtJ zSi1Jo7ZzfImg%g=t(qo=wsSR2lZoP(Rj#3wacN=q0?Br(rXzgZEGK2$ID{|A=5S{xJEuzSH>!M+7wSY6hB<=-E^*n0W7 S8wY^CX7F_Nb6Mw<&;$S{dxtsz literal 0 HcmV?d00001 diff --git a/sources/Clients.Identity.Blazor.Shared/wwwroot/exampleJsInterop.js b/sources/Clients.Identity.Blazor.Shared/wwwroot/exampleJsInterop.js new file mode 100644 index 0000000..ea8d76a --- /dev/null +++ b/sources/Clients.Identity.Blazor.Shared/wwwroot/exampleJsInterop.js @@ -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'); +} diff --git a/sources/MadWorldNL.Identity.sln b/sources/MadWorldNL.Identity.sln index 55d5534..3243ac7 100644 --- a/sources/MadWorldNL.Identity.sln +++ b/sources/MadWorldNL.Identity.sln @@ -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 @@ -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 @@ -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