@stimulus-components/notification
Version:
A Stimulus controller for showing notifications.
2 lines (1 loc) • 919 B
JavaScript
(function(global,factory){typeof exports=="object"&&typeof module<"u"?module.exports=factory(require("@hotwired/stimulus"),require("stimulus-use")):typeof define=="function"&&define.amd?define(["@hotwired/stimulus","stimulus-use"],factory):(global=typeof globalThis<"u"?globalThis:global||self,global.StimulusNotification=factory(global.Stimulus,global.useTransition))})(this,function(stimulus,stimulusUse){"use strict";const _Notification=class _Notification extends stimulus.Controller{initialize(){this.hide=this.hide.bind(this)}connect(){stimulusUse.useTransition(this),this.hiddenValue===!1&&this.show()}show(){this.enter(),this.timeout=setTimeout(this.hide,this.delayValue)}async hide(){this.timeout&&clearTimeout(this.timeout),await this.leave(),this.element.remove()}};_Notification.values={delay:{type:Number,default:3e3},hidden:{type:Boolean,default:!1}};let Notification=_Notification;return Notification});