IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123 lignes
4.1KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import { h, Component } from 'preact';
  8. class WBNavbar extends Component {
  9. render({ title, items, rhs, onItemClicked, onTitleClicked,
  10. activeItem, titleUrl, getItemUrl }) {
  11. return (
  12. <nav class="navbar navbar-expand-lg navbar-light bg-light">
  13. <a class="navbar-brand" href={ titleUrl } onclick={ e => this.titleClicked(e) }>{ title }</a>
  14. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  15. <span class="navbar-toggler-icon"></span>
  16. </button>
  17. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  18. <ul class="navbar-nav mr-auto">
  19. { items.map(i => {
  20. if (typeof(i) === 'string')
  21. return (
  22. <li class="nav-item">
  23. <a class="nav-link" href="#">{ i }</a>
  24. </li>
  25. );
  26. else if (typeof(i) === 'object')
  27. var li_cls = ['nav-item'];
  28. if (i['active'] || activeItem === i['id'])
  29. li_cls.push('active');
  30. var a_cls = ['nav-link'];
  31. if (i['disabled'])
  32. a_cls.push('disabled');
  33. if ('dropdown' in i) {
  34. li_cls.push('dropdown');
  35. a_cls.push('dropdown-toggle');
  36. li_cls = li_cls.join(' ');
  37. a_cls = a_cls.join(' ');
  38. return (
  39. <li class={ li_cls }>
  40. <a class={ a_cls } href="#" id={ i['name'].replace(' ', '-').toLowerCase() + '-dropdown' }
  41. role="button" data-toggle="dropdown" aria-haspopup="true"
  42. aria-expanded="false">{ i['name'] }</a>
  43. <div class="dropdown-menu" aria-labelledby={ i['name'].replace(' ', '-').toLowerCase() + '-dropdown' }>
  44. { i['dropdown'].map(d => {
  45. if (typeof(d) === 'string')
  46. return (
  47. <a class="dropdown-item" href={ getItemUrl(d) }
  48. onclick={ e => this.itemClicked(e, d) }>{ d }</a>
  49. );
  50. else if (typeof(d) === 'object' && d['divider'])
  51. return (
  52. <div class="dropdown-divider" />
  53. );
  54. else if (typeof(d) === 'object' && d['name'])
  55. return (
  56. <a class="dropdown-item" href={ getItemUrl(d) }
  57. onclick={ e => this.itemClicked(e, d) }>{ d['name'] }</a>
  58. );
  59. }) }
  60. </div>
  61. </li>
  62. );
  63. } else {
  64. li_cls = li_cls.join(' ');
  65. a_cls = a_cls.join(' ');
  66. return (
  67. <li class={ li_cls }>
  68. <a class={ a_cls } href={ getItemUrl(i) }
  69. onclick={ e => this.itemClicked(e, i) }>{ i['name'] }</a>
  70. </li>
  71. );
  72. }
  73. }) }
  74. </ul>
  75. { rhs }
  76. </div>
  77. </nav>
  78. );
  79. }
  80. titleClicked(e) {
  81. let { onTitleClicked } = this.props;
  82. if (!onTitleClicked)
  83. return;
  84. e.preventDefault();
  85. onTitleClicked();
  86. }
  87. itemClicked(e, i) {
  88. let { onItemClicked } = this.props;
  89. if (!onItemClicked)
  90. return;
  91. e.preventDefault();
  92. onItemClicked(i);
  93. }
  94. }
  95. WBNavbar.defaultProps = {
  96. 'title': 'Workbench Advanced',
  97. 'items': [],
  98. 'form': null,
  99. 'activeItem': null,
  100. 'titleUrl': '#',
  101. 'getItemUrl': () => ('#')
  102. }
  103. export default WBNavbar;