This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support components and static content in external NuGet packages (#247)
* On build, drop <BlazorPackageContentFiles> items into dist\_content\(PackageName)\ * Add <script> and <link> tags to generated index.html * Add testapp coverage of external content package. Still need to add E2E tests that uses it. * Add missing unit test update * Add example of packaging an entire Blazor component including CSS and images * Add E2E test for component from NuGet package
- Loading branch information
1 parent
6eadc43
commit 5ec0292
Showing
17 changed files
with
265 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@addTagHelper *, TestContentPackage | ||
@using TestContentPackage | ||
|
||
<h1>Functionality and content from an external package</h1> | ||
|
||
<p> | ||
NuGet packages can embed .NET code, which can in turn call Blazor's | ||
JS interop features if desired. This can be used to distribute new | ||
browser APIs as NuGet packages. | ||
</p> | ||
|
||
<p>Click the following button to invoke a JavaScript function.</p> | ||
|
||
<button @onclick(ShowJavaScriptPrompt)>Show JavaScript prompt</button> | ||
|
||
@if (!string.IsNullOrEmpty(result)) | ||
{ | ||
<p>Result: <strong>@result</strong></p> | ||
} | ||
|
||
<hr /> | ||
|
||
<p> | ||
Additionally, NuGet packages can contain Blazor components, and even | ||
static resources such as CSS files and images. | ||
</p> | ||
|
||
<ComponentFromPackage /> | ||
|
||
@functions | ||
{ | ||
string result; | ||
|
||
void ShowJavaScriptPrompt() | ||
{ | ||
result = MyPrompt.Show("Hello!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/testapps/TestContentPackage/ComponentFromPackage.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="special-style"> | ||
This component, including the CSS and image required to produce its | ||
elegant styling, is in an external NuGet package. | ||
<button @onclick(ChangeLabel)>@buttonLabel </button> | ||
</div> | ||
|
||
@functions | ||
{ | ||
string buttonLabel = "Click me"; | ||
|
||
void ChangeLabel() | ||
{ | ||
buttonLabel = "It works"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Blazor.Browser.Interop; | ||
|
||
namespace TestContentPackage | ||
{ | ||
public static class MyPrompt | ||
{ | ||
// Keep in sync with the identifier in the .js file | ||
const string ShowPromptIdentifier = "TestContentPackage.showPrompt"; | ||
|
||
public static string Show(string message) | ||
{ | ||
return RegisteredFunction.Invoke<string>( | ||
ShowPromptIdentifier, | ||
message); | ||
} | ||
} | ||
} |
Oops, something went wrong.