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