Skip to content

Commit 6186df4

Browse files
Version 0.1.0-beta-3
Added BlockCss Fixed restore CSS in Razor Components
1 parent bf7701b commit 6186df4

File tree

15 files changed

+374
-94
lines changed

15 files changed

+374
-94
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<PropertyGroup>
33
<BlazorVersion>0.9.0-preview3-19154-02</BlazorVersion>
44
<AspNetCoreVersion>3.0.0-preview3-19153-02</AspNetCoreVersion>
5-
<ReleaseVersion>0.1.0-beta-2</ReleaseVersion>
5+
<ReleaseVersion>0.1.0-beta-3</ReleaseVersion>
66
</PropertyGroup>
77
</Project>

README.md

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11

22
# BlazorEmbedLibrary
33

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

6-
Projects in this repo:
7-
8-
## BlazorEmbedLibrary
6+
Chanegelog:
97

10-
This is the component library that provides all the functionality.
11-
12-
It is a netstandard component library (i.e. a netstandard2.0 library) with one c# code file.
8+
#### Version 0.1.0-beta-3
9+
- Restructure source folders
10+
- Add ability to handle multiple component assemblies in one go
11+
- Add ability to block specific content files
12+
-- Including in Blazor
1313

14-
### BlazorComponentSample
15-
16-
An out-of-the-box sample Blazor component library with static files.
17-
18-
### BlazorEmbedContent - Runnable
14+
#### Version 0.1.0-beta-2
15+
- Add compatibility with Pre-Rendering
1916

20-
A sample Blazor app to show how this library detects if Blazor has already linked the static files, and does not duplicate them.
17+
#### Version 0.1.0-beta-1
18+
- Initial release
19+
- Enable support for embedded content files (CSS/JS) in Razor Components
2120

22-
### RazorComponentsSample.App
21+
Projects in this repo:
2322

24-
A sample Razor Components app to show static files working.
23+
## BlazorEmbedLibrary
2524

26-
### RazorComponentsSample.Server - Runnable
25+
This is the component library that provides all the functionality.
2726

28-
A sample Razor Components server to show static files working.
27+
It is a netstandard component library (i.e. a netstandard2.0 library) with one c# code file.
2928

3029
## How to use this library
3130

@@ -50,7 +49,66 @@ Note, by default the EmbeddedContent component has Debug turned off - if you ena
5049

5150
This will read any CSS or Js files, which are embedded resources, from the Component1 library and add them to the `head` of the document.
5251

53-
## Examples
52+
### Multiple Assemblies
53+
54+
From version 0.1.0-beta-3 onwards, you can now handle multiple component libraries in one hit using the Assemblies Parameter
55+
56+
```
57+
<EmbeddedContent Assemblies="@Assemblies" />
58+
59+
@functions
60+
{
61+
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
62+
{
63+
typeof(BlazorComponentSample.Component1).Assembly,
64+
typeof(Blazored.Toast.BlazoredToasts).Assembly
65+
};
66+
}
67+
68+
```
69+
70+
### Block Files
71+
72+
From version 0.1.0-beta-3 onwards, you can now block individual files using the BlockCss Parameter
73+
74+
This example will load content from Blazored.Toast and Component1, but will block the *styles.css* from BlazorComponentSample.
75+
76+
```
77+
<EmbeddedContent Assemblies="@Assemblies" BlockCssFiles="@BlockCss" />
78+
79+
@functions
80+
{
81+
List<string> BlockCss = new List<string>()
82+
{
83+
"BlazorComponentSample,styles.css"
84+
};
85+
86+
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
87+
{
88+
typeof(BlazorComponentSample.Component1).Assembly,
89+
typeof(Blazored.Toast.BlazoredToasts).Assembly
90+
};
91+
}
92+
93+
```
94+
95+
## Sample Projects
96+
97+
I have included Blazored.Toast and a simple custom component in the Razorcomponents and Blazor Apps
98+
99+
100+
### BlazorComponentSample
101+
102+
An out-of-the-box sample Blazor component library with static files.
103+
104+
### BlazorEmbedContent - Runnable
105+
106+
A sample Blazor app to show how this library detects if Blazor has already linked the static files, and does not duplicate them.
107+
108+
Also shows how we can toggle CSS files on/off at runtime.
109+
110+
### RazorComponentsSample.Server - Runnable
54111

55-
I have included Blazored.LocalStorage and Blazored.Toast examples in the Razorcomponents App
112+
A sample Razor Components App to show static files working.
56113

114+
Also shows how we can toggle CSS files on/off at runtime.

samples/BlazorEmbedContent/BlazorEmbedContent.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="Blazored.Toast" Version="1.0.3" />
1112
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
1213
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
1314

samples/BlazorEmbedContent/Pages/Index.cshtml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ Welcome to your new app.
66

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

9-
<EmbeddedContent BaseType="@(typeof(Component1))" />
10-
<EmbeddedContent BaseType="@(typeof(Component1))" />
11-
<EmbeddedContent BaseType="@(typeof(EmbeddedContent))" />
12-
139
<Component1 />
1410

