vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 2.05 kB
Source Map (JSON)
{"version":3,"file":"useToast.mjs","sources":["../../../../../../src/components/va-toast/hooks/useToast.ts"],"sourcesContent":["import { createToastInstance, closeById, closeAllNotifications, NotificationOptions } from '../toast'\nimport { useAppContext } from '../../../composables/useAppContext'\n\n/** This hook can be used without plugin used */\nexport const useToast = () => {\n const appContext = useAppContext()\n\n const createdInThisSetupContext: string[] = []\n\n /**\n * @param options can be options object or message string\n */\n const notify = (options: string | NotificationOptions) => {\n const id = createToastInstance(options, appContext.value)\n\n if (id) { createdInThisSetupContext.push(id) }\n\n return id\n }\n\n /**\n * @deprecated Use `notify` instead\n */\n const init = (options: string | NotificationOptions) => {\n return notify(options)\n }\n\n const close = (id: string) => closeById(id)\n\n /**\n * Closes all VaToast instances in current App instance.\n * @param allApps if you have multiple vue apps on page, set allApps to true to close it for all apps.\n */\n const closeAll = (allApps = false) => closeAllNotifications(allApps ? undefined : appContext.value)\n\n /** Use this method if you need to close only toasts that created with this hook */\n const closeAllCreatedInThisHook = () => {\n createdInThisSetupContext.forEach((id) => closeById(id))\n }\n\n return {\n init, notify, close, closeAll, closeAllCreatedInThisHook,\n }\n}\n"],"names":[],"mappings":";;AAIO,MAAM,WAAW,MAAM;AAC5B,QAAM,aAAa;AAEnB,QAAM,4BAAsC,CAAA;AAKtC,QAAA,SAAS,CAAC,YAA0C;AACxD,UAAM,KAAK,oBAAoB,SAAS,WAAW,KAAK;AAExD,QAAI,IAAI;AAAE,gCAA0B,KAAK,EAAE;AAAA,IAAE;AAEtC,WAAA;AAAA,EAAA;AAMH,QAAA,OAAO,CAAC,YAA0C;AACtD,WAAO,OAAO,OAAO;AAAA,EAAA;AAGvB,QAAM,QAAQ,CAAC,OAAe,UAAU,EAAE;AAMpC,QAAA,WAAW,CAAC,UAAU,UAAU,sBAAsB,UAAU,SAAY,WAAW,KAAK;AAGlG,QAAM,4BAA4B,MAAM;AACtC,8BAA0B,QAAQ,CAAC,OAAO,UAAU,EAAE,CAAC;AAAA,EAAA;AAGlD,SAAA;AAAA,IACL;AAAA,IAAM;AAAA,IAAQ;AAAA,IAAO;AAAA,IAAU;AAAA,EAAA;AAEnC;"}