|
|
@@ -1,10 +1,12 @@ |
|
|
|
import { h, Component } from 'preact';
|
|
|
|
|
|
|
|
class WBNavbar extends Component {
|
|
|
|
render({ title, items, rhs, onItemClicked, onTitleClicked, activeItem }) {
|
|
|
|
render({ title, items, rhs, onItemClicked, onTitleClicked,
|
|
|
|
activeItem, titleUrl, getItemUrl }) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
|
|
<a class="navbar-brand" href="#" onclick={ e => { e.preventDefault(); onTitleClicked(); } }>{ title }</a>
|
|
|
|
<a class="navbar-brand" href={ titleUrl } onclick={ e => this.titleClicked(e) }>{ title }</a>
|
|
|
|
|
|
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
@@ -45,7 +47,8 @@ class WBNavbar extends Component { |
|
|
|
{ i['dropdown'].map(d => {
|
|
|
|
if (typeof(d) === 'string')
|
|
|
|
return (
|
|
|
|
<a class="dropdown-item" href="#" onclick={ e => { e.preventDefault(); onItemClicked(d); } }>{ d }</a>
|
|
|
|
<a class="dropdown-item" href={ getItemUrl(d) }
|
|
|
|
onclick={ e => this.itemClicked(e, d) }>{ d }</a>
|
|
|
|
);
|
|
|
|
|
|
|
|
else if (typeof(d) === 'object' && d['divider'])
|
|
|
@@ -55,7 +58,8 @@ class WBNavbar extends Component { |
|
|
|
|
|
|
|
else if (typeof(d) === 'object' && d['name'])
|
|
|
|
return (
|
|
|
|
<a class="dropdown-item" href="#" onclick={ e => { e.preventDefault(); onItemClicked(d); } }>{ d['name'] }</a>
|
|
|
|
<a class="dropdown-item" href={ getItemUrl(d) }
|
|
|
|
onclick={ e => this.itemClicked(e, d) }>{ d['name'] }</a>
|
|
|
|
);
|
|
|
|
}) }
|
|
|
|
</div>
|
|
|
@@ -67,7 +71,8 @@ class WBNavbar extends Component { |
|
|
|
|
|
|
|
return (
|
|
|
|
<li class={ li_cls }>
|
|
|
|
<a class={ a_cls } href="#" onclick={ e => { e.preventDefault(); onItemClicked(i); } }>{ i['name'] }</a>
|
|
|
|
<a class={ a_cls } href={ getItemUrl(i) }
|
|
|
|
onclick={ e => this.itemClicked(e, i) }>{ i['name'] }</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
@@ -80,15 +85,31 @@ class WBNavbar extends Component { |
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
titleClicked(e) {
|
|
|
|
let { onTitleClicked } = this.props;
|
|
|
|
if (!onTitleClicked)
|
|
|
|
return;
|
|
|
|
e.preventDefault();
|
|
|
|
onTitleClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
itemClicked(e, i) {
|
|
|
|
let { onItemClicked } = this.props;
|
|
|
|
if (!onItemClicked)
|
|
|
|
return;
|
|
|
|
e.preventDefault();
|
|
|
|
onItemClicked(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WBNavbar.defaultProps = {
|
|
|
|
'title': 'Workbench Advanced',
|
|
|
|
'items': [],
|
|
|
|
'form': null,
|
|
|
|
'onItemClicked': () => {},
|
|
|
|
'onTitleClicked': () => {},
|
|
|
|
'activeItem': null
|
|
|
|
'activeItem': null,
|
|
|
|
'titleUrl': '#',
|
|
|
|
'getItemUrl': () => ('#')
|
|
|
|
}
|
|
|
|
|
|
|
|
export default WBNavbar;
|