Compare commits
No commits in common. "2126cb7644a556c55c7c55a28204ea1befa39878" and "c4ece6e9b7b005e492ed0baa7d751183ae0bbde7" have entirely different histories.
2126cb7644
...
c4ece6e9b7
12
Connected.Components.Showcase/App.razor
Normal file
12
Connected.Components.Showcase/App.razor
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Router AppAssembly="@typeof(App).Assembly">
|
||||||
|
<Found Context="routeData">
|
||||||
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||||
|
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||||
|
</Found>
|
||||||
|
<NotFound>
|
||||||
|
<PageTitle>Not found</PageTitle>
|
||||||
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
|
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||||
|
</LayoutView>
|
||||||
|
</NotFound>
|
||||||
|
</Router>
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
@ -7,8 +7,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-rc.2.22476.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-rc.2.22476.2" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
11
Connected.Components.Showcase/Program.cs
Normal file
11
Connected.Components.Showcase/Program.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using Connected.Components.Showcase;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
|
|
||||||
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||||
|
builder.RootComponents.Add<App>("#app");
|
||||||
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||||
|
|
||||||
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||||
|
|
||||||
|
await builder.Build().RunAsync();
|
@ -4,33 +4,33 @@ namespace Connected.Components;
|
|||||||
|
|
||||||
public abstract class UIComponent : ComponentBase
|
public abstract class UIComponent : ComponentBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// User class names, separated by space.
|
/// User class names, separated by space.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string Class { get; set; }
|
public string Class { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// User styles, applied on top of the component's own classes and styles.
|
/// User styles, applied on top of the component's own classes and styles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string Style { get; set; }
|
public string Style { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use Tag to attach any user data object to the component for your convenience.
|
/// Use Tag to attach any user data object to the component for your convenience.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public object Tag { get; set; }
|
public object Tag { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UserAttributes carries all attributes you add to the component that don't match any of its parameters.
|
/// UserAttributes carries all attributes you add to the component that don't match any of its parameters.
|
||||||
/// They will be splatted onto the underlying HTML tag.
|
/// They will be splatted onto the underlying HTML tag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter(CaptureUnmatchedValues = true)]
|
[Parameter(CaptureUnmatchedValues = true)]
|
||||||
public Dictionary<string, object> UserAttributes { get; set; } = new();
|
public Dictionary<string, object> UserAttributes { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If the UserAttributes contain an ID make it accessible for WCAG labelling of input fields
|
/// If the UserAttributes contain an ID make it accessible for WCAG labelling of input fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FieldId => UserAttributes.TryGetValue("id", out var id) ? id.ToString() : $"input-{Guid.NewGuid()}";
|
public string FieldId => UserAttributes.TryGetValue("id", out var id) ? id.ToString() : $"input-{Guid.NewGuid()}";
|
||||||
}
|
}
|
||||||
|
9
Connected.Components/Layouts/DefaultLayout.razor
Normal file
9
Connected.Components/Layouts/DefaultLayout.razor
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<HeadContent>
|
||||||
|
<link rel="stylesheet" href="_content/Connected.UI/Components.min.css" />
|
||||||
|
<link rel="stylesheet" href="_content/Connected.UI/Styles.min.css" />
|
||||||
|
</HeadContent>
|
||||||
|
|
||||||
|
|
||||||
|
@Body
|
@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace Connected.Middleware;
|
||||||
|
|
||||||
|
internal class ComponentMiddlewareService : IComponentMiddlewareService
|
||||||
|
{
|
||||||
|
public ComponentMiddlewareService()
|
||||||
|
{
|
||||||
|
Middleware = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConcurrentDictionary<string, List<Type>> Middleware { get; }
|
||||||
|
|
||||||
|
public void Add<TMiddleware, TComponent>()
|
||||||
|
{
|
||||||
|
var componentName = typeof(TComponent).FullName;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(componentName))
|
||||||
|
throw new ArgumentException(null, nameof(TMiddleware));
|
||||||
|
|
||||||
|
if (Middleware.TryGetValue(componentName, out List<Type>? items))
|
||||||
|
{
|
||||||
|
//TODO: sort by priority so multiple inheritance would work
|
||||||
|
items.Add(typeof(TMiddleware));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Middleware.TryAdd(componentName, new List<Type> { typeof(TMiddleware) });
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type? Select<TComponent>()
|
||||||
|
{
|
||||||
|
var typeName = typeof(TComponent).FullName;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(typeName))
|
||||||
|
throw new ArgumentException(null, nameof(TComponent));
|
||||||
|
|
||||||
|
if (Middleware.TryGetValue(typeName, out List<Type>? items) && items is not null && items.Any())
|
||||||
|
return items[0];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace Connected.Middleware;
|
||||||
|
|
||||||
|
public interface IComponentMiddlewareService
|
||||||
|
{
|
||||||
|
void Add<TMiddleware, TComponent>();
|
||||||
|
|
||||||
|
Type? Select<TComponent>();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user