Skip to content

Swal

Swal — UI component for displaying alert, confirm and prompt dialogs

ts
import { Swal } from '@aspro-cloud/miniapp-jssdk'

Constructor

Creates a Swal instance with the given parameters

ts
constructor(params: SwalParams)
ParameterTypeDescription
paramsSwalParamsDialog creation parameters

Properties

events

Object of type EventCallbacks<SwalEventName> with event handlers

ts
get events(): EventCallbacks
set events(value: EventCallbacks)

message

Dialog message text

ts
message: string

title

Dialog title

ts
title: string

view

Dialog view of type SwalView

ts
get view(): SwalView
set view(value: SwalView)

Methods

alert

Shows an alert dialog

ts
async alert(): Promise<any>

alert() method events:

EventParameterTypeDescription
'onShow'Dialog is shown
'onHide'Dialog is hidden
'onConfirm'User confirmed the action

confirm

Shows a confirm dialog

ts
async confirm(): Promise<any>

confirm() method events:

EventParameterTypeDescription
'onShow'Dialog is shown
'onHide'Dialog is hidden
'onCancel'User cancelled the action
'onConfirm'User confirmed the action

destroy

Removes subscriptions and frees resources

ts
destroy(): void

prompt

Shows a prompt dialog with parameters of type SwalPromptParams

ts
async prompt(params?: SwalPromptParams): Promise<any>
ParameterTypeDescription
paramsSwalPromptParamsInput field parameters

prompt() method events:

EventParameterTypeDescription
'onShow'Dialog is shown
'onHide'Dialog is hidden
'onCancel'User cancelled the action
'onPrompt'User entered a value
valuestringEntered value

Example

Displaying an informational message:

ts
import { App, Swal } from '@aspro-cloud/miniapp-jssdk'

await App.initializeFrame()

const swal = new Swal({
  view: 'info',
  title: 'Information',
  message: 'This is just an informational message',
  events: {
    onShow: () => console.log('Message shown'),
    onHide: () => console.log('Message hidden'),
    onCancel: () => console.log('Declined by user'),
  }
})

swal.alert();
js
const App = window.ACloudMiniApp;

await App.initializeFrame();

const swal = new App.Frame.Swal({
  view: 'info',
  title: 'Information',
  message: 'This is just an informational message',
  events: {
    onShow: () => console.log('Message shown'),
    onHide: () => console.log('Message hidden'),
    onCancel: () => console.log('Declined by user'),
  }
});

swal.alert();

Displaying a confirmation dialog:

ts
import { App, Swal } from '@aspro-cloud/miniapp-jssdk'

await App.initializeFrame()

const swal = new Swal({
  view: 'warning',
  title: 'Confirm action',
  message: 'Delete account',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onConfirm: () => console.log('Accepted by user')
  }
})

await swal.confirm()
js
const App = window.ACloudMiniApp;

await App.initializeFrame();

const swal = new App.Frame.Swal({
  view: 'warning',
  title: 'Confirm action',
  message: 'Delete account',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onConfirm: () => console.log('Accepted by user')
  }
});

await swal.confirm();

Displaying a dialog with an input field:

ts
import { App, Swal } from '@aspro-cloud/miniapp-jssdk'

await App.initializeFrame()

let swal = new Swal({
  view: 'warning',
  title: 'Specify quantity',
  message: 'Please enter the quantity:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
})

await swal.prompt({
  type: 'input',
  placeholder: 'Enter value',
})
js
const App = window.ACloudMiniApp;

await App.initializeFrame();

let swal = new App.Frame.Swal({
  view: 'warning',
  title: 'Specify quantity',
  message: 'Please enter the quantity:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
});

await swal.prompt({
  type: 'input',
  placeholder: 'Enter value',
});

Displaying a dialog with a textarea field:

ts
import { App, Swal } from '@aspro-cloud/miniapp-jssdk'

await App.initializeFrame()

let swal = new Swal({
  view: 'warning',
  title: 'Specify the reason',
  message: 'Please specify the reason:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
})

await swal.prompt({
  type: 'textarea',
  placeholder: 'Enter value',
})
js
const App = window.ACloudMiniApp;

await App.initializeFrame();

let swal = new App.Frame.Swal({
  view: 'warning',
  title: 'Specify the reason',
  message: 'Please specify the reason:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
});

await swal.prompt({
  type: 'textarea',
  placeholder: 'Enter value',
});

Displaying a dialog with a dropdown selection:

ts
import { App, Swal } from '@aspro-cloud/miniapp-jssdk'

await App.initializeFrame()

let swal = new Swal({
  view: 'warning',
  title: 'Change status',
  message: 'Select new status:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
})

await swal.prompt({
  type: 'select',
  options: [
    {value: 'active', title: 'Active'},
    {value: 'inprocessing', title: 'In progress'},
    {value: 'done', title: 'Done'}
  ],
})
js
const App = window.ACloudMiniApp;

await App.initializeFrame();

let swal = new App.Frame.Swal({
  view: 'warning',
  title: 'Change status',
  message: 'Select new status:',
  events: {
    onShow: () => console.log('Dialog shown'),
    onHide: () => console.log('Dialog hidden'),
    onCancel: () => console.log('Declined by user'),
    onPrompt: (value) => console.log(`Entered value: ${value}`)
  }
});

await swal.prompt({
  type: 'select',
  options: [
    {value: 'active', title: 'Active'},
    {value: 'inprocessing', title: 'In progress'},
    {value: 'done', title: 'Done'}
  ],
});

Published under the MIT license.