Skip to content

Commit

Permalink
prefix component names with "HB"
Browse files Browse the repository at this point in the history
  • Loading branch information
erinnmclaughlin committed May 16, 2024
1 parent 1f37bce commit 4bdc479
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 168 deletions.

This file was deleted.

28 changes: 14 additions & 14 deletions docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs.Client/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

<div class="hb-example-snippet border">
<div class="hb-example border-bottom">
<Dropdown>
<DropdownOutsideClickBehavior />
<DropdownTrigger>Click Me</DropdownTrigger>
<DropdownItems>
<DropdownItem>Default</DropdownItem>
<DropdownItemButton>Button</DropdownItemButton>
<DropdownItemButton disabled="true">Disabled Button</DropdownItemButton>
<DropdownItemButton @onclick:stopPropagation="true">Button (Stop Propagation)</DropdownItemButton>
<DropdownItemLink>Link</DropdownItemLink>
<DropdownItemLink @onclick:preventDefault="true">Link (Prevent Default)</DropdownItemLink>
<DropdownItemLink @onclick:stopPropagation="true">Link (Stop Propagation)</DropdownItemLink>
<DropdownItemLink OnClickPreventDefault="true" OnClickStopPropagation="true">Link (Prevent Default and Stop Propagation)</DropdownItemLink>
</DropdownItems>
</Dropdown>
<HBDropdown>
<HBDropdownOutsideClickBehavior />
<HBDropdownTrigger>Click Me</HBDropdownTrigger>
<HBDropdownItems>
<HBDropdownItem>Default</HBDropdownItem>
<HBDropdownItemButton>Button</HBDropdownItemButton>
<HBDropdownItemButton disabled="true">Disabled Button</HBDropdownItemButton>
<HBDropdownItemButton @onclick:stopPropagation="true">Button (Stop Propagation)</HBDropdownItemButton>
<HBDropdownItemLink>Link</HBDropdownItemLink>
<HBDropdownItemLink @onclick:preventDefault="true">Link (Prevent Default)</HBDropdownItemLink>
<HBDropdownItemLink @onclick:stopPropagation="true">Link (Stop Propagation)</HBDropdownItemLink>
<HBDropdownItemLink OnClickPreventDefault="true" OnClickStopPropagation="true">Link (Prevent Default and Stop Propagation)</HBDropdownItemLink>
</HBDropdownItems>
</HBDropdown>
</div>
<div class="hb-code-block bg-light bg-gray-100">
<pre>@Example1CodeBlock</pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HeadManipulationService>();

builder.Services
.AddHeadlessBlazor()
.AddBootstrapTheme()
Expand Down
33 changes: 2 additions & 31 deletions docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Components/App.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@using HeadlessBlazor.Core.Themes
@inject HBThemeFactory ThemeFactory
@implements IDisposable

<!DOCTYPE html>
<html lang="en" @ref="Root">
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
Expand All @@ -19,35 +15,10 @@
</head>

<body>
<div style="display: none">@Theme</div>
<Routes @rendermode="InteractiveServer" />
<script src="js/headManipulation.js"></script>
<script src="_framework/blazor.web.js"></script>
</body>

</html>

@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();
});
}
}
3 changes: 0 additions & 3 deletions docs/HeadlessBlazor.Docs/HeadlessBlazor.Docs/Program.cs
Original file line number Diff line number Diff line change
@@ -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<HeadManipulationService>();

builder.Services
.AddHeadlessBlazor()
.AddBootstrapTheme()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

namespace HeadlessBlazor;

public class Dropdown : HBElement<Dropdown>
public class HBDropdown : HBElement<HBDropdown>
{
public bool IsOpen { get; private set; }

[Parameter]
public EventCallback<DropdownItem> OnClickItem { get; set; }
public EventCallback<HBDropdownItem> OnClickItem { get; set; }

public async Task Toggle() => await SetIsOpen(!IsOpen);
public async Task Open() => await SetIsOpen(true);
public async Task Close() => await SetIsOpen(false);

protected override void OnInitialized()
{
if (!OnClickItem.HasDelegate)
OnClickItem = new EventCallback<DropdownItem>(this, Close);

base.OnInitialized();

if (!OnClickItem.HasDelegate)
OnClickItem = new EventCallback<HBDropdownItem>(this, Close);
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
var seq = 0;
builder.OpenComponent<CascadingValue<Dropdown>>(seq++);
builder.OpenComponent<CascadingValue<HBDropdown>>(seq++);
builder.AddAttribute(seq, "Value", this);
builder.AddAttribute(seq++, "ChildContent", (RenderFragment)((b) => BuildRenderTree(b, ref seq)));
builder.CloseComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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()
{
base.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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace HeadlessBlazor;

public class DropdownItemButton : DropdownItem
public class HBDropdownItemButton : HBDropdownItem
{
public override string ElementName { get; set; } = "button";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace HeadlessBlazor;

public class DropdownItemLink : DropdownItem
public class HBDropdownItemLink : HBDropdownItem
{
public override string ElementName { get; set; } = "a";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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()
{
base.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}.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public static IServiceCollection AddBootstrapTheme(this IServiceCollection servi

public static HBTheme UseBootstrap(this HBThemeBuilder t)
{
t.AddComponentDefaults<Dropdown>(c => c.AddDefaultClassNames("dropdown", "d-inline-block"));
t.AddComponentDefaults<DropdownTrigger>(c => c.AddDefaultClassNames("btn", "btn-primary", "dropdown-toggle"));
t.AddComponentDefaults<DropdownItems>(c => c.AddDefaultClassNames("dropdown-menu", "show"));
t.AddComponentDefaults<DropdownItem>(c => c.AddDefaultClassNames("dropdown-item"));
t.AddComponentDefaults<DropdownItemButton>(c =>
t.AddComponentDefaults<HBDropdown>(c => c.AddDefaultClassNames("dropdown", "d-inline-block"));
t.AddComponentDefaults<HBDropdownTrigger>(c => c.AddDefaultClassNames("btn", "btn-primary", "dropdown-toggle"));
t.AddComponentDefaults<HBDropdownItems>(c => c.AddDefaultClassNames("dropdown-menu", "show"));
t.AddComponentDefaults<HBDropdownItem>(c => c.AddDefaultClassNames("dropdown-item"));
t.AddComponentDefaults<HBDropdownItemButton>(c =>
{
c.AddDefaultClassNames("dropdown-item");
c.AddAttributeDefaults("type", "button");
});
t.AddComponentDefaults<DropdownItemLink>(c =>
t.AddComponentDefaults<HBDropdownItemLink>(c =>
{
c.AddDefaultClassNames("dropdown-item");
c.AddAttributeDefaults("href", "#");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ public static IServiceCollection AddTailwindTheme(this IServiceCollection servic

public static HBTheme UseTailwind(this HBThemeBuilder t)
{
t.AddComponentDefaults<Dropdown>(c => c.AddDefaultClassNames("relative", "inline-block", "text-left"));
t.AddComponentDefaults<DropdownTrigger>(c =>
t.AddComponentDefaults<HBDropdown>(c => c.AddDefaultClassNames("relative", "inline-block", "text-left"));
t.AddComponentDefaults<HBDropdownTrigger>(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<DropdownItems>(c =>
t.AddComponentDefaults<HBDropdownItems>(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<DropdownItem>(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<DropdownItemButton>(c =>
t.AddComponentDefaults<HBDropdownItem>(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<HBDropdownItemButton>(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<DropdownItemLink>(c =>
t.AddComponentDefaults<HBDropdownItemLink>(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", "#");
Expand Down

0 comments on commit 4bdc479

Please sign in to comment.