Added components, authentication and authorization

This commit is contained in:
2026-05-04 16:53:19 +05:00
parent 493cd71d17
commit fb1cb8e834
37 changed files with 3545 additions and 21 deletions
+101
View File
@@ -0,0 +1,101 @@
using Htmx.ApiDemo.Templates.Components;
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
namespace Htmx.ApiDemo.Templates;
public sealed class UiDemo : UiDemoBase
{
public IHtmxComponent BtnDefault { get; }
public IHtmxComponent BtnDestructive { get; }
public IHtmxComponent BtnOutline { get; }
public IHtmxComponent BtnSecondary { get; }
public IHtmxComponent BtnGhost { get; }
public IHtmxComponent BtnLink { get; }
public IHtmxComponent BtnSm { get; }
public IHtmxComponent BtnLg { get; }
public IHtmxComponent InputText { get; }
public IHtmxComponent InputEmail { get; }
public IHtmxComponent InputPassword { get; }
public IHtmxComponent InputSearch { get; }
public IHtmxComponent SelectDemo { get; }
public IHtmxComponent CalendarDemo { get; }
public IHtmxComponent CalendarRangeDemo{ get; }
public IHtmxComponent TimePickerDemo { get; }
public IHtmxComponent TimePicker12hDemo { get; }
public UiDemo()
{
BtnDefault = new Button("Default");
BtnDestructive = new Button("Destructive", variant: "destructive");
BtnOutline = new Button("Outline", variant: "outline");
BtnSecondary = new Button("Secondary", variant: "secondary");
BtnGhost = new Button("Ghost", variant: "ghost");
BtnLink = new Button("Link", variant: "link");
BtnSm = new Button("Small", size: "sm");
BtnLg = new Button("Large", size: "lg");
InputText = new Input("username", label: "Username", placeholder: "Enter username");
InputEmail = new Input("email", inputType: "email", label: "Email", placeholder: "you@example.com");
InputPassword = new Input("password", inputType: "password", label: "Password", placeholder: "••••••••");
InputSearch = new Input("search", inputType: "search", label: "Search", placeholder: "Search…",
hxAttrs: "hx-get=\"/search\" hx-trigger=\"keyup changed delay:300ms\" hx-target=\"#search-results\"");
SelectDemo = new Select(
id: "framework",
label: "Framework",
options: [("htmx", "HTMX"), ("react", "React"), ("vue", "Vue"), ("svelte", "Svelte")],
selectedValue: "htmx",
description: "Choose your preferred framework");
CalendarDemo = new Calendar(id: "demo-cal", name: "demo-date");
CalendarRangeDemo = new CalendarRange(id: "demo-calr", name: "demo-range");
TimePickerDemo = new TimePicker(name: "time-24h", label: "Time (24h)");
TimePicker12hDemo = new TimePicker(name: "time-12h", label: "Time (12h)", use12h: true);
}
protected override void RenderBtnDefault(HtmxRenderContext ctx) => BtnDefault.Render(ctx);
protected override void RenderBtnDestructive(HtmxRenderContext ctx) => BtnDestructive.Render(ctx);
protected override void RenderBtnOutline(HtmxRenderContext ctx) => BtnOutline.Render(ctx);
protected override void RenderBtnSecondary(HtmxRenderContext ctx) => BtnSecondary.Render(ctx);
protected override void RenderBtnGhost(HtmxRenderContext ctx) => BtnGhost.Render(ctx);
protected override void RenderBtnLink(HtmxRenderContext ctx) => BtnLink.Render(ctx);
protected override void RenderBtnSm(HtmxRenderContext ctx) => BtnSm.Render(ctx);
protected override void RenderBtnLg(HtmxRenderContext ctx) => BtnLg.Render(ctx);
protected override void RenderInputText(HtmxRenderContext ctx) => InputText.Render(ctx);
protected override void RenderInputEmail(HtmxRenderContext ctx) => InputEmail.Render(ctx);
protected override void RenderInputPassword(HtmxRenderContext ctx) => InputPassword.Render(ctx);
protected override void RenderInputSearch(HtmxRenderContext ctx) => InputSearch.Render(ctx);
protected override void RenderSelectDemo(HtmxRenderContext ctx) => SelectDemo.Render(ctx);
protected override void RenderCalendarDemo(HtmxRenderContext ctx) => CalendarDemo.Render(ctx);
protected override void RenderCalendarRangeDemo(HtmxRenderContext ctx) => CalendarRangeDemo.Render(ctx);
protected override void RenderTimePickerDemo(HtmxRenderContext ctx) => TimePickerDemo.Render(ctx);
protected override void RenderTimePicker12hDemo(HtmxRenderContext ctx) => TimePicker12hDemo.Render(ctx);
}
[Handler]
[MapGet("/ui-demo")]
public static partial class GetUiDemoHandler
{
public record Query;
private static ValueTask HandleAsync(
Query query,
IHttpContextAccessor httpContextAccessor,
CancellationToken token)
{
var context = httpContextAccessor.HttpContext
?? throw new InvalidOperationException("HttpContext is not available.");
var page = new UiDemo();
context.WriteHtmxPage(page, title: "UI Demo", appName: "HtmxApp", pageTitle: "UI Components");
return ValueTask.CompletedTask;
}
}