HexagonJS
Edit Page
Alerts and Messages
Provides the alert and message functions
Module Requirements
This module requires the "Font Awesome 5 Free" font to be available on the page
The npm package used for a given release can be found in package.json under optionalDependencies
About
Alerts and messages are essentially the same, with messages being a sub-type of alerts. The key difference between messages and alerts is that messages will auto-dismiss themselves after a set duration and do not show a close button, while alert will persist on screen until the close button is clicked. Both message and alert return an Alert and have the same methods available.
Messages should be used to show information that is useful for the user to know, but isn’t critical, or too complex. The best example of success message stating a task was completed successfully. Without the message the user will not know if the system was able to complete the task. If the user finds they need to dismiss the message and it is too distracting to the workflow, this is a good case to use message instead of alert.
Alert Types
Default: use as informational/neutral alerts.
Success: use to inform of successful completion of a task.
Warning: use to alert of issues that do not require the user to take action, but be aware of them.
Danger: use to inform user of errors and unsuccessful completion of tasks. It is advised to provide advice on how to resolve the issue in the alert.
Message Types
Default: use as informational/neutral messages.
Success: use to inform of successful completion of a task.
Examples

HTML

<div id="alertsDemo"></div>

JavaScript

hx.select('#alertsDemo')
  .set([
    hx.div('hx-header-small').text('Alerts'),
    hx.detached('br'),
    hx.button('hx-btn hx-flag-button').text('Success').on('click', () => hx.alert({
      title: 'This is a success alert.',
      body: 'Use it to let users know that something was successful.',
      type: 'success',
    })),
    hx.button('hx-btn hx-flag-button').text('Warning').on('click', () => hx.alert({
      title: 'This is a warning alert.',
      body: 'Use it to tell users about something that could be a problem, but won\'t block them from doing things yet.',
      type: 'warning',
    })),
    hx.button('hx-btn hx-flag-button').text('Danger').on('click', () => hx.alert({
      title: 'This is an error alert.',
      body: 'Use it to tell users about errors. Include steps that the user can take to resolve the error, even if it\'s just "Try again".',
      type: 'danger',
    })),
    hx.button('hx-btn hx-flag-button').text('Default').on('click', () => hx.alert({
      title: 'This is an information alert.',
      body: 'Use it for alerts that don\'t fit into the other three categories.',
    })),
    hx.detached('br'),
    hx.detached('br'),
    hx.detached('hr'),
    hx.div('hx-header-small').text('Messages'),
    hx.detached('br'),
    hx.button('hx-btn hx-flag-button').text('Success').on('click', () => hx.message({
      title: 'This is a success message.',
      body: 'Use it to let users know that something was successful.',
      type: 'success',
    })),
    hx.button('hx-btn hx-flag-button').text('Default').on('click', () => hx.message({
      title: 'This is an information message.',
      body: 'Use it for messages that don\'t fit into the other three categories.',
    })),
  ]);
Api
Prototypes
Alert
The constructor for the alerts used by hx.alert and hx.message
Methods
close
Closes this alert
hx.AlertManager
The constructor for creating a custom alert manager. The alert and message methods use the default alert manager that creates a container within body
Constructors
hx.AlertManagerselectorString / Selection / HTMLElementoptionsObject
Arguments
selectorString / Selection / HTMLElement
The selector for the element the container should be created inside
options
Properties
animationInDurationNumber
Sets the animationInDuration for the alerts/messages shown from this alert manager (in milliseconds)
This controls how long it takes for the alerts/messages to appear when closing (i.e. the animation duration)
Default: 200
animationOutDurationNumber
Sets the animationOutDuration for the alerts/messages shown from this alert manager (in milliseconds)
This controls how long it takes for the alerts/messages to disappear when closing (i.e. the animation duration)
Default: 200
maxMessageDurationNumber
Sets the maxMessageDuration for the alerts/messages shown from this alert manager (in milliseconds)
This controls the maximum duration messages should be displayed for when not passing in duration to the message method.
This is not used when a length is specified in the message options.
Default: 7000
minMessageDurationNumber
Sets the minMessageDuration for the alerts/messages shown from this alert manager (in milliseconds)
This controls the minimum duration messages should be displayed for when not passing in duration to the message method.
This is not used when a length is specified in the message options.
Default: 2000
Functions
hx.alertoptionsObjectAlert
Displays an alert notification that can only be dismissed by the user clicking the close button or by calling the close method.
This utilises the inbuilt alert manager that will add the alert container to the body
Arguments
options
Properties
bodyString
The main alert body to display next to the title.
titleString
The title to display in bold in the alert. This should be a short summary of the alert.
typeString
The type of message. Can be success, danger, warning or undefined
Returns
Alert
The alert that was added
hx.messageoptionsObjectAlert
Displays an alert notification that can only be dismissed by the user clicking the close button or by calling the close method.
This utilises the inbuilt alert manager that will add the alert container to the body
Arguments
options
Properties
bodyString
The main alert body to display next to the title.
durationNumber
The time (in milliseconds) that the message shoiuld display. When undefined, this value is calcuated using Math.min(Math.max(numCharacters, minMessageDuration), maxMessageDuration)
minMessageDuration is 2000 and maxMessageDuration is 7000 by default.
titleString
The title to display in bold in the alert. This should be a short summary of the alert.
typeString
The type of message. Can be success or undefined
Returns
Alert
The alert that was added