Files
decePubClient/Components/Nerd/NerdTip.razor
T

66 lines
2.4 KiB
Plaintext
Raw Normal View History

@inherits LocalizableComponentBase
2026-10-06 23:36:03 +02:00
@* Nerd stats on hover or focus: a DTooltip whose content is the rows (NerdRows). A touch screen has no hover, so there
a tap opens the same rows in a sheet from the bottom (TapOpens; not for a trigger that is a link itself, the
pictures). OnOpen runs on the first hover, focus or tap, for stats read on demand (a post's provenance). *@
@if (TapOpens)
{
@* (on touch the trigger is at least 44px: daisyUI's tooltip draws its arrow with ::after, so padding-free min sizes) *@
<DTooltip Placement="Placement" Align="Align" class="@($"{Class} pointer-coarse:inline-flex pointer-coarse:items-center pointer-coarse:min-h-11 pointer-coarse:min-w-11")"
TipContent="Body" @onmouseenter="Open" @onfocusin="Open" @onclick="Tap"
tabindex="0" role="button" aria-haspopup="dialog" aria-label="@Heading">
@ChildContent
</DTooltip>
}
else
{
<DTooltip Placement="Placement" Align="Align" class="@Class" TipContent="Body" @onmouseenter="Open" @onfocusin="Open">
@ChildContent
</DTooltip>
}
@if (isSheetOpen)
{
<DModal Placement="DModalPlacement.ResponsiveBottom" IsOpen="true" IsOpenChanged="open => isSheetOpen = open" CloseText="@Localizer["Close"]" data-nerd-sheet>
<Heading>@Heading</Heading>
<ChildContent>
<NerdRows Rows="Rows" Pending="Pending" />
</ChildContent>
</DModal>
}
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public string Heading { get; set; }
[Parameter] public IEnumerable<NerdRow> Rows { get; set; } = [];
/// <summary>Shown under the rows while OnOpen's work runs.</summary>
[Parameter] public bool Pending { get; set; }
[Parameter] public EventCallback OnOpen { get; set; }
[Parameter] public DTooltipPlacement Placement { get; set; }
[Parameter] public DTooltipAlign Align { get; set; }
[Parameter] public string Class { get; set; }
2026-10-06 23:36:03 +02:00
/// <summary>A tap opens the rows in a sheet where the screen has no hover.</summary>
[Parameter] public bool TapOpens { get; set; } = true;
bool opened;
2026-10-06 23:36:03 +02:00
bool isSheetOpen;
async Task Tap()
{
if (CascadingState.Status.CanHover())
return;
isSheetOpen = true;
await Open();
}
protected override void OnInitialized() => IsLoading = false;
async Task Open()
{
if (opened || !OnOpen.HasDelegate)
return;
opened = true;
await OnOpen.InvokeAsync();
}
2026-10-06 23:36:03 +02:00
RenderFragment Body => @<NerdRows Heading="@Heading" Rows="Rows" Pending="Pending" />;
}