@codegouvfr/react-dsfr
Version:
French State Design System React integration library
4 lines (3 loc) • 7.07 kB
JavaScript
/*! DSFR v1.8.5 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
!function(){"use strict";var t=window.dsfr,e=function(e){function i(){e.call(this,t.core.DisclosureType.SELECT)}e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i;var s={list:{configurable:!0}},n={instanceClassName:{configurable:!0}};return n.instanceClassName.get=function(){return"TabButton"},i.prototype.apply=function(t){e.prototype.apply.call(this,t),this.isPrimary&&(this.setAttribute("tabindex",t?"0":"-1"),t&&this.list&&this.list.focalize(this))},s.list.get=function(){return this.element.getAscendantInstance("TabsList","TabsGroup")},Object.defineProperties(i.prototype,s),Object.defineProperties(i,n),i}(t.core.DisclosureButton),i={TAB:t.internals.ns.selector("tabs__tab"),GROUP:t.internals.ns.selector("tabs"),PANEL:t.internals.ns.selector("tabs__panel"),LIST:t.internals.ns.selector("tabs__list"),SHADOW:t.internals.ns.selector("tabs__shadow"),SHADOW_LEFT:t.internals.ns.selector("tabs__shadow--left"),SHADOW_RIGHT:t.internals.ns.selector("tabs__shadow--right"),PANEL_START:t.internals.ns.selector("tabs__panel--direction-start"),PANEL_END:t.internals.ns.selector("tabs__panel--direction-end")},s="direction-start",n="direction-end",r="none",o=function(o){function a(){o.call(this,t.core.DisclosureType.SELECT,i.PANEL,e,"TabsGroup"),this._direction=r,this._isPreventingTransition=!1}o&&(a.__proto__=o),a.prototype=Object.create(o&&o.prototype),a.prototype.constructor=a;var c={direction:{configurable:!0},isPreventingTransition:{configurable:!0}},l={instanceClassName:{configurable:!0}};return l.instanceClassName.get=function(){return"TabPanel"},c.direction.get=function(){return this._direction},c.direction.set=function(t){if(t!==this._direction){switch(this._direction){case s:this.removeClass(i.PANEL_START);break;case n:this.removeClass(i.PANEL_END);break;case r:break;default:return}switch(this._direction=t,this._direction){case s:this.addClass(i.PANEL_START);break;case n:this.addClass(i.PANEL_END)}}},c.isPreventingTransition.get=function(){return this._isPreventingTransition},c.isPreventingTransition.set=function(e){this._isPreventingTransition!==e&&(e?this.addClass(t.internals.motion.TransitionSelector.NONE):this.removeClass(t.internals.motion.TransitionSelector.NONE),this._isPreventingTransition=!0===e)},a.prototype.translate=function(t,e){this.isPreventingTransition=e,this.direction=t},a.prototype.reset=function(){this.group.index=0},Object.defineProperties(a.prototype,c),Object.defineProperties(a,l),a}(t.core.Disclosure),a=function(e){function i(){e.call(this,"TabPanel")}e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i;var o={list:{configurable:!0},buttonHasFocus:{configurable:!0},isPreventingTransition:{configurable:!0}},a={instanceClassName:{configurable:!0}};return a.instanceClassName.get=function(){return"TabsGroup"},i.prototype.init=function(){e.prototype.init.call(this),this.listen("transitionend",this.transitionend.bind(this)),this.listenKey(t.core.KeyCodes.RIGHT,this.pressRight.bind(this),!0,!0),this.listenKey(t.core.KeyCodes.LEFT,this.pressLeft.bind(this),!0,!0),this.listenKey(t.core.KeyCodes.HOME,this.pressHome.bind(this),!0,!0),this.listenKey(t.core.KeyCodes.END,this.pressEnd.bind(this),!0,!0),this.isRendering=!0,this.list&&this.list.apply()},o.list.get=function(){return this.element.getDescendantInstances("TabsList","TabsGroup",!0)[0]},i.prototype.transitionend=function(t){this.isPreventingTransition=!0},o.buttonHasFocus.get=function(){return this.members.some((function(t){return t.buttonHasFocus}))},i.prototype.pressRight=function(){this.buttonHasFocus&&(this.index<this.length-1?this.index++:this.index=0,this.focus())},i.prototype.pressLeft=function(){this.buttonHasFocus&&(this.index>0?this.index--:this.index=this.length-1,this.focus())},i.prototype.pressHome=function(){this.buttonHasFocus&&(this.index=0,this.focus())},i.prototype.pressEnd=function(){this.buttonHasFocus&&(this.index=this.length-1,this.focus())},i.prototype.focus=function(){this.current&&this.current.focus()},i.prototype.apply=function(){for(var t=0;t<this._index;t++)this.members[t].translate(s);this.current.translate(r);for(var e=this._index+1;e<this.length;e++)this.members[e].translate(n);this.isPreventingTransition=!1},o.isPreventingTransition.get=function(){return this._isPreventingTransition},o.isPreventingTransition.set=function(e){this._isPreventingTransition!==e&&(e?this.addClass(t.internals.motion.TransitionSelector.NONE):this.removeClass(t.internals.motion.TransitionSelector.NONE),this._isPreventingTransition=!0===e)},i.prototype.render=function(){if(null!==this.current){var t=Math.round(this.current.node.offsetHeight);if(this.panelHeight!==t){this.panelHeight=t;var e=0;this.list&&(e=this.list.node.offsetHeight),this.style.setProperty("--tabs-height",this.panelHeight+e+"px")}}},Object.defineProperties(i.prototype,o),Object.defineProperties(i,a),i}(t.core.DisclosuresGroup),c=function(t){function e(){t.apply(this,arguments)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var s={group:{configurable:!0},isScrolling:{configurable:!0}},n={instanceClassName:{configurable:!0}};return n.instanceClassName.get=function(){return"TabsList"},e.prototype.init=function(){this.listen("scroll",this.scroll.bind(this)),this.isResizing=!0},s.group.get=function(){return this.element.getAscendantInstance("TabsGroup","TabsList")},e.prototype.focalize=function(t){var e=t.getRect(),i=this.getRect(),s=this.node.scrollLeft;e.left<i.left?this.node.scrollTo(s-i.left+e.left-16,0):e.right>i.right&&this.node.scrollTo(s-i.right+e.right+16,0)},s.isScrolling.get=function(){return this._isScrolling},s.isScrolling.set=function(t){this._isScrolling!==t&&(this._isScrolling=t,this.apply())},e.prototype.apply=function(){this.group&&(this._isScrolling?(this.group.addClass(i.SHADOW),this.scroll()):(this.group.removeClass(i.SHADOW_RIGHT),this.group.removeClass(i.SHADOW_LEFT),this.group.removeClass(i.SHADOW)))},e.prototype.scroll=function(){if(this.group){var t=this.node.scrollLeft,e=t<=16,s=this.node.scrollWidth-this.node.clientWidth-16,n=Math.abs(t)>=s,r="rtl"===document.documentElement.getAttribute("dir"),o=r?i.SHADOW_RIGHT:i.SHADOW_LEFT,a=r?i.SHADOW_LEFT:i.SHADOW_RIGHT;e?this.group.removeClass(o):this.group.addClass(o),n?this.group.removeClass(a):this.group.addClass(a)}},e.prototype.resize=function(){this.isScrolling=this.node.scrollWidth>this.node.clientWidth+16,this.setProperty("--tab-list-height",this.getRect().height+"px")},e.prototype.dispose=function(){this.isScrolling=!1},Object.defineProperties(e.prototype,s),Object.defineProperties(e,n),e}(t.core.Instance);t.tab={TabPanel:o,TabButton:e,TabsGroup:a,TabsList:c,TabSelector:i},t.internals.register(t.tab.TabSelector.PANEL,t.tab.TabPanel),t.internals.register(t.tab.TabSelector.GROUP,t.tab.TabsGroup),t.internals.register(t.tab.TabSelector.LIST,t.tab.TabsList)}();
//# sourceMappingURL=tab.nomodule.min.js.map