package main import ( "time" "git.d3nexus.de/Dadido3/D3vugu-components/components/input" "git.d3nexus.de/Dadido3/D3vugu-components/components/overlay" "git.d3nexus.de/Dadido3/D3vugu-components/icons" "github.com/vugu/vugu" ) type PageOverlays struct { overlay.OverlayContainerRef } func (c *PageOverlays) handleSimpleModalButton(event vugu.DOMEvent) { c.SetModal(&overlay.ModalRequester{ IconSlot: &icons.LInfoCircle{AttrMap: vugu.AttrMap{"style": "font-size: 2em;"}}, Title: "Simple requester", Message: "This is a simple modal requester, are you happy with it?\nIt also supports multi line text!", SignalColor: "d3c-color-attention", ClickAbort: input.ClickFunc(func(event input.ClickEvent) {}), ClickYes: input.ClickFunc(func(event input.ClickEvent) {}), }) } func (c *PageOverlays) handleSimpleToastButton(event vugu.DOMEvent) { c.AddToast(event.EventEnv(), &overlay.ToastSimple{ IconSlot: &icons.LInfoCircle{AttrMap: vugu.AttrMap{"style": "font-size: 2em;"}}, 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) + ".", SignalColor: "d3c-color-attention", }) } func (c *PageOverlays) handleWarningToastButton(event vugu.DOMEvent) { c.AddToast(event.EventEnv(), &overlay.ToastSimple{ IconSlot: &icons.LWarning{AttrMap: vugu.AttrMap{"style": "font-size: 2em;", "class": "d3c-color-caution d3c-icon-use-color"}}, Message: "This is a warning, be careful!", SignalColor: "d3c-color-caution", }) } func (c *PageOverlays) handleToastMessageButton(event vugu.DOMEvent) { c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeCritical, Message: "Uh oh!"}) } func (c *PageOverlays) handleToastMessageTimeoutButton(event vugu.DOMEvent) { c.AddToast(event.EventEnv(), &overlay.ToastMessage{MessageType: overlay.ToastMessageTypeSuccess, Message: "That worked!", Duration: 5 * time.Second}) } func (c *PageOverlays) handleWaitOverlayButton(event vugu.DOMEvent) { c.WaitOverlayOpen() go func() { // Simulate some request or some other action. time.Sleep(5 * time.Second) // We need to lock and unlock the event environment in order for the DOM to re-render and the overlay to disappear correctly. event.EventEnv().Lock() defer event.EventEnv().UnlockRender() defer c.WaitOverlayDone() // WaitOverlayDone has to be called before UnlockRender, so we need to put it afterwards (defer ordering). // Update other UI stuff here. }() }