Skip to content

Commit

Permalink
Version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
SQL-MisterMagoo committed Sep 15, 2019
1 parent a6de699 commit 852e23a
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 101 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<BlazorVersion>0.9.0-preview3-19154-02</BlazorVersion>
<AspNetCoreVersion>3.0.0-preview3-19153-02</AspNetCoreVersion>
<ReleaseVersion>0.1.0-beta-4</ReleaseVersion>
<BlazorVersion>3.0.0-preview9.19424.4</BlazorVersion>
<AspNetCoreVersion>3.0.0-preview9.19424.4</AspNetCoreVersion>
<ReleaseVersion>1.0.0</ReleaseVersion>
</PropertyGroup>
</Project>
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

This is a component library that provides Blazor-style static file embedding for Razor Components/Blazor.

Chanegelog:
Changelog:

#### Version 1.0.0
- Update to Preview9

#### Version 0.1.0-beta-4
- Add BlazorFileProvider : Static File Provider that serves embedded files from Blazor Libraries
Expand Down Expand Up @@ -38,17 +41,34 @@ https://www.nuget.org/packages/BlazorEmbedLibrary/

#### Using the EmbeddedComponent to extract CSS/JS files

Add a *Using* and an *addTagHelper* to the __ViewImports file
I recommend placing this in your MainLayout (or equivalent), but you can do it on individual pages if that suits your project.

