TP_JO2024/home/dist/component/tooltip/tooltip.module.min.js

4 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2024-03-27 17:19:37 +01:00
/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
const t="fr",s="dsfr",e=window[s],i={TOOLTIP:e.internals.ns.selector("tooltip"),SHOWN:e.internals.ns.selector("tooltip--shown"),BUTTON:e.internals.ns.selector("btn--tooltip")},o=1,n=2;class h extends e.core.PlacementReferent{constructor(){super(),this._state=0}static get instanceClassName(){return"TooltipReferent"}init(){if(super.init(),this.listen("focusin",this.focusIn.bind(this)),this.listen("focusout",this.focusOut.bind(this)),!this.matches(i.BUTTON)){const t=this.mouseover.bind(this);this.listen("mouseover",t),this.placement.listen("mouseover",t);const s=this.mouseout.bind(this);this.listen("mouseout",s),this.placement.listen("mouseout",s)}this.addEmission(e.core.RootEmission.KEYDOWN,this._keydown.bind(this)),this.listen("click",this._click.bind(this)),this.addEmission(e.core.RootEmission.CLICK,this._clickOut.bind(this))}_click(){this.focus()}_clickOut(t){this.node.contains(t)||this.blur()}_keydown(t){if(t===e.core.KeyCodes.ESCAPE)this.blur(),this.close()}close(){this.state=0}get state(){return this._state}set state(t){this._state!==t&&(this.isShown=t>0,this._state=t)}focusIn(){this.state|=o}focusOut(){this.state&=~o}mouseover(){this.state|=n}mouseout(){this.state&=~n}}const r=s=>`${t}-${s}`;r.selector=(t,s)=>(void 0===s&&(s="."),`${s}${r(t)}`),(r.attr=t=>`data-${r(t)}`).selector=(t,s)=>{let e=r.attr(t);return void 0!==s&&(e+=`="${s}"`),`[${e}]`},r.event=t=>`${s}.${t}`,r.emission=(t,s)=>`emission:${t}.${s}`;const c={SHOW:r.event("show"),HIDE:r.event("hide")},a="hidden",l="shown",d="hiding";class u extends e.core.Placement{constructor(){super(e.core.PlacementMode.AUTO,[e.core.PlacementPosition.TOP,e.core.PlacementPosition.BOTTOM],[e.core.PlacementAlign.CENTER,e.core.PlacementAlign.START,e.core.PlacementAlign.END]),this.modifier="",this._state=a}static get instanceClassName(){return"Tooltip"}init(){super.init(),this.register(`[aria-describedby="${this.id}"]`,h),this.listen("transitionend",this.transitionEnd.bind(this))}transitionEnd(){this._state===d&&(this._state=a,this.isShown=!1)}get isShown(){return super.isShown}set isShown(t){if(this.isEnabled)switch(!0){case t:this._state=l,this.addClass(i.SHOWN),this.dispatch(c.SHOW),super.isShown=!0;break;case this.isShown&&!t&&this._state===l:this._state=d,this.removeClass(i.SHOWN);break;case this.isShown&&!t&&this._state===a:this.dispatch(c.HIDE),super.isShown=!1}}render(){super.render();let t=this.referentRect.center-this.rect.center;const s=.5*this.rect.width-8;t<-s&&(t=-s),t>s&&(t=s),this.setProperty("--arrow-x",`${t.toFixed(2)}px`)}}e.tooltip={Tooltip:u,TooltipSelector:i,TooltipEvent:c},e.internals.register(e.tooltip.TooltipSelector.TOOLTIP,e.tooltip.Tooltip);
//# sourceMappingURL=tooltip.module.min.js.map