Added components, authentication and authorization
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
namespace Htmx.ApiDemo.Templates.Components;
|
||||
|
||||
/// <summary>
|
||||
/// shadcn-style range Calendar. Lets the user pick a start and end date.
|
||||
/// State and rendering are handled by components.js (initCalendarRange).
|
||||
/// Fires a <c>rangeChange</c> CustomEvent with <c>{ start, end }</c> detail.
|
||||
/// </summary>
|
||||
public sealed class CalendarRange : CalendarRangeBase
|
||||
{
|
||||
private readonly byte[] _idData;
|
||||
private readonly byte[] _nameStartData;
|
||||
private readonly byte[] _nameEndData;
|
||||
private readonly byte[] _yearData;
|
||||
private readonly byte[] _monthData;
|
||||
private readonly byte[] _defaultStartData;
|
||||
private readonly byte[] _defaultEndData;
|
||||
|
||||
public CalendarRange(
|
||||
string id,
|
||||
string name = "date",
|
||||
DateOnly? selectedStart = null,
|
||||
DateOnly? selectedEnd = null)
|
||||
{
|
||||
// Show the start month if provided, otherwise today
|
||||
var viewDate = selectedStart ?? DateOnly.FromDateTime(DateTime.Today);
|
||||
|
||||
_idData = id.ToUtf8Bytes();
|
||||
_nameStartData = (name + "-start").ToUtf8Bytes();
|
||||
_nameEndData = (name + "-end").ToUtf8Bytes();
|
||||
_yearData = viewDate.Year.ToString().ToUtf8Bytes();
|
||||
_monthData = (viewDate.Month - 1).ToString().ToUtf8Bytes(); // 0-based
|
||||
|
||||
_defaultStartData = selectedStart.HasValue
|
||||
? selectedStart.Value.ToString("yyyy-MM-dd").ToUtf8Bytes()
|
||||
: [] ;
|
||||
|
||||
_defaultEndData = selectedEnd.HasValue
|
||||
? selectedEnd.Value.ToString("yyyy-MM-dd").ToUtf8Bytes()
|
||||
: [];
|
||||
}
|
||||
|
||||
protected override void RenderId(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_idData);
|
||||
protected override void RenderNameStart(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_nameStartData);
|
||||
protected override void RenderNameEnd(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_nameEndData);
|
||||
protected override void RenderYear(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_yearData);
|
||||
protected override void RenderMonth(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_monthData);
|
||||
protected override void RenderDefaultStart(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_defaultStartData);
|
||||
protected override void RenderDefaultEnd(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_defaultEndData);
|
||||
}
|
||||
Reference in New Issue
Block a user