Skip to content

Commit 0f116e0

Browse files
committed
New trigger and httpcontext extensions
1 parent 3449177 commit 0f116e0

File tree

15 files changed

+216
-56
lines changed

15 files changed

+216
-56
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
66

7+
## [0.3.0] - 2025-07-11
8+
9+
### Added
10+
11+
- HttpContext extensions to check htmx request headers
12+
- Add a Trigger to the RazorHxResult.
13+
714
## [0.2.0] - 2025-01-13
815

916
### Added

README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
44

5-
This small helper library seamlessly combines HTMX with the latest Razor Components in the ASP.NET Core world. With this library, you can effortlessly return HTML through Minimal API endpoints, which is then rendered by Razor Components. Streamline development by harnessing the power of HTMX alongside the flexibility of Razor Components and Minimal APIs.
5+
This small helper library seamlessly combines HTMX with the latest Razor Components in the ASP.NET Core world. With this
6+
library, you can effortlessly return HTML through Minimal API endpoints, which is then rendered by Razor Components.
7+
Streamline development by harnessing the power of HTMX alongside the flexibility of Razor Components and Minimal APIs.
68

79
## Features
810

@@ -12,12 +14,15 @@ This small helper library seamlessly combines HTMX with the latest Razor Compone
1214

1315
## Installation
1416

15-
To use RazorHx in your ASP.NET Core project, you only need to install the NuGet package. Open your project in the Package Manager Console and run the following command:
17+
To use RazorHx in your ASP.NET Core project, you only need to install the NuGet package. Open your project in the
18+
Package Manager Console and run the following command:
19+
1620
```bash
1721
Install-Package RazorHx
1822
```
1923

2024
Alternatively, you can use the .NET CLI with the following command:
25+
2126
```bash
2227
dotnet add package RazorHx
2328
```
@@ -42,15 +47,46 @@ app.MapGet("/", () => new RazorHxResult<Hello>());
4247
app.Run();
4348
```
4449

45-
### "Out of Band" Components
50+
### Triggers
51+
52+
[Read more at the official documentation site.](https://htmx.org/docs/#triggers)
53+
54+
Create an endpoint which returns a RazorHxResult and append the WithTrigger extension to specify the event to trigger:
55+
56+
```csharp
57+
app.MapGet("/", () => new RazorHxResult<Hello>()
58+
.WithTrigger("event"));
59+
```
60+
61+
Specify the timing, when the event should trigger:
62+
63+
```csharp
64+
app.MapGet("/", () => new RazorHxResult<Hello>()
65+
.WithTrigger("event", timing: TriggerTiming.Default)
66+
.WithTrigger("event", timing: TriggerTiming.AfterSettle)
67+
.WithTrigger("event", timing: TriggerTiming.AfterSwap));
68+
```
69+
70+
Specify the condition, when the event should be included:
71+
72+
```csharp
73+
app.MapGet("/", () => new RazorHxResult<Hello>()
74+
.WithTrigger("event", include: false));
75+
```
76+
77+
### Out of Band Swaps
78+
79+
[Read more at the official documentation site.](https://htmx.org/docs/#oob_swaps)
4680

4781
Create an endpoint which returns a RazorHxResult and append the WithOutOfBand extension to specify your oob component:
82+
4883
```csharp
4984
app.MapGet("/", () => new RazorHxResult<Hello>()
5085
.WithOutOfBand<World>());
5186
```
5287

53-
Define a slot in the DOM where the response will be swapped to:
88+
Define a slot in the DOM where the response will be swapped to:
89+
5490
```html
5591
<!-- Hello.razor or somewhere in Layouts -->
5692
<div id="oob">
@@ -73,7 +109,8 @@ For a detailed changelog, please refer to the [CHANGELOG.md](CHANGELOG.md) file.
73109

74110
## Contributing
75111

76-
We welcome contributions and feedback on these planned features. If you have specific features you'd like to see or would like to contribute to the development, please check our [contribution guidelines](CONTRIBUTING.md)
112+
We welcome contributions and feedback on these planned features. If you have specific features you'd like to see or
113+
would like to contribute to the development, please check our [contribution guidelines](CONTRIBUTING.md)
77114

78115
## License
79116

src/RazorHx.Components/RazorHx.Components.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<Version>0.0.2</Version>
87
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
98
<Title>RazorHx</Title>
109
<Authors>dmkk3r</Authors>
@@ -20,6 +19,10 @@
2019

2120
<ItemGroup>
2221
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.11" />
22+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
</PackageReference>
2326
</ItemGroup>
2427

2528
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
3+
"version": "0.0.2",
4+
"gitCommitIdShortAutoMinimum": 7,
5+
"publicReleaseRefSpec": [
6+
"^refs/heads/main$",
7+
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-[a-zA-Z0-9]+(?:\\.\\d+)*)?$"
8+
],
9+
"cloudBuild": {
10+
"buildNumber": {
11+
"enabled": true
12+
}
13+
}
14+
}

src/RazorHx.Htmx/HtmxTrigger.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace RazorHx.Htmx;
2+
3+
public class HtmxTrigger
4+
{
5+
public required string Name { get; init; }
6+
public TriggerTiming Timing { get; init; }
7+
public object? Parameters { get; init; }
8+
}

src/RazorHx.Htmx/RazorHx.Htmx.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.1.1</Version>
87
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
98
<Title>RazorHx</Title>
109
<Authors>dmkk3r</Authors>
@@ -18,4 +17,11 @@
1817
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
1918
</ItemGroup>
2019

20+
<ItemGroup>
21+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageReference>
25+
</ItemGroup>
26+
2127
</Project>

src/RazorHx.Htmx/TriggerTiming.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace RazorHx.Htmx;
2+
3+
public enum TriggerTiming
4+
{
5+
Default,
6+
AfterSettle,
7+
AfterSwap
8+
}

src/RazorHx.Htmx/version.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
3+
"version": "0.2.0",
4+
"gitCommitIdShortAutoMinimum": 7,
5+
"publicReleaseRefSpec": [
6+
"^refs/heads/main$",
7+
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-[a-zA-Z0-9]+(?:\\.\\d+)*)?$"
8+
],
9+
"cloudBuild": {
10+
"buildNumber": {
11+
"enabled": true
12+
}
13+
}
14+
}

src/RazorHx/ObjectExtensions.cs renamed to src/RazorHx/Extensions/ObjectExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.ComponentModel;
22

3-
namespace RazorHx;
3+
namespace RazorHx.Extensions;
44

5-
public static class ObjectExtensions
5+
internal static class ObjectExtensions
66
{
77
public static Dictionary<string, object?> ToDictionary(this object? values)
88
{

src/RazorHx/RazorHx.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.2.0</Version>
87
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
98
<Title>RazorHx</Title>
109
<Authors>dmkk3r</Authors>
@@ -28,5 +27,12 @@
2827
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
2928
<None Include="..\..\LICENSE" Pack="true" PackagePath="\"/>
3029
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115">
33+
<PrivateAssets>all</PrivateAssets>
34+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
35+
</PackageReference>
36+
</ItemGroup>
3137

3238
</Project>

0 commit comments

Comments
 (0)