UNPKG

@spaced-out/ui-design-system

Version:
57 lines (55 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toastManager = exports.toastApi = exports.POSITIONS = exports.ACTIONS = void 0; var _helpers = require("../../utils/helpers"); const DEFAULT_AUTOCLOSE_TIME = 8000; // default auto close time for with autoClose = true (be default true) but timeout not passed. const POSITIONS = exports.POSITIONS = { TOP_CENTER: 'topCenter', TOP_LEFT: 'topLeft', TOP_RIGHT: 'topRight', BOTTOM_LEFT: 'bottomLeft', BOTTOM_RIGHT: 'bottomRight', BOTTOM_CENTER: 'bottomCenter' }; const ACTIONS = exports.ACTIONS = { ADD: 'ADD', REMOVE: 'REMOVE' }; const defaultOptions = { autoClose: true, timeout: DEFAULT_AUTOCLOSE_TIME, position: POSITIONS.BOTTOM_LEFT }; const toastManager = exports.toastManager = (() => { let callbackFn; const manager = { subscribe(callback) { callbackFn = callback; }, add(content, options) { const mergedOptions = { ...defaultOptions, ...options }; const toastId = (0, _helpers.uuid)(); callbackFn?.(ACTIONS.ADD, content, { ...mergedOptions, id: toastId }); return toastId; }, remove(id) { callbackFn(ACTIONS.REMOVE, null, { id }); return true; } }; return manager; })(); const toastApi = exports.toastApi = { show: (content, options) => toastManager.add(content, options), remove: id => toastManager.remove(id) };