UI/Components/Modal/ModalHost.razor

A Blazor/Sandbox.UI Razor component that hosts a modal dialog. It renders a ModalPanel and passes modal state (IsOpen, Title, body, footer, close behavior) from a Modal model into the panel, resolving either a RenderFragment body or a text fragment.

@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 );
}