Skip to content

Commit

Permalink
feat: out of band example using SectionContent and SectionOutlet comp…
Browse files Browse the repository at this point in the history
…oents
  • Loading branch information
egil committed May 8, 2024
1 parent 3d55136 commit b993c6b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion samples/HtmxorExamples/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inherits LayoutComponentBase
<main class="container-fluid p-3">
<main class="container p-3">
@Body
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@inherits ConditionalComponentBase
@attribute [HtmxLayout(typeof(OutOfBandHtmxLayout), Priority = 1)]
@layout OutOfBandMainLayout
@page "/examples/out-of-band-outlets"
@code {
[SupplyParameterFromForm]
private int CurrentCount { get; set; } = 0;

private void IncrementCount(HtmxEventArgs args)
{
CurrentCount++;
}
}
<PageTitle>Htmxor - Examples - Out of Band Outlets</PageTitle>

<p>This is an example of a counter updating and a element in the header also updating out of bounds.</p>

<div id="counter" class="border p-3 d-inline-block text-center">
<HtmxPartial>
<SectionContent SectionName="toast">
<span id="toasts" hx-swap-oob=@SwapStyles.OuterHTML class="text-warning">
The count is @(CurrentCount % 2 == 0 ? "even" : "odd")!
</span>
</SectionContent>

<p role="status">
Current count: @CurrentCount
</p>
<button class="btn btn-primary"
hx-put="/examples/out-of-band-outlets"
hx-vals='{ "CurrentCount": @(CurrentCount) }'
hx-target="#counter"
@onput="IncrementCount">
Click me
</button>
</HtmxPartial>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@inherits HtmxLayoutComponentBase
<SectionOutlet SectionName="toast" />
@Body
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@inherits LayoutComponentBase
<header class="container p-3 bg-secondary text-white shadow">
This header contains content that can be updated out of bounds:
<SectionOutlet SectionName="toast" />
</header>
<main class="container p-3">
@Body
</main>
18 changes: 16 additions & 2 deletions samples/HtmxorExamples/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@
</tr>
<tr>
<td><a href="/examples/updating-other-content/triggering-events">Updating Other Content - Triggering Events</a></td>
<td>Demonstrates how to update content beyond just the target elements by triggering events on the client using HX-Trigger response header.</td>
<td>
Demonstrates how to update content beyond just the target elements by
triggering events on the client using HX-Trigger response header.
</td>
</tr>
<tr>
<td><a href="/examples/updating-other-content/triggering-events-indirectly">Updating Other Content - Triggering Events Indirectly</a></td>
<td>Demonstrates how to update content beyond just the target elements by triggering events on the client using HX-Trigger response header from another routable component.</td>
<td>
Demonstrates how to update content beyond just the target elements by
triggering events on the client using HX-Trigger response header from another routable component.
</td>
</tr>
<tr>
<td><a href="/examples/out-of-band-outlets">Out of Band Outlets</a></td>
<td>
Shows how you can leverage <code>SectionContent</code> and <code>SectionOutlet</code> components in Blazor to dynamically
add out-of-band content to a htmx response. The key is to have the <code>SectionOutlet</code> component in both
the MainLayout and in the Htmx specific layout.
</td>
</tr>
</tbody>
</table>
1 change: 1 addition & 0 deletions samples/HtmxorExamples/Components/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using System.Net.Http
@using System.Net.Http.Json
@using HtmxorExamples.Components.Layout
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
Expand Down

0 comments on commit b993c6b

Please sign in to comment.