- 1 :
import { BaseStorage } from '../../../../../mel_metapage/js/lib/classes/base_storage.js';
- 2 :
import {
- 3 :
EWebComponentMode,
- 4 :
HtmlCustomTag,
- 5 :
} from '../../../../../mel_metapage/js/lib/html/JsHtml/CustomAttributes/js_html_base_web_elements.js';
- 6 :
export { NavBarComponent };
- 7 :
- 8 :
/**
- 9 :
* @class
- 10 :
* @classdesc
- 11 :
* @extends HtmlCustomTag
- 12 :
* @abstract
- 13 :
*/
- 14 :
class NavBarComponent extends HtmlCustomTag {
- 15 :
/**
- 16 :
* Contient les données des data
- 17 :
* @private
- 18 :
* @type {BaseStorage<string>}
- 19 :
*/
- 20 :
#data = new BaseStorage();
- 21 :
/**
- 22 :
* NavBar parente. Si elle n'a pas été définie, renvoie `null`.<br/>
- 23 :
*
- 24 :
* Considérez qu'elle n'est jamais null.
- 25 :
* @type {?WspNavBar}
- 26 :
* @private
- 27 :
*/
- 28 :
#parent = null;
- 29 :
- 30 :
/**
- 31 :
* La classe contient des aides utiles pour les composants de la barre de navagation.
- 32 :
* @param {Object} [param0={}] Contient le mode ainsi que le parent.
- 33 :
* @param {EWebComponentMode} [param0.mode=EWebComponentMode.span] Mode du composant
- 34 :
* @param {?WspNavBar} [param0.parent=null] NavBar parente
- 35 :
*/
- 36 :
constructor({ mode = EWebComponentMode.span, parent = null } = {}) {
- 37 :
super({ mode });
- 38 :
- 39 :
this._p_save_into_data('mode', mode);
- 40 :
this.#parent = parent;
- 41 :
}
- 42 :
- 43 :
/**
- 44 :
* Récupère la navbar parente
- 45 :
* @returns {WspNavBar}
- 46 :
*/
- 47 :
get parent() {
- 48 :
return this.#parent;
- 49 :
}
- 50 :
- 51 :
_p_main() {
- 52 :
switch (this._p_get_data('mode')) {
- 53 :
case EWebComponentMode.div:
- 54 :
this.style.display = 'block';
- 55 :
break;
- 56 :
- 57 :
case EWebComponentMode.flex:
- 58 :
this.style.display = 'flex';
- 59 :
break;
- 60 :
- 61 :
case EWebComponentMode.inline_block:
- 62 :
this.style.display = 'inline-block';
- 63 :
break;
- 64 :
- 65 :
default:
- 66 :
break;
- 67 :
}
- 68 :
- 69 :
return super._p_main();
- 70 :
}
- 71 :
- 72 :
/**
- 73 :
* Récupère l'élément ou le shadowroot si le data-shadow est activé. <br/>
- 74 :
*
- 75 :
* Si le parent est défini, le shaodw dom sera toujours inactif.
- 76 :
* @protected
- 77 :
* @returns {this | ShadowRoot}
- 78 :
*/
- 79 :
_p_start_construct() {
- 80 :
return !!this.parent ? this : super._p_start_construct();
- 81 :
}
- 82 :
- 83 :
/**
- 84 :
* Récupère une data en mémoire et supprime l'attribut à la première récupération.
- 85 :
* @param {string} dataName data. Pas de tirets.
- 86 :
* @returns {string} Data en mémoire
- 87 :
* @protected
- 88 :
*/
- 89 :
_p_get_data(dataName) {
- 90 :
if (!this.#data.has(dataName)) {
- 91 :
this.#data.add(dataName, this.data(dataName));
- 92 :
this.removeAttribute(`data-${dataName}`);
- 93 :
}
- 94 :
- 95 :
return this.#data.get(dataName);
- 96 :
}
- 97 :
- 98 :
_p_save_into_data(dataName, value) {
- 99 :
this.#data.add(dataName, value);
- 100 :
- 101 :
return this;
- 102 :
}
- 103 :
- 104 :
destroy() {
- 105 :
super.destroy();
- 106 :
- 107 :
this.#data.clear();
- 108 :
this.#data = null;
- 109 :
this.#parent = null;
- 110 :
}
- 111 :
- 112 :
/**
- 113 :
* Set la navbar parent
- 114 :
* @param {WspNavBar} parent
- 115 :
*/
- 116 :
setNavBarParent(parent) {
- 117 :
this.#parent = parent;
- 118 :
return this;
- 119 :
}
- 120 :
}