UNPKG

simple-notify

Version:

Simple Notify is a pure Javascript library to show nice and customizable alert notifications.

1 lines 22.2 kB
{"version":3,"sources":["../src/icons/close.svg","../src/icons/error.svg","../src/icons/info.svg","../src/icons/success.svg","../src/icons/warning.svg","../src/utils.ts","../src/consts.ts","../src/effects.ts","../src/index.ts"],"names":["close_default","error_default","info_default","success_default","warning_default","stringToHTML","__name","strHTML","getSvgNode","svg","doc","CLASSNAMES","NOTIFY_STATUS_ENUMS","NOTIFY_TYPE_ENUMS","NOTIFY_ANIMATION_ENUMS","ICONS","fadeIn","self","fadeOut","slideIn","slideOut","_Notify","args","callback","notificationsGap","notificationsPadding","status","effect","type","title","text","showIcon","customIcon","customClass","speed","showCloseButton","autoclose","autotimeout","position","customWrapper","container","closeWrapper","className","contentWrapper","titleElement","textElement","computedIcon","iconWrapper","observer","entries","Notify"],"mappings":"+EAAA,IAAAA,EAAA;AAAA;AAAA;ECAA,IAAAC,EAAA;AAAA;AAAA;ECAA,IAAAC,EAAA;AAAA;AAAA;ECAA,IAAAC,EAAA;AAAA;AAAA;ECAA,IAAAC,EAAA;AAAA;AAAA;ECAO,IAAMC,EAAeC,EAACC,GACZ,IAAI,UAAU,EAEd,gBAAgBA,EADnB,WACmC,EAEpC,KAAK,WAAW,CAAC,EALF,gBAQfC,EAAaF,EAACG,GAAgB,CACzC,IAAMC,EAAM,IAAI,UAAU,EAAE,gBAAgBD,EAAK,iBAAiB,EAElE,OADa,SAAS,WAAWC,EAAI,gBAAiB,EAAI,EAC9C,SACd,EAJ0B,cCDnB,IAAMC,EAAa,CACxB,UAAW,6BACX,OAAQ,YACR,eAAgB,oBAChB,YAAa,iBACb,aAAc,kBACd,aAAc,kBACd,YAAa,iBACb,YAAa,iBACb,YAAa,iBACb,UAAW,eACX,QAAS,aACT,SAAU,cACV,OAAQ,YACR,UAAW,eACX,eAAgB,oBAChB,cAAe,mBACf,aAAc,kBACd,eAAgB,oBAChB,eAAgB,oBAChB,YAAa,iBACb,YAAa,iBACb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ArB7B,EAgSE,WAAmB,OAAS6B","sourcesContent":["<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"m8.94 8 4.2-4.193a.67.67 0 0 0-.947-.947L8 7.06l-4.193-4.2a.67.67 0 1 0-.947.947L7.06 8l-4.2 4.193a.667.667 0 0 0 .217 1.093.666.666 0 0 0 .73-.146L8 8.94l4.193 4.2a.666.666 0 0 0 1.094-.217.665.665 0 0 0-.147-.73L8.94 8Z\" fill=\"currentColor\"/>\r\n</svg>\r\n","<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24A10.667 10.667 0 0 1 5.333 16a10.56 10.56 0 0 1 2.254-6.533l14.946 14.946A10.56 10.56 0 0 1 16 26.667Zm8.413-4.134L9.467 7.587A10.56 10.56 0 0 1 16 5.333 10.667 10.667 0 0 1 26.667 16a10.56 10.56 0 0 1-2.254 6.533Z\" fill=\"currentColor\"/>\r\n</svg>\r\n","<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M16 14.667A1.333 1.333 0 0 0 14.667 16v5.333a1.333 1.333 0 0 0 2.666 0V16A1.333 1.333 0 0 0 16 14.667Zm.507-5.227a1.333 1.333 0 0 0-1.014 0 1.334 1.334 0 0 0-.44.28 1.56 1.56 0 0 0-.28.44c-.075.158-.11.332-.106.507a1.332 1.332 0 0 0 .386.946c.13.118.279.213.44.28a1.334 1.334 0 0 0 1.84-1.226 1.4 1.4 0 0 0-.386-.947 1.334 1.334 0 0 0-.44-.28ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z\" fill=\"currentColor\"/>\r\n</svg>\r\n","<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"m19.627 11.72-5.72 5.733-2.2-2.2a1.334 1.334 0 1 0-1.88 1.881l3.133 3.146a1.333 1.333 0 0 0 1.88 0l6.667-6.667a1.333 1.333 0 1 0-1.88-1.893ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z\" fill=\"currentColor\"/>\r\n</svg>\r\n","<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M16.334 17.667a1.334 1.334 0 0 0 1.334-1.333v-5.333a1.333 1.333 0 0 0-2.665 0v5.333a1.333 1.333 0 0 0 1.33 1.333Zm-.508 5.227c.325.134.69.134 1.014 0 .165-.064.314-.159.44-.28a1.56 1.56 0 0 0 .28-.44c.076-.158.112-.332.107-.507a1.332 1.332 0 0 0-.387-.946 1.532 1.532 0 0 0-.44-.28 1.334 1.334 0 0 0-1.838 1.226 1.4 1.4 0 0 0 .385.947c.127.121.277.216.44.28Zm.508 6.773a13.333 13.333 0 1 0 0-26.667 13.333 13.333 0 0 0 0 26.667Zm0-24A10.667 10.667 0 1 1 16.54 27a10.667 10.667 0 0 1-.206-21.333Z\" fill=\"currentColor\"/>\r\n</svg>\r\n","export const stringToHTML = (strHTML: string): HTMLElement => {\r\n const parser = new DOMParser(),\r\n content = 'text/html',\r\n DOM = parser.parseFromString(strHTML, content)\r\n\r\n return DOM.body.childNodes[0] as HTMLElement\r\n}\r\n\r\nexport const getSvgNode = (svg: string) => {\r\n const doc = new DOMParser().parseFromString(svg, 'application/xml')\r\n const node = document.importNode(doc.documentElement, true)\r\n return node.outerHTML\r\n}\r\n","import SvgClose from './icons/close.svg'\r\nimport SvgError from './icons/error.svg'\r\nimport SvgInfo from './icons/info.svg'\r\nimport SvgSuccess from './icons/success.svg'\r\nimport SvgWarning from './icons/warning.svg'\r\nimport { getSvgNode } from './utils'\r\n\r\nexport const CLASSNAMES = {\r\n CONTAINER: 'sn-notifications-container',\r\n NOTIFY: 'sn-notify',\r\n NOTIFY_CONTENT: 'sn-notify-content',\r\n NOTIFY_ICON: 'sn-notify-icon',\r\n NOTIFY_CLOSE: 'sn-notify-close',\r\n NOTIFY_TITLE: 'sn-notify-title',\r\n NOTIFY_TEXT: 'sn-notify-text',\r\n IS_X_CENTER: 'sn-is-x-center',\r\n IS_Y_CENTER: 'sn-is-y-center',\r\n IS_CENTER: 'sn-is-center',\r\n IS_LEFT: 'sn-is-left',\r\n IS_RIGHT: 'sn-is-right',\r\n IS_TOP: 'sn-is-top',\r\n IS_BOTTOM: 'sn-is-bottom',\r\n NOTIFY_OUTLINE: 'sn-notify-outline',\r\n NOTIFY_FILLED: 'sn-notify-filled',\r\n NOTIFY_ERROR: 'sn-notify-error',\r\n NOTIFY_WARNING: 'sn-notify-warning',\r\n NOTIFY_SUCCESS: 'sn-notify-success',\r\n NOTIFY_INFO: 'sn-notify-info',\r\n NOTIFY_FADE: 'sn-notify-fade',\r\n NOTIFY_FADE_IN: 'sn-notify-fade-in',\r\n NOTIFY_SLIDE: 'sn-notify-slide',\r\n NOTIFY_SLIDE_IN: 'sn-notify-slide-in',\r\n NOTIFY_AUTOCLOSE: 'sn-notify-autoclose'\r\n} as const\r\n\r\nexport const NOTIFY_STATUS_ENUMS = {\r\n ERROR: 'error',\r\n WARNING: 'warning',\r\n SUCCESS: 'success',\r\n INFO: 'info'\r\n} as const\r\n\r\nexport const NOTIFY_TYPE_ENUMS = {\r\n OUTLINE: 'outline',\r\n FILLED: 'filled'\r\n} as const\r\n\r\nexport const NOTIFY_ANIMATION_ENUMS = {\r\n FADE: 'fade',\r\n SLIDE: 'slide'\r\n} as const\r\n\r\nexport const ICONS = {\r\n CLOSE: getSvgNode(SvgClose),\r\n SUCCESS: getSvgNode(SvgSuccess),\r\n ERROR: getSvgNode(SvgError),\r\n WARNING: getSvgNode(SvgWarning),\r\n INFO: getSvgNode(SvgInfo)\r\n}\r\n","import { CLASSNAMES } from './consts'\r\nimport type Notify from './index'\r\n\r\nexport const fadeIn = (self: Notify): void => {\r\n self.wrapper.classList.add(CLASSNAMES.NOTIFY_FADE)\r\n setTimeout(() => {\r\n self.wrapper.classList.add(CLASSNAMES.NOTIFY_FADE_IN)\r\n }, 100)\r\n}\r\n\r\nexport const fadeOut = (self: Notify): void => {\r\n self.wrapper.classList.remove(CLASSNAMES.NOTIFY_FADE_IN)\r\n setTimeout(() => {\r\n self.wrapper.remove()\r\n }, self.speed)\r\n}\r\n\r\nexport const slideIn = (self: Notify): void => {\r\n self.wrapper.classList.add(CLASSNAMES.NOTIFY_SLIDE)\r\n setTimeout(() => {\r\n self.wrapper.classList.add(CLASSNAMES.NOTIFY_SLIDE_IN)\r\n }, 100)\r\n}\r\nexport const slideOut = (self: Notify): void => {\r\n self.wrapper.classList.remove(CLASSNAMES.NOTIFY_SLIDE_IN)\r\n setTimeout(() => {\r\n self.wrapper.remove()\r\n }, self.speed)\r\n}\r\n","import { CLASSNAMES, ICONS, NOTIFY_ANIMATION_ENUMS, NOTIFY_STATUS_ENUMS, NOTIFY_TYPE_ENUMS } from './consts'\r\nimport { fadeIn, fadeOut, slideIn, slideOut } from './effects'\r\nimport './style.css'\r\nimport type { IArgs, NotifyEffect, NotifyPosition, NotifyStatus, NotifyType } from './types'\r\nimport { stringToHTML } from './utils'\r\n\r\nexport type { IArgs, NotifyEffect, NotifyPosition, NotifyStatus, NotifyType }\r\n\r\nexport default class Notify {\r\n wrapper: HTMLElement\r\n customWrapper: string\r\n container: HTMLElement\r\n status: NotifyStatus\r\n type: NotifyType\r\n effect: NotifyEffect\r\n position: NotifyPosition\r\n title: string\r\n text: string\r\n showIcon: boolean\r\n customIcon: string\r\n showCloseButton: boolean\r\n customClass: string\r\n speed: number\r\n autoclose: boolean\r\n autotimeout: number\r\n notificationsGap: number\r\n notificationsPadding: number\r\n selectedNotifyInEffect: (self: Notify) => void\r\n selectedNotifyOutEffect: (self: Notify) => void\r\n\r\n constructor(args: IArgs) {\r\n const {\r\n notificationsGap = 20,\r\n notificationsPadding = 20,\r\n status = 'success',\r\n effect = NOTIFY_ANIMATION_ENUMS.FADE,\r\n type = 'outline',\r\n title,\r\n text,\r\n showIcon = true,\r\n customIcon = '',\r\n customClass = '',\r\n speed = 500,\r\n showCloseButton = true,\r\n autoclose = true,\r\n autotimeout = 3000,\r\n position = 'right top',\r\n customWrapper = ''\r\n } = args\r\n\r\n this.customWrapper = customWrapper\r\n this.status = status\r\n this.title = title\r\n this.text = text\r\n this.showIcon = showIcon\r\n this.customIcon = customIcon\r\n this.customClass = customClass\r\n this.speed = speed\r\n this.effect = effect\r\n this.showCloseButton = showCloseButton\r\n this.autoclose = autoclose\r\n this.autotimeout = autotimeout\r\n this.notificationsGap = notificationsGap\r\n this.notificationsPadding = notificationsPadding\r\n this.type = type\r\n this.position = position\r\n\r\n if (!this.checkRequirements()) {\r\n console.error(\"You must specify 'title' or 'text' at least.\")\r\n return\r\n }\r\n\r\n // set outer container for all Notify's\r\n this.setContainer()\r\n\r\n // set wrapper for each Notify\r\n this.setWrapper()\r\n\r\n this.setPosition()\r\n\r\n // set icon in the left\r\n if (this.showIcon) this.setIcon()\r\n\r\n // set close button\r\n if (this.showCloseButton) this.setCloseButton()\r\n\r\n // set title, text\r\n this.setContent()\r\n\r\n // add the Notify to our container\r\n this.container.prepend(this.wrapper)\r\n\r\n // init effect\r\n this.setEffect()\r\n this.notifyIn(this.selectedNotifyInEffect)\r\n\r\n // init autoclose\r\n if (this.autoclose) this.autoClose()\r\n\r\n // check whether Notify is visible\r\n this.setObserver()\r\n }\r\n\r\n private checkRequirements(): boolean {\r\n return !!(this.title || this.text)\r\n }\r\n\r\n private setContainer(): void {\r\n const container: HTMLElement = document.querySelector(`.${CLASSNAMES.CONTAINER}`)\r\n if (container) {\r\n this.container = container\r\n } else {\r\n this.container = document.createElement('div')\r\n this.container.classList.add(CLASSNAMES.CONTAINER)\r\n document.body.appendChild(this.container)\r\n }\r\n\r\n if (this.notificationsPadding) {\r\n this.container.style.setProperty('--sn-notifications-padding', `${this.notificationsPadding}px`)\r\n }\r\n\r\n if (this.notificationsGap) {\r\n this.container.style.setProperty('--sn-notifications-gap', `${this.notificationsGap}px`)\r\n }\r\n }\r\n\r\n private setPosition(): void {\r\n this.container.classList[this.position === 'center' ? 'add' : 'remove'](CLASSNAMES.IS_CENTER)\r\n this.container.classList[this.position.includes('left') ? 'add' : 'remove'](CLASSNAMES.IS_LEFT)\r\n this.container.classList[this.position.includes('right') ? 'add' : 'remove'](CLASSNAMES.IS_RIGHT)\r\n this.container.classList[this.position.includes('top') ? 'add' : 'remove'](CLASSNAMES.IS_TOP)\r\n this.container.classList[this.position.includes('bottom') ? 'add' : 'remove'](CLASSNAMES.IS_BOTTOM)\r\n this.container.classList[this.position.includes('x-center') ? 'add' : 'remove'](CLASSNAMES.IS_X_CENTER)\r\n this.container.classList[this.position.includes('y-center') ? 'add' : 'remove'](CLASSNAMES.IS_Y_CENTER)\r\n }\r\n\r\n private setCloseButton(): void {\r\n const closeWrapper = document.createElement('div')\r\n closeWrapper.classList.add(CLASSNAMES.NOTIFY_CLOSE)\r\n closeWrapper.innerHTML = ICONS.CLOSE\r\n this.wrapper.appendChild(closeWrapper)\r\n\r\n closeWrapper.addEventListener('click', () => {\r\n this.close()\r\n })\r\n }\r\n\r\n private setWrapper(): void {\r\n if (this.customWrapper) {\r\n this.wrapper = stringToHTML(this.customWrapper)\r\n } else {\r\n this.wrapper = document.createElement('div')\r\n }\r\n this.wrapper.style.setProperty('--sn-notify-transition-duration', `${this.speed}ms`)\r\n\r\n // set classes\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY)\r\n\r\n switch (this.type) {\r\n case NOTIFY_TYPE_ENUMS.OUTLINE:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_OUTLINE)\r\n break\r\n case NOTIFY_TYPE_ENUMS.FILLED:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_FILLED)\r\n break\r\n default:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_OUTLINE)\r\n }\r\n\r\n switch (this.status) {\r\n case NOTIFY_STATUS_ENUMS.SUCCESS:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_SUCCESS)\r\n break\r\n case NOTIFY_STATUS_ENUMS.ERROR:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_ERROR)\r\n break\r\n case NOTIFY_STATUS_ENUMS.WARNING:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_WARNING)\r\n break\r\n case NOTIFY_STATUS_ENUMS.INFO:\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_INFO)\r\n break\r\n }\r\n\r\n if (this.autoclose) {\r\n this.wrapper.classList.add(CLASSNAMES.NOTIFY_AUTOCLOSE)\r\n this.wrapper.style.setProperty('--sn-notify-autoclose-timeout', `${this.autotimeout + this.speed}ms`)\r\n }\r\n\r\n if (this.customClass) {\r\n const classes = this.customClass.split(' ')\r\n classes.forEach((className) => {\r\n this.wrapper.classList.add(className)\r\n })\r\n }\r\n }\r\n\r\n private setContent(): void {\r\n const contentWrapper = document.createElement('div')\r\n contentWrapper.classList.add(CLASSNAMES.NOTIFY_CONTENT)\r\n\r\n let titleElement, textElement\r\n\r\n if (this.title) {\r\n titleElement = document.createElement('div')\r\n titleElement.classList.add(CLASSNAMES.NOTIFY_TITLE)\r\n titleElement.textContent = this.title.trim()\r\n if (!this.showCloseButton) titleElement.style.paddingRight = '0'\r\n }\r\n\r\n if (this.text) {\r\n textElement = document.createElement('div')\r\n textElement.classList.add(CLASSNAMES.NOTIFY_TEXT)\r\n textElement.innerHTML = this.text.trim()\r\n if (!this.title) textElement.style.marginTop = '0'\r\n }\r\n\r\n this.wrapper.appendChild(contentWrapper)\r\n if (this.title) contentWrapper.appendChild(titleElement)\r\n if (this.text) contentWrapper.appendChild(textElement)\r\n }\r\n\r\n private setIcon(): void {\r\n const computedIcon = (status: NotifyStatus) => {\r\n switch (status) {\r\n case NOTIFY_STATUS_ENUMS.SUCCESS:\r\n return ICONS.SUCCESS\r\n case NOTIFY_STATUS_ENUMS.ERROR:\r\n return ICONS.ERROR\r\n case NOTIFY_STATUS_ENUMS.WARNING:\r\n return ICONS.WARNING\r\n case NOTIFY_STATUS_ENUMS.INFO:\r\n return ICONS.INFO\r\n }\r\n }\r\n\r\n const iconWrapper = document.createElement('div')\r\n iconWrapper.classList.add(CLASSNAMES.NOTIFY_ICON)\r\n iconWrapper.innerHTML = this.customIcon || computedIcon(this.status)\r\n if (this.status || this.customIcon) this.wrapper.appendChild(iconWrapper)\r\n }\r\n\r\n private setObserver(): void {\r\n const observer = new IntersectionObserver(\r\n (entries) => {\r\n if (!(entries[0].intersectionRatio <= 0)) {\r\n return\r\n } else {\r\n this.close()\r\n }\r\n },\r\n {\r\n threshold: 0\r\n }\r\n )\r\n\r\n setTimeout(() => {\r\n observer.observe(this.wrapper)\r\n }, this.speed)\r\n }\r\n\r\n private notifyIn(callback: (p: Notify) => void): void {\r\n callback(this)\r\n }\r\n\r\n private notifyOut = (callback: (p: Notify) => void): void => {\r\n callback(this)\r\n }\r\n\r\n private autoClose(): void {\r\n setTimeout(() => {\r\n this.close()\r\n }, this.autotimeout + this.speed)\r\n }\r\n\r\n public close(): void {\r\n this.notifyOut(this.selectedNotifyOutEffect)\r\n }\r\n\r\n private setEffect(): void {\r\n switch (this.effect) {\r\n case NOTIFY_ANIMATION_ENUMS.FADE:\r\n this.selectedNotifyInEffect = fadeIn\r\n this.selectedNotifyOutEffect = fadeOut\r\n break\r\n case NOTIFY_ANIMATION_ENUMS.SLIDE:\r\n this.selectedNotifyInEffect = slideIn\r\n this.selectedNotifyOutEffect = slideOut\r\n break\r\n default:\r\n this.selectedNotifyInEffect = fadeIn\r\n this.selectedNotifyOutEffect = fadeOut\r\n }\r\n }\r\n}\r\n\r\n;(globalThis as any).Notify = Notify\r\n"]}