@inject IDialogService dialogService
@implements IDialog
@implements IDisposable
@if(Title is not null) {
@Title
}
@ChildContent
@code {
[Parameter]
public string? Title { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public int HeightPixels { set => height = $"{value}px"; }
[Parameter]
public int HeightPercent { set => height = $"{value}%"; }
public bool Visible {
get => visible;
set {
visible = value;
if(value)
Bump();
StateHasChanged();
}
}
public int? ZIndex {
get => zIndex;
set {
zIndex = value;
StateHasChanged();
}
}
private bool visible = false;
private int? zIndex;
private string? height;
protected override void OnInitialized() =>
dialogService.Register(this);
public void Show() => Visible = true;
public void Hide() => Visible = false;
private void Bump() =>
dialogService.BumpZIndex(this);
private string style =>
zIndexStyle +
heightStyle +
visiblilityStyle;
private string zIndexStyle =>
zIndex is null ? "display:none;" : $"z-index:{zIndex};";
private string heightStyle =>
$"{(height is null ? "" : $"max-height:{height};")}";
private string visiblilityStyle =>
Visible ? "opacity:1;visibility:visible;" : "opacity:0;visibility:hidden;";
public void Dispose() =>
dialogService.Unregister(this);
}