Notifications
Iridium supports a basic form of notifications for V1. What's coming?
Notifications can be fired to your user on any request, by writing to a specific response header and allowing Alpine.js to display them.
Sending a notification
Any place within your forms, tables, pages, etc., where you have access to the current net/http writer struct allows you to send a notification to your users when their request finishes. You'll generally have access to the writer in your contexts, like in a form field's FieldContext, or an action's ActionContext.
Example of sending a notification
RecordAction("my-action").
Handler(
func(ctx RecordActionContext) {
notification.NewNotification("Notifying you!").
Type(notification.Success).
Description("here's a description of your notification").
Position(notification.BottomLeft).
Send(ctx.Writer)
},
)You're also able to directly instantiate a notification instead of using a builder pattern
RecordAction("my-action").
Handler(
func(ctx RecordActionContext) {
notification.Notify(
ctx.Writer, ¬ification.Notification{
TitleStr: ctx.Record.Name,
TypeStr: "info",
PositionStr: "bottom-right",
},
)
},
)Notification Methods
New Notification
You can create a new notification as so. The provided string is the title of your notification
notification.NewNotification("Notifying you!").Type
Notifications support four types: success, danger, info, and warning. If none is provided, it will default to an info notification.
// Your custom theme can override these colours.
Type(notifications.Success) // Green check mark
Type(notifications.Danger) // Red alert
Type(notifications.Info) // Grey info icon
Type(notification.Warning) // Yellow warning signDescription
You can optionally include a description for your notifications. It will render underneath your notifications icon & title.
Description("My description here!")Position
You can choose which part of the user's screen a notification will render on. The default location is top-right.
Position(notifications.TopLeft)
Position(notifications.Top)
Position(notifications.TopRight)
Position(notifications.BottomLeft)
Position(notifications.Bottom)
Position(notifications.BottomRight)