D3vugu-components/components/overlay/toast-message.go
David Vogel 69160e02c4 Add timeout/duration option to toasts
- Rename overlay-classes.go to interfaces.go
- Add event parameter to AddToast method
- Update overlay example page
2023-05-28 15:04:18 +02:00

38 lines
853 B
Go

package overlay
import "time"
type ToastMessageType int
const (
ToastMessageTypeSuccess ToastMessageType = iota
ToastMessageTypeAttention
ToastMessageTypeCaution
ToastMessageTypeCritical
)
type ToastMessage struct {
MessageType ToastMessageType `vugu:"data"`
Message string `vugu:"data"`
Duration time.Duration // Auto close toast after this duration.
}
func (c *ToastMessage) OverlayClasses() (signalClasses, containerClasses string) {
switch c.MessageType {
case ToastMessageTypeSuccess:
return "d3c-color-success", ""
case ToastMessageTypeAttention:
return "d3c-color-attention", ""
case ToastMessageTypeCaution:
return "d3c-color-caution", ""
case ToastMessageTypeCritical:
return "d3c-color-critical", ""
}
return "", ""
}
func (c *ToastMessage) ToastDuration() time.Duration {
return c.Duration
}