11+
@inject IToastService toastService
12+
13+
<h1>Toast Demo</h1>
14+
15+
To show a toast just click one of the buttons below.
16+
17+
<button class="btn btn-info" onclick="@(() => toastService.ShowToast(ToastLevel.Info, "I'm an INFO message"))">Info Toast</button>
18+
<button class="btn btn-success" onclick="@(() => toastService.ShowToast(ToastLevel.Success, "I'm a SUCCESS message with a custom title", "Congratulations!"))">Success Toast</button>
19+
<button class="btn btn-warning" onclick="@(() => toastService.ShowToast(ToastLevel.Warning, "I'm a WARNING message"))">Warning Toast</button>
20+
<button class="btn btn-danger" onclick="@(() => toastService.ShowToast(ToastLevel.Error, "I'm an ERROR message"))">Error Toast</button>
21+
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
@layout MainLayout
2-
@using BlazorEmbedLibrary
3-
@using BlazorComponentSample
4-
@addTagHelper *, BlazorEmbedLibrary
5-
@addTagHelper *, BlazorComponentSample
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
11
@inherits LayoutComponentBase
2-
32
<div class="sidebar">
43
<NavMenu />
54
</div>
65

76
<div class="main">
87
<div class="top-row px-4">
9-
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
8+
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank" class="ml-md-auto">About</a>
109
</div>
1110

1211
<div class="content px-4">
1312
@Body
13+
@**@
14+
<hr />
15+
<button class="btn btn-dark" onclick="@SwitchEmbedding">Switch Embedding Test</button>
16+
@if (EmbedSwitch)
17+
{
18+
<div>@(new MarkupString("<EmbeddedContent Assemblies=\"@Assemblies\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
19+
<EmbeddedContent Assemblies="@Assemblies" Debug="true" BlockCssFiles="@BlockCss" />
20+
}
21+
else
22+
{
23+
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
24+
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />
25+
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Component1))\" Debug=\"true\" />").Value)</div>
26+
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
27+
}
28+
<BlazoredToasts />
1429
</div>
1530
</div>
31+
32+
33+
@functions
34+
{
35+
bool EmbedSwitch;
36+
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
37+
{
38+
typeof(BlazorComponentSample.Component1).Assembly,
39+
typeof(Blazored.Toast.BlazoredToasts).Assembly
40+
};
41+
List<string> BlockCss = new List<string>()
42+
{
43+
"BlazorComponentSample,styles.css"
44+
};
45+
void SwitchEmbedding(UIMouseEventArgs args)
46+
{
47+
EmbedSwitch = !EmbedSwitch;
48+
}
49+
50+
}

samples/BlazorEmbedContent/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Blazored.Toast.Services;
12
using Microsoft.AspNetCore.Components.Builder;
23
using Microsoft.Extensions.DependencyInjection;
34

@@ -7,6 +8,7 @@ public class Startup
78
{
89
public void ConfigureServices(IServiceCollection services)
910
{
11+
services.AddScoped<IToastService, ToastService>();
1012
}
1113

1214
public void Configure(IComponentsApplicationBuilder app)

samples/BlazorEmbedContent/_ViewImports.cshtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
@using Microsoft.JSInterop
55
@using BlazorEmbedContent
66
@using BlazorEmbedContent.Shared
7+
@using BlazorComponentSample
8+
@using BlazorEmbedLibrary
9+
@using Blazored.Toast.Services
10+
@addTagHelper *, BlazorComponentSample
11+
@addTagHelper *, BlazorEmbedLibrary
12+
@addTagHelper *, Blazored.Toast

samples/RazorComponentsSample/RazorComponentsSample.Server/Components/Pages/Index.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Welcome to your new app.
66

7-
<EmbeddedContent BaseType="@(typeof(Component1))" />
8-
97
<Component1 />
108

119
@inject IToastService toastService

samples/RazorComponentsSample/RazorComponentsSample.Server/Components/Shared/MainLayout.razor

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
@inherits LayoutComponentBase
2-
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="false"/>
3-
<BlazoredToasts />
42
<div class="sidebar">
53
<NavMenu />
64
</div>
@@ -12,5 +10,41 @@
1210

1311
<div class="content px-4">
1412
@Body
13+
@**@
14+
<hr />
15+
<button class="btn btn-dark" onclick="@SwitchEmbedding">Switch Embedding Test</button>
16+
@if (EmbedSwitch)
17+
{
18+
<div>@(new MarkupString("<EmbeddedContent Assemblies=\"@Assemblies\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
19+
<EmbeddedContent Assemblies="@Assemblies" Debug="true" BlockCssFiles="@BlockCss" />
20+
}
21+
else
22+
{
23+
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
24+
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />
25+
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Component1))\" Debug=\"true\" />").Value)</div>
26+
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
27+
}
28+
<BlazoredToasts />
1529
</div>
1630
</div>
31+
32+
33+
@functions
34+
{
35+
bool EmbedSwitch;
36+
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
37+
{
38+
typeof(BlazorComponentSample.Component1).Assembly,
39+
typeof(Blazored.Toast.BlazoredToasts).Assembly
40+
};
41+
List<string> BlockCss = new List<string>()
42+
{
43+
"BlazorComponentSample,styles.css"
44+
};
45+
void SwitchEmbedding(UIMouseEventArgs args)
46+
{
47+
EmbedSwitch = !EmbedSwitch;
48+
}
49+
50+
}

0 commit comments

Comments
 (0)