You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
5.0 KiB
Plaintext

<div>
<layout:Container>
<h1>Overlays</h1>
<p>Overlays are handled by the <view:CodeInline>overlay.Container</view:CodeInline> component which has to be embedded into your root component.</p>
<p>Every page or component that creates overlays has to embed the <view:CodeInline>overlay.OverlayContainerRef</view:CodeInline> structure. Your wiring function also needs to set the reference to your <view:CodeInline>overlay.Container</view:CodeInline> that you have placed in your root component.</p>
<h2>Modals</h2>
<p>A simple requester modal is already contained in the overlay package. Use it with:</p>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.SetModal(&overlay.ModalRequester{\n" +
" IconSlot: &icons.LInfoCircle{AttrMap: vugu.AttrMap{\"style\": \"font-size: 2em;\"}},\n" +
" Title: \"Simple requester\",\n" +
" Message: \"This is a simple modal requester, are you happy with it?\\nIt also supports multi line text!\",\n" +
" SignalColor: \"d3c-color-accent\",\n" +
" ClickAbort: input.ClickFunc(func(event input.ClickEvent) {}),\n" +
" ClickYes: input.ClickFunc(func(event input.ClickEvent) {}),\n" +
" })\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<input:Button @Click="c.handleSimpleModalButton(event)">Open simple modal</input:Button>
<h2>Toasts</h2>
<p>A simple toast with an icon slot and custom color setting can be found in the overlay package. Use it with:</p>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event, &overlay.ToastSimple{\n" +
" IconSlot: &icons.LInfoCircle{AttrMap: vugu.AttrMap{\"style\": \"font-size: 2em;\"}},\n" +
" Message: \"This is a simple toast!\\nIt supports multiple lines and has an icon slot.\\nThere also can be multiple of it at the same time, this one was opened at \" + time.Now().Format(time.TimeOnly) + \".\",\n" +
" SignalColor: \"d3c-color-accent\",\n" +
" })\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<layout:ContainerHorizontal>
<input:Button @Click="c.handleSimpleToastButton(event)">Open simple toast</input:Button>
<input:Button @Click="c.handleWarningToastButton(event)">Open warning toast</input:Button>
</layout:ContainerHorizontal>
<p>A shorter version of this is <view:CodeInline>overlay.ToastMessage</view:CodeInline> which only accepts a message text and a message type which is one of</p>
<ul>
<li><view:CodeInline>overlay.ToastMessageTypeSuccess</view:CodeInline></li>
<li><view:CodeInline>overlay.ToastMessageTypeAttention</view:CodeInline></li>
<li><view:CodeInline>overlay.ToastMessageTypeCaution</view:CodeInline></li>
<li><view:CodeInline>overlay.ToastMessageTypeCritical</view:CodeInline></li>
</ul>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: \"Uh oh!\"})\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<input:Button @Click="c.handleToastMessageButton(event)">Open message toast</input:Button>
<p>To let the toast close itself after some time, you can use the <view:CodeInline>Duration</view:CodeInline> option:</p>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleButton(event vugu.DOMEvent) {\n" +
" c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: \"That worked!\", Duration: 5 * time.Second})\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<input:Button @Click="c.handleToastMessageTimeoutButton(event)">Open self closing message toast</input:Button>
<h2>Wait/Load overlay</h2>
<p>For actions that take a bit longer you can show the wait overlay:</p>
<view:Code>
<pre vg-content='"func (c *PageOverlays) handleWaitOverlayButton(event vugu.DOMEvent) {\n" +
" c.WaitOverlayOpen()\n" +
" go func() {\n" +
" // Simulate some request or some other action.\n" +
" time.Sleep(5 * time.Second)\n" +
" // We need to lock and unlock the event environment in order for the DOM to re-render and the overlay to disappear correctly.\n" +
" event.EventEnv().Lock()\n" +
" defer event.EventEnv().UnlockRender()\n" +
" defer c.WaitOverlayDone() // WaitOverlayDone has to be called before UnlockRender, so we need to put it afterwards (defer ordering).\n" +
" // Update other UI stuff here.\n" +
" }()\n" +
"}"' style="margin: 0;"></pre>
</view:Code>
<layout:ContainerHorizontal>
<input:Button @Click="c.handleWaitOverlayButton(event)">Do some action that takes time</input:Button>
</layout:ContainerHorizontal>
</layout:Container>
</div>
<style>
</style>
<script type="application/x-go">
import (
"git.d3nexus.de/Dadido3/D3vugu-components/components/input"
"git.d3nexus.de/Dadido3/D3vugu-components/components/layout"
"git.d3nexus.de/Dadido3/D3vugu-components/components/view"
)
</script>