|
@@ -1,10 +1,12 @@ |
|
|
import { h, Component } from 'preact';
|
|
|
import { h, Component } from 'preact';
|
|
|
|
|
|
|
|
|
class WBNavbar extends Component {
|
|
|
class WBNavbar extends Component {
|
|
|
render({ title, items, rhs, onItemClicked, onTitleClicked, activeItem }) {
|
|
|
|
|
|
|
|
|
render({ title, items, rhs, onItemClicked, onTitleClicked,
|
|
|
|
|
|
activeItem, titleUrl, getItemUrl }) {
|
|
|
|
|
|
|
|
|
return (
|
|
|
return (
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
|
<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">
|
|
|
<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>
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
@@ -45,7 +47,8 @@ class WBNavbar extends Component { |
|
|
{ i['dropdown'].map(d => {
|
|
|
{ i['dropdown'].map(d => {
|
|
|
if (typeof(d) === 'string')
|
|
|
if (typeof(d) === 'string')
|
|
|
return (
|
|
|
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'])
|
|
|
else if (typeof(d) === 'object' && d['divider'])
|
|
@@ -55,7 +58,8 @@ class WBNavbar extends Component { |
|
|
|
|
|
|
|
|
else if (typeof(d) === 'object' && d['name'])
|
|
|
else if (typeof(d) === 'object' && d['name'])
|
|
|
return (
|
|
|
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>
|
|
|
</div>
|
|
@@ -67,7 +71,8 @@ class WBNavbar extends Component { |
|
|
|
|
|
|
|
|
return (
|
|
|
return (
|
|
|
<li class={ li_cls }>
|
|
|
<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>
|
|
|
</li>
|
|
|
);
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -80,15 +85,31 @@ class WBNavbar extends Component { |
|
|
</nav>
|
|
|
</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 = {
|
|
|
WBNavbar.defaultProps = {
|
|
|
'title': 'Workbench Advanced',
|
|
|
'title': 'Workbench Advanced',
|
|
|
'items': [],
|
|
|
'items': [],
|
|
|
'form': null,
|
|
|
'form': null,
|
|
|
'onItemClicked': () => {},
|
|
|
|
|
|
'onTitleClicked': () => {},
|
|
|
|
|
|
'activeItem': null
|
|
|
|
|
|
|
|
|
'activeItem': null,
|
|
|
|
|
|
'titleUrl': '#',
|
|
|
|
|
|
'getItemUrl': () => ('#')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
export default WBNavbar;
|
|
|
export default WBNavbar;
|