@freshworks/crayons
Version:
Crayons Web Components library
1 lines • 5.53 kB
JavaScript
var __awaiter=this&&this.__awaiter||function(e,t,n,i){function o(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,r){function a(e){try{l(i.next(e))}catch(t){r(t)}}function s(e){try{l(i["throw"](e))}catch(t){r(t)}}function l(e){e.done?n(e.value):o(e.value).then(a,s)}l((i=i.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,o,r,a;return a={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(e){return function(t){return l([e,t])}}function l(a){if(i)throw new TypeError("Generator is already executing.");while(n)try{if(i=1,o&&(r=a[0]&2?o["return"]:a[0]?o["throw"]||((r=o["return"])&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;if(o=0,r)a=[a[0]&2,r.value];switch(a[0]){case 0:case 1:r=a;break;case 4:n.label++;return{value:a[1],done:false};case 5:n.label++;o=a[1];a=[0];continue;case 7:a=n.ops.pop();n.trys.pop();continue;default:if(!(r=n.trys,r=r.length>0&&r[r.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]<r[3])){n.label=a[1];break}if(a[0]===6&&n.label<r[1]){n.label=r[1];r=a;break}if(r&&n.label<r[2]){n.label=r[2];n.ops.push(a);break}if(r[2])n.ops.pop();n.trys.pop();continue}a=t.call(e,n)}catch(s){a=[6,s];o=0}finally{i=r=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{r as registerInstance,c as createEvent,h,e as Host,i as getElement}from"./index-25bc21e4.js";var inlineMessageCss=':host{font-family:var(--fw-font-family, -apple-system, blinkmacsystemfont, "Segoe UI", roboto, oxygen, ubuntu, cantarell, "Open Sans", "Helvetica Neue", sans-serif);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-box-sizing:border-box;box-sizing:border-box}:host{margin:0}.alert{position:relative;display:-ms-flexbox;display:flex;width:100%;border-radius:4px;-webkit-box-sizing:border-box;box-sizing:border-box;margin:inherit;padding:8px 6px;background-color:transparent}.alert--success{background:#e0f5f1;border:1px solid #b4e5da}.alert--success .alert__message{border-left:1px solid #b4e5da}.alert--warning{background:#fef1e1;border:1px solid #fedcb3}.alert--warning .alert__message{border-left:1px solid #fedcb3}.alert--info{background:#e5f2fd;border:1px solid #bbdcfe}.alert--info .alert__message{border-left:1px solid #bbdcfe}.alert--error{border:1px solid #ffd0d6;background:#ffecf0}.alert--error .alert__message{border-left:1px solid #ffd0d6}.alert__icon{-ms-flex:0 0 auto;flex:0 0 auto;display:-ms-flexbox;display:flex;-ms-flex-item-align:start;align-self:flex-start;margin-right:8px}.alert__message{padding-left:12px;-ms-flex:1 1 auto;flex:1 1 auto;color:#12344d;font-size:14px;font-weight:400;line-height:20px}.alert__message ::slotted(a){font-weight:500;color:#365dbe;text-decoration:none}.alert__close{-ms-flex:0 0 auto;flex:0 0 auto;display:-ms-flexbox;display:flex;-ms-flex-item-align:start;align-self:flex-start;padding-right:6px;padding-left:12px;cursor:pointer}';var iconMap={error:"alert",warning:"info",info:"info",success:"success"};var iconColorMap={error:"#e43538",warning:"#c7502f",info:"#264966",success:"#00795b"};var InlineMessage=function(){function e(e){registerInstance(this,e);this.fwShow=createEvent(this,"fwShow",7);this.fwHide=createEvent(this,"fwHide",7);this.closable=true;this.type="info";this.duration=Infinity;this.open=true}e.prototype.startAutoHide=function(){var e=this;clearTimeout(this.autoHideTimeout);if(this.open&&this.duration<Infinity){this.autoHideTimeout=setTimeout((function(){return e.hide()}),this.duration)}};e.prototype.handleOpen=function(){if(this.open){this.host.style.display="flex";this.fwShow.emit();if(this.duration<Infinity){this.startAutoHide()}}else{clearTimeout(this.autoHideTimeout);this.host.style.display="none";this.fwHide.emit()}};e.prototype.handleDurationChange=function(){this.startAutoHide()};e.prototype.show=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){if(this.open){return[2]}this.open=true;return[2]}))}))};e.prototype.hide=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){if(!this.open){return[2]}this.open=false;return[2]}))}))};e.prototype.connectedCallback=function(){this.host.style.display=this.open?"flex":"none"};e.prototype.disconnectedCallback=function(){clearTimeout(this.autoHideTimeout)};e.prototype.handleKeyUp=function(e){if(e.code==="Enter"){e.preventDefault();this.hide()}};e.prototype.handleClose=function(){this.hide()};e.prototype.render=function(){var e=this;return h(Host,{role:"alert","aria-hidden":this.open?"false":"true"},h("div",{class:"alert "+"alert--"+this.type},h("span",{class:"alert__icon"},h("fw-icon",{name:iconMap[this.type],color:iconColorMap[this.type]})),h("span",{class:"alert__message"},h("slot",null)),this.closable&&h("span",{class:"alert__close",role:"button",tabindex:"0",onKeyUp:function(t){return e.handleKeyUp(t)},onClick:function(){return e.handleClose()}},h("fw-icon",{name:"cross",color:"#12344d",size:8,library:"system"}))))};Object.defineProperty(e.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{open:["handleOpen"],duration:["handleDurationChange"]}},enumerable:false,configurable:true});return e}();InlineMessage.style=inlineMessageCss;export{InlineMessage as fw_inline_message};