Skip to content

Popup

Simple notification pop-up.

Usage

Simple Usage

ts
import { popup } from '@privyid/persona/core'

popup('This is popup message', 'Hi!')

Advance Usage

ts
import { popup } from '@privyid/persona/core'

popup({
  type      : 'error',
  title     : 'Lorem ipsum',
  text      : 'Lorem ipsum dolor sit amet.',
  variant   : 'filled',
  duration  : 5000,
  popupClass: 'custom-popup',
})

Type Variant

There available 4 type variants: info, success, warning, error. default is info

preview

Try it:

ts
import { popup } from '@privyid/persona/core'

// info
popup({
  type : 'info',
  title: 'Lorem ipsum',
  text : 'Lorem ipsum dolor sit amet.',
})

// success
popup({
  type : 'success',
  title: 'Lorem ipsum',
  text : 'Lorem ipsum dolor sit amet.',
})

// Using shorthand
// warning
popup('Lorem ipsum dolor sit amet.', 'Lorem ipsum', 'warning')
// error
popup('Lorem ipsum dolor sit amet.', 'Lorem ipsum', 'error')

Style Variant

There available 2 style variant: simple and filled. default is simple

preview

Try it:

ts
import { popup } from '@privyid/persona/core'

// info
popup({
  type   : 'info',
  variant: 'filled',
  title  : 'Lorem ipsum',
  text   : 'Lorem ipsum dolor sit amet.',
})

// success
popup({
  type   : 'success',
  variant: 'filled',
  title  : 'Lorem ipsum',
  text   : 'Lorem ipsum dolor sit amet.',
})

// Using shorthand
// warning
popup('Lorem ipsum dolor sit amet.', 'Lorem ipsum', 'warning', 'filled')
// error
popup('Lorem ipsum dolor sit amet.', 'Lorem ipsum', 'error', 'filled')

Position

There available 6 position for popup: top-left, top-center, top-right, bottom-left, bottom-center, top-right default is bottom-left

Try it:

ts
import { popup } from '@privyid/persona/core'

// top-left
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'top-left'
})

// top-center
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'top-center'
})

// top-right
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'top-right'
})

// bottom-left
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'bottom-left'
})

// bottom-center
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'bottom-center'
})

// bottom-right
popup({
  title   : 'Lorem ipsum',
  text    : 'Lorem ipsum dolor sit amet.',
  position: 'bottom-right'
})

Icon

It's possible to custom icon of toast, like color and icon-name. There are 6 icon colors available for toast: default, primary, info, success, warning and danger. Default icon color is toast icon color it's self.

ts
import { markRaw } from 'vue-demi'
import { popup } from '@privyid/persona/core'
import IconSuccess from '@privyid/persona-icon/vue/checkmark/24.vue'
import IconFailed from '@privyid/persona-icon/vue/trash/24.vue'

popup({
  text     : 'Member added to the group',
  icon     : markRaw(IconSuccess),
  iconColor: 'success',
})

popup({
  text   : 'Members removed from the group',
  type   : 'error',
  variant: 'filled',
  icon   : markRaw(IconFailed),
})

Actions

Add additional button using option actions.

preview
ts
popup({
  title     : 'Upload success',
  text      : 'Upload document successfully.',
  actions   : [
    {
      text: 'Goto Doc',
      onClick (event) {
        // Do something
        // ...
        event.close()
      }
    }
  ],
})

Dismissable

Dismiss button of toast can be show or hide by dismissable props. If dismissable set to true, dismiss button will show.

preview
ts
import { toast } from '@privyid/persona/core'

toast({
  title      : 'Lorem ipsum dolor sit amet.',
  variant    : 'filled',
  dismissable: false,
})

Customization

You can add some custom class to Popup element via popupClass and popupAttrs.

ts
import { popup } from '@privyid/persona/core'

popup({
  title     : 'Lorem ipsum',
  text      : 'Lorem ipsum dolor sit amet.',
  popupClass: 'h-40',
  popupAttrs: { 'data-e2eid': 'popup-custom' }
})

API

popup(options: PopupOptions): Promise<CloseFn>

OptionsTypeDefaultDescription
typeStringinfoToast type variant, valid value is info, success, warning, error
titleString-Toast title message (support markdown)
textString-Toast text message (support markdown)
variantStringsimpleToast style variant, valid value is simple, filled
durationNumber3000Duration for which the popup should be displayed. -1 to permanent popup
positionStringbottom-leftPosition for popup, valid value is top-left, top-center, top-right, bottom-left, bottom-center, top-right
iconString or Component-Custom popup icon (will replace default icon)
iconColorString-Custom color of popup icon, valid value is default, primary, info, success, warning, danger
popupClassString-Add class to popup component
popupAttrsObject-Add attribute to popup component
dismissableBooleantrueEnable dismiss button
actionsArray<ActionOption>-Add action button

In actions contains:

PropsTypeDefaultDescription
textString-Action button's text
attrsObject-Action additional attribute
onClickFunction-Action on-click handler

Shorthand

popup(text: string, title?: string, type?: string, variant?: string): Promise<CloseFn>

See Also

Released under the MIT License.