@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 2.94 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
;var tslib_es6=require("./tslib.es6-7DbU_BSw.js"),index=require("./index-BH-BeuHg.js"),clsx=require("./clsx-CkZlkaek.js"),componentNames=require("./component-names-Bu9hV7OT.js"),i18n=require("./i18n-D4Klw_bZ.js"),bem=require("./bem-DQRepkGo.js"),Heading=require("./Heading-CTBJ4kM-.js");const translateError=i18n.translate("kol-error"),translateInfo=i18n.translate("kol-info"),translateWarning=i18n.translate("kol-warning"),translateSuccess=i18n.translate("kol-success"),translateMessage=i18n.translate("kol-message"),Icon=({ariaLabel:e,icon:a})=>index.h(index.Fragment,null,index.h("span",{class:"visually-hidden"},e),index.h(componentNames.KolIconTag,{class:bem.BEM_CLASS_ALERT__ICON,_label:"",_icons:a})),AlertIcon=({type:e,label:a})=>{switch(e){case"error":return index.h(Icon,{ariaLabel:translateError,icon:"kolicon-alert-error",label:a});case"info":return index.h(Icon,{ariaLabel:translateInfo,icon:"kolicon-alert-info",label:a});case"warning":return index.h(Icon,{ariaLabel:translateWarning,icon:"kolicon-alert-warning",label:a});case"success":return index.h(Icon,{ariaLabel:translateSuccess,icon:"kolicon-alert-success",label:a});default:return index.h(Icon,{ariaLabel:translateMessage,icon:"kolicon-alert-info",label:a})}},translateCloseAlert=i18n.translate("kol-close-alert"),vibrateOnError=()=>{if("undefined"==typeof navigator||"function"!=typeof navigator.vibrate)return;const e=navigator.userActivation;if(((null==e?void 0:e.isActive)||(null==e?void 0:e.hasBeenActive))&&matchMedia("(any-pointer: coarse)").matches)try{navigator.vibrate([100,75,100,75,100])}catch(e){}},KolAlertFc=(e,a)=>{const{class:n={},alert:l=!1,hasCloser:t=!1,label:r,level:i=0,type:s="default",variant:o="msg",onAlertTimeout:c,onCloserClick:d}=e,b=tslib_es6.__rest(e,["class","alert","hasCloser","label","level","type","variant","onAlertTimeout","onCloserClick"]);l&&(vibrateOnError(),setTimeout(()=>{null==c||c()},1e4));const u=bem.bem("kol-alert",{hasCloser:!!t,[`type-${s}`]:!0,[`variant-${o}`]:!0}),_=bem.bem("kol-alert","heading",{[`h${i}`]:!0}),h=Object.assign({class:clsx.clsx(n,u)},b);return index.h("div",Object.assign({role:l?"alert":void 0},h,{"data-testid":"alert"}),index.h("div",{class:"kol-alert__container"},index.h(AlertIcon,{label:r,type:s}),index.h("div",{class:"kol-alert__container-content"},r&&index.h(Heading.KolHeadingFc,{class:_,level:i,id:"heading"},r),"msg"===o&&index.h("span",{class:bem.BEM_CLASS_ALERT__CONTENT,"aria-describedby":r?"heading":void 0},a)),t&&index.h(componentNames.KolButtonWcTag,{class:bem.BEM_CLASS_ALERT__CLOSER,"data-testid":"alert-close-button",_ariaDescription:(null==r?void 0:r.trim())||"",_hideLabel:!0,_icons:{left:{icon:"kolicon-cross"}},_label:translateCloseAlert,_on:{onClick:d},_tooltipAlign:"left"})),"card"===o&&index.h("div",{class:bem.BEM_CLASS_ALERT__CONTENT,"aria-describedby":r?"heading":void 0},a))};exports.KolAlertFc=KolAlertFc;