UNPKG

@codegouvfr/react-dsfr

Version:

French State Design System React integration library

4 lines (3 loc) 3.98 kB
/*! DSFR v1.13.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */ !function(){"use strict";var e=window.dsfr,t={HEADER:e.internals.ns.selector("header"),BRAND_LINK:e.internals.ns.selector("header__brand a"),TOOLS_LINKS:e.internals.ns.selector("header__tools-links"),MENU_LINKS:e.internals.ns.selector("header__menu-links"),BUTTONS:e.internals.ns.selector("header__tools-links")+" "+e.internals.ns.selector("btns-group")+", "+e.internals.ns.selector("header__tools-links")+" "+e.internals.ns.selector("links-group"),MODALS:""+e.internals.ns.selector("header__search")+e.internals.ns.selector("modal")+", "+e.internals.ns.selector("header__menu")+e.internals.ns.selector("modal")},r=function(r){function a(){r.apply(this,arguments)}r&&(a.__proto__=r),a.prototype=Object.create(r&&r.prototype),a.prototype.constructor=a;var i={instanceClassName:{configurable:!0}};return i.instanceClassName.get=function(){return"HeaderLinks"},a.prototype.init=function(){var r=this.queryParentSelector(t.HEADER);this.toolsLinks=r.querySelector(t.TOOLS_LINKS),this.menuLinks=r.querySelector(t.MENU_LINKS);var a="-mobile",i=this.toolsLinks.innerHTML.replace(/ +/g," "),s=this.menuLinks.innerHTML.replace(/ +/g," "),n=i.match(/id="(.*?)"/gm)||[];n=n.map((function(e){return e.replace('id="',"").replace('"',"")}));for(var o=i.replace(/id="(.*?)"/gm,'id="$1'+a+'"'),l=0,c=["aria-controls","aria-describedby","aria-labelledby"];l<c.length;l+=1){var d=c[l],h=i.match(new RegExp(d+'="(.*?)"',"gm"));if(h)for(var u=0,p=h;u<p.length;u+=1){var b=p[u].replace(d+'="',"").replace('"',"");n.includes(b)&&(o=o.replace(d+'="'+b+'"',d+'="'+(b+a)+'"'))}}if(o!==s)switch(e.mode){case e.Modes.ANGULAR:case e.Modes.REACT:case e.Modes.VUE:this.warn("header__tools-links content is different from header__menu-links content.\nAs you're using a dynamic framework, you should handle duplication of this content yourself, please refer to documentation:\n"+e.header.doc);break;default:this.menuLinks.innerHTML=o}},Object.defineProperties(a,i),a}(e.core.Instance),a=function(t){function r(){t.apply(this,arguments)}t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r;var a={instanceClassName:{configurable:!0}};return a.instanceClassName.get=function(){return"HeaderModal"},r.prototype.init=function(){this.storeAria(),this.isResizing=!0},r.prototype.resize=function(){this.isBreakpoint(e.core.Breakpoints.LG)?this.deactivateModal():this.activateModal()},r.prototype.activateModal=function(){var e=this.element.getInstance("Modal");e?(this.restoreAria(),e.isActive=!0,this.listenClick({capture:!0})):this.request(this.activateModal.bind(this))},r.prototype.deactivateModal=function(){var e=this.element.getInstance("Modal");e?(e.conceal(),e.isActive=!1,this.storeAria(),this.unlistenClick({capture:!0})):this.request(this.deactivateModal.bind(this))},r.prototype.storeAria=function(){this.hasAttribute("aria-labelledby")&&(this._ariaLabelledby=this.getAttribute("aria-labelledby")),this.hasAttribute("aria-label")&&(this._ariaLabel=this.getAttribute("aria-label")),this.removeAttribute("aria-labelledby"),this.removeAttribute("aria-label")},r.prototype.restoreAria=function(){this._ariaLabelledby&&this.setAttribute("aria-labelledby",this._ariaLabelledby),this._ariaLabel&&this.setAttribute("aria-label",this._ariaLabel)},r.prototype.handleClick=function(t){!t.target.matches("a, button")||t.target.matches("[aria-controls]")||t.target.matches(e.core.DisclosureSelector.PREVENT_CONCEAL)||this.element.getInstance("Modal").conceal()},Object.defineProperties(r,a),r}(e.core.Instance);e.header={HeaderLinks:r,HeaderModal:a,HeaderSelector:t,doc:"https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/en-tete"},e.internals.register(e.header.HeaderSelector.TOOLS_LINKS,e.header.HeaderLinks),e.internals.register(e.header.HeaderSelector.MODALS,e.header.HeaderModal)}(); //# sourceMappingURL=header.nomodule.min.js.map