This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ud-pf-nav-layout.html
133 lines (113 loc) · 3.7 KB
/
ud-pf-nav-layout.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<dom-module id="ud-pf-nav-layout">
<template>
<style include="ud-pf-base-styles ud-pf-shared-styles ud-pf-layout-styles ud-pf-list-group-styles">
.layout-pf {
margin-top: 60px;
}
.hidden {
display: none !important;
}
</style>
<div class="layout-pf layout-pf-fixed">
<slot name="nav"></slot>
<div class$="[[_contentStyle]]">
<slot></slot>
</div>
</div>
</template>
<script>
/**
* `ud-pf-nav-layout`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class UdPfNavLayoutElement extends Polymer.Element {
static get is() { return 'ud-pf-nav-layout'; }
static get properties() {
return {
vertical: {
type: Boolean,
reflectToAttribute: true,
value: () => false,
observer: '_verticalChanged'
},
_navbar: Object,
_veerticalNav: Object,
_withBadges: Boolean,
_navCollapsed: Boolean,
_contentStyle: {
type: String,
computed: '_computeContentStyle(vertical, _navbar, _withBadges, _navCollapsed)'
}
};
}
constructor() {
super();
this._itemsObserver = new Polymer.FlattenedNodesObserver(this, info => {
if (info.addedNodes.filter(node => node.nodeType === Node.ELEMENT_NODE).length > 0 ||
info.removedNodes.filter(node => node.nodeType === Node.ELEMENT_NODE).length > 0) {
this._setupChildren();
}
});
}
ready() {
super.ready();
this.addEventListener('nav-toggle', this._handleToggle.bind(this));
}
_verticalChanged(vertical) {
if (this._navbar) {
this._navbar.vertical = vertical;
}
}
_handleToggle(e) {
if (this._verticalNav) {
this._verticalNav.collapsed = !this._verticalNav.collapsed;
}
}
_setupChildren() {
this._navbar = this.querySelector('ud-pf-navbar');
if (this._navbar) {
this._navbar._layout = this;
this._navbar.vertical = this.vertical;
this._navbar.setAttribute('slot', 'nav');
}
if (this._verticalNav) {
this._verticalNav.removeEventListener('with-badges-changed', this._withBadgesChanged.bind(this));
this._verticalNav.removeEventListener('collapsed-changed', this._navCollapsedChanged.bind(this));
}
this._verticalNav = this.querySelector('ud-pf-vertical-nav');
if (this._verticalNav) {
this._verticalNav._layout = this;
this._verticalNav.setAttribute('slot', 'nav');
this._verticalNav.addEventListener('with-badges-changed', this._withBadgesChanged.bind(this));
this._verticalNav.addEventListener('collapsed-changed', this._navCollapsedChanged.bind(this));
}
}
_computeContentStyle(vertical, navbar, withBadges, navCollapsed) {
let style = 'container-fluid';
if (vertical) {
style += ' container-pf-nav-pf-vertical';
}
if (this._verticalNav && this._verticalNav.withBadges) {
style += ' nav-pf-vertical-with-badges';
}
if (navCollapsed) {
style += ' collapsed-nav';
}
return style;
}
_withBadgesChanged(e) {
this._withBadges = e.detail.value;
}
_navCollapsedChanged(e) {
this._navCollapsed = e.detail.value;
}
}
window.customElements.define(UdPfNavLayoutElement.is, UdPfNavLayoutElement);
</script>
</dom-module>