AI-Studio/app/MindWork AI Studio/Components/InnerScrolling.razor.cs

82 lines
2.6 KiB
C#
Raw Normal View History

2024-08-21 06:30:01 +00:00
using AIStudio.Layout;
2024-06-30 13:26:28 +00:00
using Microsoft.AspNetCore.Components;
2024-08-21 06:30:01 +00:00
namespace AIStudio.Components;
2024-06-30 13:26:28 +00:00
public partial class InnerScrolling : MSGComponentBase
{
2024-11-02 21:53:02 +00:00
[Parameter]
public bool FillEntireHorizontalSpace { get; set; }
/// <summary>
/// Set the height of anything above the scrolling content; usually a header.
2024-06-30 13:26:28 +00:00
/// What we do is calc(100vh - HeaderHeight). Means, you can use multiple measures like
/// 230px - 3em. Default is 3em.
/// </summary>
[Parameter]
public string HeaderHeight { get; set; } = "3em";
2024-11-02 21:53:02 +00:00
[Parameter]
public RenderFragment? HeaderContent { get; set; }
[Parameter]
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Optional footer content, shown after the scrolling area.
/// </summary>
[Parameter]
public RenderFragment? FooterContent { get; set; }
2024-11-02 21:53:02 +00:00
[Parameter]
public string Class { get; set; } = string.Empty;
2024-06-30 13:26:28 +00:00
[CascadingParameter]
private MainLayout MainLayout { get; set; } = null!;
[Inject]
private IJSRuntime JsRuntime { get; init; } = null!;
private ElementReference AnchorAfterChildContent { get; set; }
2024-06-30 13:26:28 +00:00
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
this.ApplyFilters([], [ Event.STATE_HAS_CHANGED ]);
await base.OnInitializedAsync();
}
#endregion
#region Overrides of MSGComponentBase
public override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
2024-06-30 13:26:28 +00:00
{
switch (triggeredEvent)
{
case Event.STATE_HAS_CHANGED:
this.StateHasChanged();
break;
}
return Task.CompletedTask;
}
public override Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) where TResult : default where TPayload : default
{
return Task.FromResult(default(TResult));
}
2024-06-30 13:26:28 +00:00
#endregion
2024-11-02 21:53:02 +00:00
private string Styles => this.FillEntireHorizontalSpace ? $"height: calc(100vh - {this.HeaderHeight} - {this.MainLayout.AdditionalHeight}); overflow-x: auto; min-width: 0;" : $"height: calc(100vh - {this.HeaderHeight} - {this.MainLayout.AdditionalHeight}); flex-shrink: 0;";
private string Classes => this.FillEntireHorizontalSpace ? $"{this.Class} d-flex flex-column flex-grow-1" : $"{this.Class} d-flex flex-column";
public async Task ScrollToBottom()
{
await this.AnchorAfterChildContent.ScrollIntoViewAsync(this.JsRuntime);
}
}