UI/Components/Modal/ModalHost.razor

A Blazor Razor component that hosts a modal dialog. It renders a ModalPanel using properties from a Modal model, resolves body content either from a RenderFragment or plain text, and provides a close callback and a hash based on the modal version.

@namespace Sunless.Libraries.UI
@using Sandbox
@using Sandbox.UI
@using Microsoft.AspNetCore.Components
@inherits Panel

<root>
	<ModalPanel [email protected] [email protected]
	            [email protected] [email protected]
	            Body=@ResolvedBody [email protected]
	            OnClose=@(() => Modal.Close()) />
</root>

@code
{
	RenderFragment ResolvedBody => Modal.BodyFragment ?? (string.IsNullOrEmpty( Modal.BodyText ) ? null : TextFragment( Modal.BodyText ));

	static RenderFragment TextFragment( string text ) => builder =>
	{
		builder.OpenElement( 0, "div" );
		builder.AddContent( 1, text );
		builder.CloseElement();
	};

	protected override int BuildHash() => HashCode.Combine( Modal.Version );
}