```
Add a *Using* statement to the page to make it easier to reference the component

*MainLayout.razor*
``` C#
@using BlazorEmbedLibrary
@addTagHelper *, BlazorEmbedLibrary
```

Then add the component to whichever page you want e.g. MainLayout, Index.cshtml - wherever makes sense for your project/needs.
...add the component :

``` HTML
<EmbeddedContent BaseType="@(typeof(Component1))" />
```
<EmbeddedContent BaseType="@(typeof(Component1))" />
``` C#
@code
{
bool hasConnected = false;
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (firstRender)
{
StateHasChanged();
hasConnected = true;
}
}
}
```

Note, by default the EmbeddedContent component has Debug turned off - if you enable it by setting Debug=true, it outputs the list of embedded resources.
Expand All @@ -62,7 +82,7 @@ From version 0.1.0-beta-3 onwards, you can now handle multiple component librari
```
<EmbeddedContent Assemblies="@Assemblies" />
@functions
@code
{
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
{
Expand All @@ -82,7 +102,7 @@ This example will load content from Blazored.Toast and Component1, but will bloc
```
<EmbeddedContent Assemblies="@Assemblies" BlockCssFiles="@BlockCss" />
@functions
@code
{
List<string> BlockCss = new List<string>()
{
Expand Down
17 changes: 12 additions & 5 deletions samples/BlazorComponentSample/BlazorComponentSample.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<LangVersion>latest</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,10 +18,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
<None Remove="Component1.razor" />
</ItemGroup>

<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(BlazorVersion)" />
<ItemGroup>
<Content Include="Component1.razor" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview9.19424.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
@using Microsoft.AspNetCore.Components
@inherits ComponentBase
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@inherits ComponentBase
@inject IJSRuntime jSRuntime

<div class="my-component">
This Blazor component is defined in the <strong>BlazorComponentSample</strong> package.
</div>

<button onclick="@OnClick">Click Me!</button>
<button @onclick="()=>OnClick()">Click Me!</button>


@functions
@code
{
Task OnClick(UIMouseEventArgs args)
ValueTask<string> OnClick()
{
return ExampleJsInterop.Prompt(jSRuntime,"you clicked me");
}
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorComponentSample/ExampleJsInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BlazorComponentSample
{
public class ExampleJsInterop
{
public static Task<string> Prompt(IJSRuntime jSRuntime, string message)
public static ValueTask<string> Prompt(IJSRuntime jSRuntime, string message)
{
// Implemented in exampleJsInterop.js
return jSRuntime.InvokeAsync<string>(
Expand Down
5 changes: 0 additions & 5 deletions samples/BlazorEmbedContent/App.cshtml

This file was deleted.

10 changes: 10 additions & 0 deletions samples/BlazorEmbedContent/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
14 changes: 7 additions & 7 deletions samples/BlazorEmbedContent/BlazorEmbedContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RunCommand>dotnet</RunCommand>
<RunArguments>blazor serve</RunArguments>
<OutputType>Exe</OutputType>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazored.Toast" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />

<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(BlazorVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<p>Current count: @currentCount</p>

<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@functions {
int currentCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else
@functions {
WeatherForecast[] forecasts;

protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
Expand Down
21 changes: 0 additions & 21 deletions samples/BlazorEmbedContent/Pages/Index.cshtml

This file was deleted.

21 changes: 21 additions & 0 deletions samples/BlazorEmbedContent/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<BlazorComponentSample.Component1 />

@*@inject IToastService toastService*@

<h1>Toast Demo</h1>

To show a toast just click one of the buttons below.

@*<button class="btn btn-info" @onclick="@(() => toastService.ShowToast(ToastLevel.Info, "I'm an INFO message"))">Info Toast</button>
<button class="btn btn-success" @onclick="@(() => toastService.ShowToast(ToastLevel.Success, "I'm a SUCCESS message with a custom title", "Congratulations!"))">Success Toast</button>
<button class="btn btn-warning" @onclick="@(() => toastService.ShowToast(ToastLevel.Warning, "I'm a WARNING message"))">Warning Toast</button>
<button class="btn btn-danger" @onclick="@(() => toastService.ShowToast(ToastLevel.Error, "I'm an ERROR message"))">Error Toast</button>*@

Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@
@Body
@**@
<hr />
<button class="btn btn-dark" onclick="@SwitchEmbedding">Switch Embedding Test</button>
<button @ ></button>
<button class="btn btn-dark" @onclick="@(()=>SwitchEmbedding())">Switch Embedding Test</button>
@if (EmbedSwitch)
{
<div>@(new MarkupString("<EmbeddedContent Assemblies=\"@Assemblies\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
<EmbeddedContent Assemblies="@Assemblies" Debug="true" BlockCssFiles="@BlockCss" />
}
else
{
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />
@*<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />*@
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Component1))\" Debug=\"true\" />").Value)</div>
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
}
<BlazoredToasts />
@*<BlazoredToasts />*@
</div>
</div>


@functions
@code
{
bool EmbedSwitch;
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
{
typeof(BlazorComponentSample.Component1).Assembly,
typeof(Blazored.Toast.BlazoredToasts).Assembly
//typeof(Blazored.Toast.BlazoredToasts).Assembly
};
List<string> BlockCss = new List<string>()
List<string> BlockCss = new List<string>()
{
"BlazorComponentSample,styles.css"
};
void SwitchEmbedding(UIMouseEventArgs args)
void SwitchEmbedding()
{
EmbedSwitch = !EmbedSwitch;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<div class="top-row pl-4 navbar navbar-dark">

<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">BlazorEmbedContent</a>
<button class="navbar-toggler" onclick="@ToggleNavMenu">
<button class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>

<div class="@NavMenuCssClass" onclick="@ToggleNavMenu">
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<ul class="nav flex-column">
<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
Expand All @@ -25,7 +26,7 @@
</ul>
</div>

@functions {
@code {
bool collapseNavMenu = true;

string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

@functions {
// Demonstrates how a parent component can supply parameters
[Parameter] string Title { get; set; }
[Parameter] public string Title { get; set; }
}
4 changes: 2 additions & 2 deletions samples/BlazorEmbedContent/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Blazored.Toast.Services;
//using Blazored.Toast.Services;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -8,7 +8,7 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IToastService, ToastService>();
//services.AddScoped<IToastService, ToastService>();
}

public void Configure(IComponentsApplicationBuilder app)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorEmbedContent
@using BlazorEmbedContent.Shared
@using BlazorComponentSample
@using BlazorEmbedLibrary
@using Blazored.Toast.Services
@addTagHelper *, BlazorComponentSample
@addTagHelper *, BlazorEmbedLibrary
@addTagHelper *, Blazored.Toast
@*@using Blazored.Toast.Services*@

2 changes: 1 addition & 1 deletion samples/BlazorEmbedContent/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<body>
<app>Loading...</app>

<script src="_framework/components.webassembly.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
</body>
</html>
Loading

0 comments on commit 852e23a

Please sign in to comment.