From 4bdc4799b7a1e476999a9e9340e23e43d2141168 Mon Sep 17 00:00:00 2001 From: Erin McLaughlin Date: Thu, 16 May 2024 17:51:44 -0400 Subject: [PATCH] prefix component names with "HB" --- .../HeadManipulationService.cs | 38 --------------- .../HeadlessBlazor.Docs.Client/Home.razor | 28 +++++------ .../HeadlessBlazor.Docs.Client/Program.cs | 3 -- .../HeadlessBlazor.Docs/Components/App.razor | 33 +------------ .../HeadlessBlazor.Docs/Program.cs | 3 -- .../wwwroot/js/headManipulation.js | 46 ------------------- .../{Dropdown.cs => HBDropdown.cs} | 12 ++--- .../{DropdownItem.cs => HBDropdownItem.cs} | 6 +-- ...nItemButton.cs => HBDropdownItemButton.cs} | 2 +- ...pdownItemLink.cs => HBDropdownItemLink.cs} | 2 +- .../{DropdownItems.cs => HBDropdownItems.cs} | 6 +-- ...r.cs => HBDropdownOutsideClickBehavior.cs} | 7 ++- ...ropdownTrigger.cs => HBDropdownTrigger.cs} | 6 +-- .../HBBootstrapThemeConfiguration.cs | 12 ++--- .../HBTailwindThemeConfiguration.cs | 12 ++--- 15 files changed, 48 insertions(+), 168 deletions(-) delete mode 100644 docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/HeadManipulationService.cs delete mode 100644 docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/wwwroot/js/headManipulation.js rename src/HeadlessBlazor.Dropdown/{Dropdown.cs => HBDropdown.cs} (79%) rename src/HeadlessBlazor.Dropdown/{DropdownItem.cs => HBDropdownItem.cs} (78%) rename src/HeadlessBlazor.Dropdown/{DropdownItemButton.cs => HBDropdownItemButton.cs} (66%) rename src/HeadlessBlazor.Dropdown/{DropdownItemLink.cs => HBDropdownItemLink.cs} (65%) rename src/HeadlessBlazor.Dropdown/{DropdownItems.cs => HBDropdownItems.cs} (75%) rename src/HeadlessBlazor.Dropdown/{DropdownOutsideClickBehavior.cs => HBDropdownOutsideClickBehavior.cs} (73%) rename src/HeadlessBlazor.Dropdown/{DropdownTrigger.cs => HBDropdownTrigger.cs} (85%) diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/HeadManipulationService.cs b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/HeadManipulationService.cs deleted file mode 100644 index 13f3933..0000000 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/HeadManipulationService.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.JSInterop; - -namespace HeadlessBlazor.Docs.Client; - -public class HeadManipulationService(IJSRuntime jsRuntime) -{ - private readonly IJSRuntime _jsRuntime = jsRuntime; - - public ValueTask SetTheme(string theme) - { - return _jsRuntime.InvokeVoidAsync("headManipulation.setTheme", theme); - } - - public ValueTask AddLinkAsync(string href, string rel) - { - return _jsRuntime.InvokeVoidAsync("headManipulation.addLink", href, rel); - } - - public ValueTask RemoveLinkAsync(string href) - { - return _jsRuntime.InvokeVoidAsync("headManipulation.removeLink", href); - } - - public ValueTask AddScriptAsync(string src) - { - return _jsRuntime.InvokeVoidAsync("headManipulation.addScript", src); - } - - public ValueTask RemoveScriptAsync(string src) - { - return _jsRuntime.InvokeVoidAsync("headManipulation.removeScript", src); - } - - public ValueTask RemoveStyleAsync() - { - return _jsRuntime.InvokeVoidAsync("headManipulation.removeStyle"); - } -} diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Home.razor b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Home.razor index 7725dbb..3b61a03 100644 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Home.razor +++ b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Home.razor @@ -7,20 +7,20 @@
- - - Click Me - - Default - Button - Disabled Button - Button (Stop Propagation) - Link - Link (Prevent Default) - Link (Stop Propagation) - Link (Prevent Default and Stop Propagation) - - + + + Click Me + + Default + Button + Disabled Button + Button (Stop Propagation) + Link + Link (Prevent Default) + Link (Stop Propagation) + Link (Prevent Default and Stop Propagation) + +
@Example1CodeBlock
diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Program.cs b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Program.cs index dd072f0..e8f4ae7 100644 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Program.cs +++ b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Program.cs @@ -1,13 +1,10 @@ using HeadlessBlazor; -using HeadlessBlazor.Docs.Client; using HeadlessBlazor.Themes.Bootstrap; using HeadlessBlazor.Themes.Tailwind; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; var builder = WebAssemblyHostBuilder.CreateDefault(args); -builder.Services.AddScoped(); - builder.Services .AddHeadlessBlazor() .AddBootstrapTheme() diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Components/App.razor b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Components/App.razor index abe6a92..db7feed 100644 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Components/App.razor +++ b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Components/App.razor @@ -1,9 +1,5 @@ -@using HeadlessBlazor.Core.Themes -@inject HBThemeFactory ThemeFactory -@implements IDisposable - - - + + @@ -19,7 +15,6 @@ -
@Theme
@@ -27,27 +22,3 @@ -@code { - private string Theme { get; set; } = "Bootstrap"; - - private ElementReference Root; - - public void Dispose() - { - ThemeFactory.ThemeChanged -= HandleThemeChanged; - } - - protected override void OnInitialized() - { - ThemeFactory.ThemeChanged += HandleThemeChanged; - } - - private void HandleThemeChanged(string theme) - { - InvokeAsync(() => - { - Theme = theme; - StateHasChanged(); - }); - } -} diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Program.cs b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Program.cs index 1cbd57b..82c3150 100644 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Program.cs +++ b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Program.cs @@ -1,13 +1,10 @@ using HeadlessBlazor; -using HeadlessBlazor.Docs.Client; using HeadlessBlazor.Docs.Components; using HeadlessBlazor.Themes.Bootstrap; using HeadlessBlazor.Themes.Tailwind; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddScoped(); - builder.Services .AddHeadlessBlazor() .AddBootstrapTheme() diff --git a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/wwwroot/js/headManipulation.js b/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/wwwroot/js/headManipulation.js deleted file mode 100644 index 9ad2e77..0000000 --- a/docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/wwwroot/js/headManipulation.js +++ /dev/null @@ -1,46 +0,0 @@ -window.headManipulation = { - setTheme: function (theme) { - document.documentElement.setAttribute('hb-theme', theme); - }, - addLink: function (href, rel) { - var link = document.createElement('link'); - link.href = href; - link.rel = rel; - document.head.appendChild(link); - }, - removeLink: function (href) { - console.log('removing link: ' + href); - var links = document.head.getElementsByTagName('link'); - for (var i = 0; i < links.length; i++) { - if (links[i].href === href) { - document.head.removeChild(links[i]); - break; - } - } - }, - addScript: function (src) { - var script = document.createElement('script'); - script.src = src; - script.async = true; - document.head.appendChild(script); - }, - removeScript: function (src) { - console.log('removing script: ' + src); - var scripts = document.head.getElementsByTagName('script'); - for (var i = 0; i < scripts.length; i++) { - if (scripts[i].src === src) { - document.head.removeChild(scripts[i]); - break; - } - } - }, - removeStyle: function () { - console.log('removing style'); - var s = document.head.getElementsByTagName('style'); - if (s) { - for (var i = 0; i < s.length; i++) { - document.head.removeChild(s[i]); - } - } - } -}; diff --git a/src/HeadlessBlazor.Dropdown/Dropdown.cs b/src/HeadlessBlazor.Dropdown/HBDropdown.cs similarity index 79% rename from src/HeadlessBlazor.Dropdown/Dropdown.cs rename to src/HeadlessBlazor.Dropdown/HBDropdown.cs index 3d2340b..4ae713f 100644 --- a/src/HeadlessBlazor.Dropdown/Dropdown.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdown.cs @@ -4,12 +4,12 @@ namespace HeadlessBlazor; -public class Dropdown : HBElement +public class HBDropdown : HBElement { public bool IsOpen { get; private set; } [Parameter] - public EventCallback OnClickItem { get; set; } + public EventCallback OnClickItem { get; set; } public async Task Toggle() => await SetIsOpen(!IsOpen); public async Task Open() => await SetIsOpen(true); @@ -17,16 +17,16 @@ public class Dropdown : HBElement protected override void OnInitialized() { - if (!OnClickItem.HasDelegate) - OnClickItem = new EventCallback(this, Close); - base.OnInitialized(); + + if (!OnClickItem.HasDelegate) + OnClickItem = new EventCallback(this, Close); } protected override void BuildRenderTree(RenderTreeBuilder builder) { var seq = 0; - builder.OpenComponent>(seq++); + builder.OpenComponent>(seq++); builder.AddAttribute(seq, "Value", this); builder.AddAttribute(seq++, "ChildContent", (RenderFragment)((b) => BuildRenderTree(b, ref seq))); builder.CloseComponent(); diff --git a/src/HeadlessBlazor.Dropdown/DropdownItem.cs b/src/HeadlessBlazor.Dropdown/HBDropdownItem.cs similarity index 78% rename from src/HeadlessBlazor.Dropdown/DropdownItem.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownItem.cs index c71441a..4355b04 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownItem.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownItem.cs @@ -4,10 +4,10 @@ namespace HeadlessBlazor; -public class DropdownItem : HBElement +public class HBDropdownItem : HBElement { [CascadingParameter] - public Dropdown Dropdown { get; set; } = default!; + public HBDropdown Dropdown { get; set; } = default!; protected override void OnParametersSet() { @@ -15,7 +15,7 @@ protected override void OnParametersSet() if (Dropdown == null) { - throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(Dropdown).Name}."); + throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(HBDropdown).Name}."); } UserAttributes.TryAdd("onclick", new EventCallback(this, HandleClick)); diff --git a/src/HeadlessBlazor.Dropdown/DropdownItemButton.cs b/src/HeadlessBlazor.Dropdown/HBDropdownItemButton.cs similarity index 66% rename from src/HeadlessBlazor.Dropdown/DropdownItemButton.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownItemButton.cs index d146673..9773579 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownItemButton.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownItemButton.cs @@ -1,6 +1,6 @@ namespace HeadlessBlazor; -public class DropdownItemButton : DropdownItem +public class HBDropdownItemButton : HBDropdownItem { public override string ElementName { get; set; } = "button"; } diff --git a/src/HeadlessBlazor.Dropdown/DropdownItemLink.cs b/src/HeadlessBlazor.Dropdown/HBDropdownItemLink.cs similarity index 65% rename from src/HeadlessBlazor.Dropdown/DropdownItemLink.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownItemLink.cs index 2cd57c9..a647522 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownItemLink.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownItemLink.cs @@ -1,6 +1,6 @@ namespace HeadlessBlazor; -public class DropdownItemLink : DropdownItem +public class HBDropdownItemLink : HBDropdownItem { public override string ElementName { get; set; } = "a"; } diff --git a/src/HeadlessBlazor.Dropdown/DropdownItems.cs b/src/HeadlessBlazor.Dropdown/HBDropdownItems.cs similarity index 75% rename from src/HeadlessBlazor.Dropdown/DropdownItems.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownItems.cs index 5d7d1ac..767e305 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownItems.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownItems.cs @@ -4,10 +4,10 @@ namespace HeadlessBlazor; -public class DropdownItems : HBElement +public class HBDropdownItems : HBElement { [CascadingParameter] - public Dropdown Dropdown { get; set; } = default!; + public HBDropdown Dropdown { get; set; } = default!; protected override void OnParametersSet() { @@ -15,7 +15,7 @@ protected override void OnParametersSet() if (Dropdown == null) { - throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(Dropdown).Name}."); + throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(HBDropdown).Name}."); } } diff --git a/src/HeadlessBlazor.Dropdown/DropdownOutsideClickBehavior.cs b/src/HeadlessBlazor.Dropdown/HBDropdownOutsideClickBehavior.cs similarity index 73% rename from src/HeadlessBlazor.Dropdown/DropdownOutsideClickBehavior.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownOutsideClickBehavior.cs index b514d59..597adf6 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownOutsideClickBehavior.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownOutsideClickBehavior.cs @@ -1,14 +1,13 @@ using HeadlessBlazor.Core.Behaviors; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Rendering; -using Microsoft.AspNetCore.Components.Web.Virtualization; namespace HeadlessBlazor; -public class DropdownOutsideClickBehavior : HBOutsideClickBehavior +public class HBDropdownOutsideClickBehavior : HBOutsideClickBehavior { [CascadingParameter] - public Dropdown Dropdown { get; set; } = default!; + public HBDropdown Dropdown { get; set; } = default!; protected override void BuildRenderTree(RenderTreeBuilder builder) { @@ -22,7 +21,7 @@ protected override void OnParametersSet() if (Dropdown == null) { - throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(Dropdown).Name}."); + throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(HBDropdown).Name}."); } UserAttributes.TryAdd("onclick", new EventCallback(this, HandleClick)); diff --git a/src/HeadlessBlazor.Dropdown/DropdownTrigger.cs b/src/HeadlessBlazor.Dropdown/HBDropdownTrigger.cs similarity index 85% rename from src/HeadlessBlazor.Dropdown/DropdownTrigger.cs rename to src/HeadlessBlazor.Dropdown/HBDropdownTrigger.cs index 1cb4109..7151789 100644 --- a/src/HeadlessBlazor.Dropdown/DropdownTrigger.cs +++ b/src/HeadlessBlazor.Dropdown/HBDropdownTrigger.cs @@ -4,10 +4,10 @@ namespace HeadlessBlazor; -public class DropdownTrigger : HBElement +public class HBDropdownTrigger : HBElement { [CascadingParameter] - public Dropdown Dropdown { get; set; } = default!; + public HBDropdown Dropdown { get; set; } = default!; [Parameter] public override string ElementName { get; set; } = "button"; @@ -24,7 +24,7 @@ protected override void OnParametersSet() if (Dropdown == null) { - throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(Dropdown).Name}."); + throw new InvalidOperationException($"{GetType().Name} requires a cascading parameter of type {typeof(HBDropdown).Name}."); } UserAttributes.TryAdd("onclick", new EventCallback(this, HandleClick)); diff --git a/themes/HeadlessBlazor.Themes.Bootstrap/HBBootstrapThemeConfiguration.cs b/themes/HeadlessBlazor.Themes.Bootstrap/HBBootstrapThemeConfiguration.cs index 1853428..f0fedfa 100644 --- a/themes/HeadlessBlazor.Themes.Bootstrap/HBBootstrapThemeConfiguration.cs +++ b/themes/HeadlessBlazor.Themes.Bootstrap/HBBootstrapThemeConfiguration.cs @@ -16,16 +16,16 @@ public static IServiceCollection AddBootstrapTheme(this IServiceCollection servi public static HBTheme UseBootstrap(this HBThemeBuilder t) { - t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown", "d-inline-block")); - t.AddComponentDefaults(c => c.AddDefaultClassNames("btn", "btn-primary", "dropdown-toggle")); - t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown-menu", "show")); - t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown-item")); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown", "d-inline-block")); + t.AddComponentDefaults(c => c.AddDefaultClassNames("btn", "btn-primary", "dropdown-toggle")); + t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown-menu", "show")); + t.AddComponentDefaults(c => c.AddDefaultClassNames("dropdown-item")); + t.AddComponentDefaults(c => { c.AddDefaultClassNames("dropdown-item"); c.AddAttributeDefaults("type", "button"); }); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => { c.AddDefaultClassNames("dropdown-item"); c.AddAttributeDefaults("href", "#"); diff --git a/themes/HeadlessBlazor.Themes.Tailwind/HBTailwindThemeConfiguration.cs b/themes/HeadlessBlazor.Themes.Tailwind/HBTailwindThemeConfiguration.cs index 5f76dc2..d7c57c0 100644 --- a/themes/HeadlessBlazor.Themes.Tailwind/HBTailwindThemeConfiguration.cs +++ b/themes/HeadlessBlazor.Themes.Tailwind/HBTailwindThemeConfiguration.cs @@ -16,23 +16,23 @@ public static IServiceCollection AddTailwindTheme(this IServiceCollection servic public static HBTheme UseTailwind(this HBThemeBuilder t) { - t.AddComponentDefaults(c => c.AddDefaultClassNames("relative", "inline-block", "text-left")); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => c.AddDefaultClassNames("relative", "inline-block", "text-left")); + t.AddComponentDefaults(c => { c.AddDefaultClassNames("inline-flex w-full justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 [&:not(:disabled)]:hover:bg-gray-50"); c.AddAttributeDefaults("type", "button"); }); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => { c.AddDefaultClassNames("absolute left-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"); }); - t.AddComponentDefaults(c => c.AddDefaultClassNames("text-gray-700 block px-4 py-2 text-sm text-left w-full hover:text-gray-900 hover:bg-gray-100")); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => c.AddDefaultClassNames("text-gray-700 block px-4 py-2 text-sm text-left w-full hover:text-gray-900 hover:bg-gray-100")); + t.AddComponentDefaults(c => { c.AddDefaultClassNames("text-gray-700 block px-4 py-2 text-sm text-left w-full [&:not(:disabled)]:hover:text-gray-900 [&:not(:disabled)]:hover:bg-gray-100 disabled:opacity-50"); c.AddAttributeDefaults("type", "button"); }); - t.AddComponentDefaults(c => + t.AddComponentDefaults(c => { c.AddDefaultClassNames("text-gray-700 block px-4 py-2 text-sm text-left w-full hover:text-gray-900 hover:bg-gray-100"); c.AddAttributeDefaults("href", "#");