@ucd-lib/theme-elements 0.0.2 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/brand/ucd-theme-header/ucd-theme-header.js +67 -31
  2. package/brand/ucd-theme-header/ucd-theme-header.tpl.js +58 -23
  3. package/brand/ucd-theme-pagination/ucd-theme-pagination.js +12 -6
  4. package/brand/ucd-theme-primary-nav/ucd-theme-primary-nav.js +32 -104
  5. package/brand/ucd-theme-quick-links/ucd-theme-quick-links.js +9 -34
  6. package/brand/ucd-theme-quick-links/ucd-theme-quick-links.tpl.js +1 -1
  7. package/brand/ucd-theme-search-form/ucd-theme-search-form.js +7 -1
  8. package/brand/ucd-theme-search-form/ucd-theme-search-form.tpl.js +8 -3
  9. package/brand/ucd-theme-search-popup/ucd-theme-search-popup.js +3 -3
  10. package/brand/ucd-theme-slim-select/ucd-theme-slim-select.js +62 -0
  11. package/brand/ucd-theme-slim-select/ucd-theme-slim-select.tpl.js +26 -0
  12. package/brand/ucd-theme-subnav/ucd-theme-subnav.js +196 -0
  13. package/brand/ucd-theme-subnav/ucd-theme-subnav.tpl.js +60 -0
  14. package/package.json +5 -4
  15. package/ucdlib/ucdlib-branding-bar/book.js +4 -0
  16. package/ucdlib/ucdlib-branding-bar/logo.js +67 -0
  17. package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.js +101 -0
  18. package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.tpl.js +102 -0
  19. package/ucdlib/ucdlib-icon/ucdlib-icon.tpl.js +2 -0
  20. package/ucdlib/ucdlib-icons/sitefarm.js +107 -0
  21. package/ucdlib/ucdlib-icons/ucdlib-icons.js +7 -1
  22. package/ucdlib/ucdlib-icons/utils.js +3 -3
  23. package/ucdlib/ucdlib-iconset/ucdlib-iconset.js +5 -2
  24. package/ucdlib/ucdlib-pages/ucdlib-pages.js +4 -4
  25. package/utils/{break-points.js → controllers/break-points.js} +8 -9
  26. package/utils/controllers/index.js +11 -0
  27. package/utils/controllers/intersection-observer.js +58 -0
  28. package/utils/controllers/mutation-observer.js +52 -0
  29. package/utils/controllers/wait.js +43 -0
  30. package/utils/mixins/index.js +8 -0
  31. package/utils/{main-dom-element.js → mixins/main-dom-element.js} +0 -0
  32. package/utils/{mixin.js → mixins/mixin.js} +0 -0
  33. package/utils/mixins/nav-element.js +103 -0
  34. package/utils/index.js +0 -6
  35. package/utils/mutation-observer.js +0 -47
@@ -1,7 +1,10 @@
1
1
  import { LitElement } from 'lit';
2
2
  import {render, styles} from "./ucd-theme-header.tpl.js";
3
3
 
4
- import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.js";
4
+ import {
5
+ IntersectionObserverController,
6
+ MutationObserverController,
7
+ WaitController } from '../../utils/controllers';
5
8
 
6
9
  /**
7
10
  * @class UcdThemeHeader
@@ -15,6 +18,7 @@ import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.j
15
18
  * @property {String} figureSrc - Site logo/icon to display next to site name
16
19
  * @property {String} siteUrl - Url to use for links around site name and figure
17
20
  * @property {Boolean} opened - Whether header is open in the mobile view
21
+ * @property {Boolean} preventFixed - Navbar will not be fixed to top of screen in desktop view
18
22
  *
19
23
  * @example
20
24
  * <ucd-theme-header site-name="A UC Davis Website">
@@ -35,8 +39,10 @@ import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.j
35
39
  * </ucd-theme-header>
36
40
  *
37
41
  */
38
- export default class UcdThemeHeader extends Mixin(LitElement)
39
- .with(MutationObserverElement, BreakPoints) {
42
+ export default class UcdThemeHeader extends LitElement {
43
+
44
+ mutationObserver = new MutationObserverController(this);
45
+ wait = new WaitController(this);
40
46
 
41
47
  static get properties() {
42
48
  return {
@@ -45,11 +51,13 @@ export default class UcdThemeHeader extends Mixin(LitElement)
45
51
  figureSrc: {type: String, attribute: "figure-src"},
46
52
  siteUrl: {type: String, attribute: "site-url"},
47
53
  opened: {type: Boolean},
54
+ preventFixed: {type: Boolean, attribute: "prevent-fixed"},
48
55
  isDemo: {type: Boolean, attribute: "is-demo"},
49
56
  _transitioning: {type: Boolean, state: true},
50
57
  _hasSlottedBranding: {type: Boolean, state: true},
51
58
  _hasQuickLinks: {type: Boolean, state: true},
52
- _hasSearch: {type: Boolean, state: true}
59
+ _hasSearch: {type: Boolean, state: true},
60
+ _brandingBarInView: {type: Boolean, state: true}
53
61
  };
54
62
  }
55
63
 
@@ -73,26 +81,38 @@ export default class UcdThemeHeader extends Mixin(LitElement)
73
81
  this._hasQuickLinks = false;
74
82
  this._hasSearch = false;
75
83
  this._animationDuration = 500;
84
+ this._brandingBarInView = false;
76
85
 
77
86
  }
78
87
 
79
- /**
80
- * @method updated
81
- * @description Lit lifecycle method called after element has updated.
82
- * @param {Map} props - Properties updated in cycle
83
- * @private
84
- */
85
- updated( props ){
88
+ connectedCallback(){
89
+ super.connectedCallback();
90
+ if ( !this.preventFixed ) {
91
+ this.intersectionObserver = new IntersectionObserverController(this, {}, "_onBrandingBarIntersection", false);
92
+ }
93
+ }
86
94
 
87
- // Check if we're using the default branding div
88
- const brandProps = ['siteName', 'slogan', 'figureSrc'];
89
- if ( brandProps.map(p => props.has(p)).filter(Boolean).length ) {
90
- if ( brandProps.map(p => this[p]).filter(Boolean).length ) {
91
- this._hasSlottedBranding = false;
95
+ firstUpdated(){
96
+ if ( !this.preventFixed ) {
97
+ let aboveNav = this.renderRoot.getElementById('branding-bar-container');
98
+ this.intersectionObserver.observer.observe(aboveNav);
99
+ }
100
+ }
101
+
102
+ _onBrandingBarIntersection(entries){
103
+ let offSetValue = 0;
104
+ try {
105
+ offSetValue = this.renderRoot.getElementById('nav-bar').getBoundingClientRect().height;
106
+ } catch (error) {}
107
+ if ( offSetValue > 150 ) offSetValue = 0;
108
+ entries.forEach(entry => {
109
+ this._brandingBarInView = entry.isIntersecting;
110
+ if (this._brandingBarInView) {
111
+ this.style.marginBottom = '0px';
92
112
  } else {
93
- this._hasSlottedBranding = true;
113
+ this.style.marginBottom = offSetValue + "px";
94
114
  }
95
- }
115
+ })
96
116
  }
97
117
 
98
118
  /**
@@ -105,7 +125,7 @@ export default class UcdThemeHeader extends Mixin(LitElement)
105
125
 
106
126
  this.opened = true;
107
127
  this._transitioning = true;
108
- await this._waitForAnimation();
128
+ await this.wait.wait(this._animationDuration);
109
129
  this._transitioning = false;
110
130
  return true;
111
131
 
@@ -121,7 +141,7 @@ export default class UcdThemeHeader extends Mixin(LitElement)
121
141
 
122
142
  this.opened = false;
123
143
  this._transitioning = true;
124
- await this._waitForAnimation();
144
+ await this.wait.wait(this._animationDuration);
125
145
  this._transitioning = false;
126
146
  return true;
127
147
 
@@ -168,6 +188,24 @@ export default class UcdThemeHeader extends Mixin(LitElement)
168
188
  return classes;
169
189
  }
170
190
 
191
+ /**
192
+ * @method _getHeaderClasses
193
+ * @description Get classes to be assigned to the header element
194
+ * @private
195
+ * @returns {Object}
196
+ */
197
+ _getHeaderClasses(){
198
+ let classes = {
199
+ "l-header": true,
200
+ "header": true
201
+ };
202
+
203
+ classes['fixed-mobile'] = !this.preventFixed;
204
+ classes['fixed-desktop'] = !this.preventFixed && !this._brandingBarInView;
205
+
206
+ return classes;
207
+ }
208
+
171
209
  /**
172
210
  * @method _ucdLogo
173
211
  * @description Returns URI-encoded svg string of UC Davis logo
@@ -213,18 +251,16 @@ export default class UcdThemeHeader extends Mixin(LitElement)
213
251
  } else {
214
252
  this._hasSearch = false;
215
253
  }
216
- }
217
254
 
218
- /**
219
- * @method _waitForAnimation
220
- * @private
221
- * @description Wait for time designated for open/close animation
222
- * @returns {Promise}
223
- */
224
- async _waitForAnimation() {
225
- return new Promise(resolve => {
226
- setTimeout(resolve, this._animationDuration);
227
- });
255
+ let UcdlibBrandingBar = this.querySelector('ucdlib-branding-bar');
256
+ if ( UcdlibBrandingBar ) {
257
+ UcdlibBrandingBar.setAttribute('slot', 'branding-bar');
258
+ this._hasSlottedBranding = true;
259
+ } else if ( this.querySelector("*[slot='branding-bar']") ){
260
+ this._hasSlottedBranding = true;
261
+ } else {
262
+ this._hasSlottedBranding = false;
263
+ }
228
264
  }
229
265
 
230
266
  }
@@ -20,6 +20,39 @@ export function styles() {
20
20
  button {
21
21
  cursor: pointer;
22
22
  }
23
+ ::slotted(ucdlib-branding-bar){
24
+ width: 100%;
25
+ }
26
+
27
+ @media (max-width: 991px) {
28
+ .fixed-mobile .mobile-bar {
29
+ position: fixed;
30
+ width: 100%;
31
+ z-index: 1000;
32
+ top: 0;
33
+ }
34
+ .fixed-mobile .off-canvas {
35
+ position: fixed;
36
+ overflow: auto;
37
+ z-index: 1000;
38
+ top: 55px;
39
+ }
40
+ .fixed-mobile .l-header__branding {
41
+ margin-top: 55px;
42
+ }
43
+ }
44
+
45
+ @media (min-width: 992px) {
46
+ .fixed-desktop .l-navbar {
47
+ position: fixed;
48
+ z-index: 1000;
49
+ top: 0;
50
+ right: 0;
51
+ left: 0;
52
+ width: 100%;
53
+ }
54
+ }
55
+
23
56
  `;
24
57
 
25
58
  return [
@@ -41,7 +74,7 @@ ${this.isDemo ? html`
41
74
  .l-navbar { top: auto !important}
42
75
  </style>
43
76
  ` : html``}
44
- <header class="l-header header">
77
+ <header class=${classMap(this._getHeaderClasses())}>
45
78
  <div class="mobile-bar">
46
79
  <div class="mobile-bar__nav-toggle">
47
80
  <button
@@ -61,32 +94,34 @@ ${this.isDemo ? html`
61
94
  </div>
62
95
  </div>
63
96
 
64
- <div class="header__bar">
65
- <div class="header__university">
66
- <a href="https://www.ucdavis.edu/">
67
- <img class="ucd-logo" src='data:image/svg+xml;utf8,${this._ucdLogo()}'>
68
- </a>
69
- </div>
70
- </div>
71
- <div class="l-header__branding">
72
- ${this._hasSlottedBranding ? html`
73
- <slot name="branding-bar"></slot>
74
- ` : html`
75
- <div class="site-branding">
76
- <div class="site-branding__figure" ?hidden=${!this.figureSrc}>
77
- <a href="${this.siteUrl}" class=""><img src=${this.figureSrc} class="site-logo" alt="Site Logo" /></a>
97
+ <div id="branding-bar-container">
98
+ <div class="header__bar">
99
+ <div class="header__university">
100
+ <a href="https://www.ucdavis.edu/">
101
+ <img class="ucd-logo" src='data:image/svg+xml;utf8,${this._ucdLogo()}'>
102
+ </a>
78
103
  </div>
79
- <div class="site-branding__body">
80
- <h1 class="site-branding__site-name" ?hidden=${!this.siteName}>
81
- <a href=${this.siteUrl}>${this.siteName}</a>
82
- </h1>
83
- <div class="site-branding__slogan" ?hidden=${!this.slogan}>${this.slogan}</div>
104
+ </div>
105
+ <div class="l-header__branding">
106
+ ${this._hasSlottedBranding ? html`
107
+ <slot name="branding-bar"></slot>
108
+ ` : html`
109
+ <div class="site-branding">
110
+ <div class="site-branding__figure" ?hidden=${!this.figureSrc}>
111
+ <a href="${this.siteUrl}" class=""><img src=${this.figureSrc} class="site-logo" alt="Site Logo" /></a>
112
+ </div>
113
+ <div class="site-branding__body">
114
+ <h1 class="site-branding__site-name" ?hidden=${!this.siteName}>
115
+ <a href=${this.siteUrl}>${this.siteName}</a>
116
+ </h1>
117
+ <div class="site-branding__slogan" ?hidden=${!this.slogan}>${this.slogan}</div>
118
+ </div>
84
119
  </div>
85
- </div>
86
- `}
120
+ `}
121
+ </div>
87
122
  </div>
88
123
 
89
- <div class="${classMap(this._getNavbarClasses())}">
124
+ <div class="${classMap(this._getNavbarClasses())}" id="nav-bar">
90
125
  <div class="l-container--navigation off-canvas off-canvas--left">
91
126
  <div class="off-canvas__container l-nav-horizontal">
92
127
  ${this._hasSearch ? html`
@@ -1,7 +1,8 @@
1
1
  import { LitElement, html } from 'lit';
2
2
  //import { Page } from 'puppeteer';
3
3
  import {render, styles} from "./ucd-theme-pagination.tpl.js";
4
- import { Mixin, BreakPoints } from "../../utils/index.js";
4
+
5
+ import { BreakPointsController } from '../../utils/controllers';
5
6
 
6
7
  /**
7
8
  * @class UcdThemePagination
@@ -11,6 +12,7 @@ import { Mixin, BreakPoints } from "../../utils/index.js";
11
12
  * - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-pagination
12
13
  *
13
14
  * @property {String} base-path - for anchor tag href
15
+ * @property {String} queryParams - Append query parameters if constructing an anchor tag
14
16
  * @property {String} current-page - Page to show and highlight
15
17
  * @property {String} max-pages - Max number of total pages
16
18
  * @property {String} visible-link-count - How many page links to show
@@ -33,8 +35,8 @@ import { Mixin, BreakPoints } from "../../utils/index.js";
33
35
  * </ucd-theme-pagination>
34
36
  *
35
37
  */
36
- export default class UcdThemePagination extends Mixin(LitElement)
37
- .with(BreakPoints) {
38
+ export default class UcdThemePagination extends LitElement {
39
+ breakPoints = new BreakPointsController(this);
38
40
 
39
41
  static get properties() {
40
42
  return {
@@ -42,6 +44,10 @@ export default class UcdThemePagination extends Mixin(LitElement)
42
44
  type: String,
43
45
  attribute: 'base-path'
44
46
  },
47
+ queryParams: {
48
+ type: String,
49
+ attribute: 'query-params'
50
+ },
45
51
  useHash : {
46
52
  type: Boolean,
47
53
  attribute: 'use-hash'
@@ -94,6 +100,7 @@ export default class UcdThemePagination extends Mixin(LitElement)
94
100
  this.disableLabel = false;
95
101
  this.type = 'virtual';
96
102
  this.basePath = '';
103
+ this.queryParams = '';
97
104
  this.visibleLinkCount = 7;
98
105
  this.currentPage = 1;
99
106
  this.maxPages = 1;
@@ -101,8 +108,7 @@ export default class UcdThemePagination extends Mixin(LitElement)
101
108
  this.xs_screen = false;
102
109
  this.size = '';
103
110
 
104
- this.screen_check = (window.innerWidth <= this._mobileBreakPoint) ? true : false;
105
- console.log(this.screen_check);
111
+ this.screen_check = (window.innerWidth <= this.breakPoints.mobileBreakPoint) ? true : false;
106
112
 
107
113
  this.render = render.bind(this);
108
114
  }
@@ -190,7 +196,7 @@ export default class UcdThemePagination extends Mixin(LitElement)
190
196
  </li>`;
191
197
  }
192
198
 
193
- let href = (this.useHash ? '#' : '') + (this.basePath || '/') + page;
199
+ let href = (this.useHash ? '#' : '') + (this.basePath || '/') + page + (this.queryParams ? '?' + this.queryParams : '');
194
200
  return html`<li class="pager__item ${args.class || ''}">
195
201
  ${((this.currentPage == 1 && args.label == "Prev") || (this.currentPage == this.maxPages && args.label == "Next") ) ?
196
202
  html` <a style="pointer-events: none; cursor: default; color:#999999; background:white;" href="${href}">${args.label || page}</a>`:
@@ -4,7 +4,8 @@ import { styleMap } from 'lit/directives/style-map.js';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
  import { ifDefined } from 'lit/directives/if-defined.js';
6
6
 
7
- import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.js";
7
+ import { Mixin, NavElement } from "../../utils/mixins";
8
+ import { MutationObserverController, BreakPointsController } from '../../utils/controllers';
8
9
 
9
10
  /**
10
11
  * @class UcdThemePrimaryNav
@@ -33,7 +34,10 @@ import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.j
33
34
  * </ucd-theme-primary-nav>
34
35
  */
35
36
  export default class UcdThemePrimaryNav extends Mixin(LitElement)
36
- .with(MutationObserverElement, BreakPoints) {
37
+ .with(NavElement) {
38
+
39
+ mutationObserver = new MutationObserverController(this, {subtree: true, childList: true});
40
+ breakPoints = new BreakPointsController(this);
37
41
 
38
42
  static get properties() {
39
43
  return {
@@ -58,8 +62,6 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
58
62
  this.styleModifiers = "";
59
63
  this.hoverDelay = 300;
60
64
  this.animationDuration = 300;
61
- this.navItems = [];
62
- this.maxDepth = 2;
63
65
 
64
66
  this._classPrefix = "primary-nav";
65
67
  this._acceptedNavTypes = ['superfish', 'mega'];
@@ -99,7 +101,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
99
101
  if ( !navItem ) return;
100
102
 
101
103
  // Open on mobile
102
- if ( this.isMobile() ) {
104
+ if ( this.breakPoints.isMobile() ) {
103
105
  let nav = this.renderRoot.getElementById(`nav--${navLocation.join("-")}`);
104
106
  if ( !nav ) return;
105
107
  let ul = nav.querySelector('ul');
@@ -108,14 +110,14 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
108
110
  navItem.isTransitioning = true;
109
111
 
110
112
  // Get expanded height
111
- navItem.mobileStyles.display = "block";
112
- navItem.mobileStyles.height = 0 + "px";
113
+ navItem.inlineStyles.display = "block";
114
+ navItem.inlineStyles.height = 0 + "px";
113
115
  this.requestUpdate();
114
116
  await this.updateComplete;
115
117
  const expandedHeight = ul.scrollHeight + "px";
116
118
 
117
119
  // Set expanded height
118
- navItem.mobileStyles.height = expandedHeight;
120
+ navItem.inlineStyles.height = expandedHeight;
119
121
  this.requestUpdate();
120
122
  await this.updateComplete;
121
123
 
@@ -131,7 +133,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
131
133
  return;
132
134
  }
133
135
 
134
- this.clearMobileAnimationStyles(navItem);
136
+ this.clearItemInlineStyles(navItem);
135
137
  if ( navItem.isClosing ) {
136
138
  navItem.isClosing = false;
137
139
  this.requestUpdate();
@@ -162,7 +164,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
162
164
  if ( !navItem ) return;
163
165
 
164
166
  // close on mobile
165
- if ( this.isMobile() ) {
167
+ if ( this.breakPoints.isMobile() ) {
166
168
  let nav = this.renderRoot.getElementById(`nav--${navLocation.join("-")}`);
167
169
  if ( !nav ) return;
168
170
  let ul = nav.querySelector('ul');
@@ -171,15 +173,15 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
171
173
  navItem.isTransitioning = true;
172
174
 
173
175
  // Set expanded height
174
- navItem.mobileStyles.height = ul.scrollHeight + "px";
175
- navItem.mobileStyles.display = "block";
176
+ navItem.inlineStyles.height = ul.scrollHeight + "px";
177
+ navItem.inlineStyles.display = "block";
176
178
  this.requestUpdate();
177
179
  await this.updateComplete;
178
180
 
179
181
  // Set height to 0 by requesting all of the animation frames :-(
180
182
  requestAnimationFrame(() => {
181
183
  requestAnimationFrame(() => {
182
- navItem.mobileStyles.height = "0px";
184
+ navItem.inlineStyles.height = "0px";
183
185
  this.requestUpdate();
184
186
 
185
187
  requestAnimationFrame(() => {
@@ -200,7 +202,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
200
202
  }
201
203
 
202
204
 
203
- this.clearMobileAnimationStyles(navItem);
205
+ this.clearItemInlineStyles(navItem);
204
206
  if ( navItem.timeout ) clearTimeout(navItem.timeout);
205
207
  if ( !navItem.isOpen ) return;
206
208
 
@@ -234,22 +236,6 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
234
236
  });
235
237
  }
236
238
 
237
- /**
238
- * @method clearMobileAnimationStyles
239
- * @description Removes inline styles on a nav element (used for mobile transition animation)
240
- * @param {Object} navItem - Member of the this.navItems array
241
- */
242
- clearMobileAnimationStyles(navItem){
243
- if (
244
- navItem &&
245
- navItem.mobileStyles &&
246
- Object.keys(navItem.mobileStyles).length > 0
247
- ) {
248
- navItem.mobileStyles = {};
249
- this.requestUpdate();
250
- }
251
- }
252
-
253
239
  /**
254
240
  * @method isMegaMenu
255
241
  * @description Does this element use the mega menu?
@@ -260,20 +246,6 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
260
246
  return false;
261
247
  }
262
248
 
263
- /**
264
- * @method getNavItem
265
- * @description Retrieves an item from the navItems array.
266
- * @param {Array} location - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4].
267
- * @returns {Object}
268
- */
269
- getNavItem(location){
270
- let accessor = "this.navItems";
271
- if ( location && location.length > 0) {
272
- accessor += "[" + location.join("].subItems[") + "]";
273
- }
274
- return eval(accessor);
275
- }
276
-
277
249
  /**
278
250
  * @method _getNavClasses
279
251
  * @private
@@ -295,46 +267,14 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
295
267
  /**
296
268
  * @method _onChildListMutation
297
269
  * @private
298
- * @description Fires when light dom child list changes. Injected by MutationObserverElement mixin.
270
+ * @description Fires when light dom child list changes. Injected by MutationObserverController.
299
271
  * Sets the 'navItems' property.
300
272
  */
301
273
  _onChildListMutation(){
302
- const children = Array.from(this.children);
303
- let navItems = children.map((child) => this._makeNavItemTree(child)).filter(navItem => navItem.linkText);
274
+ let navItems = this.parseNavChildren();
304
275
  if ( navItems.length ) this.navItems = navItems;
305
276
  }
306
277
 
307
- /**
308
- * @method _makeNavItemTree
309
- * @private
310
- * @description Extracts menu item data from DOM Element
311
- * @param {Element} ele - Element
312
- * @returns {Object} Formatted object describing the menu item and its children
313
- */
314
- _makeNavItemTree(ele){
315
- let linkText, href, subItems = [], isOpen=false, mobileStyles={};
316
- if ( ele.tagName === 'LI' && ele.children.length > 0) ele = ele.children[0];
317
-
318
- if ( ele.tagName === 'A' ) {
319
- linkText = ele.innerText;
320
- href = ele.href;
321
- } else if ( ele.tagName === 'LI' ) {
322
- linkText = ele.innerText;
323
- } else if ( ele.tagName === 'OL' || ele.tagName === 'UL' ) {
324
- linkText = ele.getAttribute('link-text');
325
- href = ele.getAttribute('href');
326
-
327
- for (const child of Array.from(ele.children)) {
328
- let childItem = this._makeNavItemTree(child);
329
- if ( childItem.linkText ) subItems.push(childItem);
330
- }
331
- }
332
-
333
- if ( linkText ) linkText = linkText.trim();
334
- return {linkText, href, subItems, isOpen, mobileStyles};
335
-
336
- }
337
-
338
278
  /**
339
279
  * @method _renderNavItem
340
280
  * @private
@@ -347,7 +287,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
347
287
  const depth = location.length - 1;
348
288
 
349
289
  // Render item and its subnav
350
- if ( this._hasSubNav(navItem) && depth < this.maxDepth) {
290
+ if ( this.itemHasSubNav(navItem) && depth < this.maxDepth) {
351
291
  return html`
352
292
  <li
353
293
  id="nav--${location.join("-")}"
@@ -409,7 +349,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
409
349
  this.isMegaMenu() &&
410
350
  depth > 0 &&
411
351
  !this._megaIsOpen &&
412
- this.isDesktop()
352
+ this.breakPoints.isDesktop()
413
353
  ) i = -1;
414
354
 
415
355
  return i;
@@ -439,7 +379,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
439
379
  * @param {Array} navLocation - Array coordinates of corresponding nav item
440
380
  */
441
381
  async _toggleMobileMenu(navLocation){
442
- if ( this.isDesktop() ) return;
382
+ if ( this.breakPoints.isDesktop() ) return;
443
383
  let navItem = this.getNavItem(navLocation);
444
384
  if ( navItem.isOpen ) {
445
385
  this.closeSubNav(navLocation);
@@ -455,7 +395,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
455
395
  */
456
396
  _onNavMouseenter(){
457
397
  if (
458
- this.isMobile() ||
398
+ this.breakPoints.isMobile() ||
459
399
  !this.isMegaMenu() )
460
400
  return;
461
401
 
@@ -472,7 +412,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
472
412
  */
473
413
  _onNavMouseleave(){
474
414
  if (
475
- this.isMobile() ||
415
+ this.breakPoints.isMobile() ||
476
416
  !this.isMegaMenu() )
477
417
  return;
478
418
 
@@ -490,7 +430,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
490
430
  */
491
431
  _onNavFocusin(){
492
432
  if (
493
- this.isMobile() ||
433
+ this.breakPoints.isMobile() ||
494
434
  !this.isMegaMenu() )
495
435
  return;
496
436
 
@@ -511,7 +451,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
511
451
  * @param {Event} e
512
452
  */
513
453
  _onItemMouseenter(e){
514
- if ( this.isMobile() ) return;
454
+ if ( this.breakPoints.isMobile() ) return;
515
455
  this.openSubNav(e.target.key);
516
456
  }
517
457
 
@@ -522,7 +462,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
522
462
  * @param {Event} e
523
463
  */
524
464
  _onItemFocus(e){
525
- if ( this.isMobile() ) return;
465
+ if ( this.breakPoints.isMobile() ) return;
526
466
  const LI = e.target.parentElement.parentElement;
527
467
 
528
468
  if (LI.hasnav) {
@@ -561,7 +501,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
561
501
  */
562
502
  _completeMobileTransition(navItem){
563
503
  navItem.timeout = setTimeout(() => {
564
- navItem.mobileStyles = {};
504
+ navItem.inlineStyles = {};
565
505
  navItem.isOpen = !navItem.isOpen;
566
506
  navItem.isTransitioning = false;
567
507
  this.requestUpdate();
@@ -575,7 +515,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
575
515
  * @param {Event} e
576
516
  */
577
517
  _onItemMouseleave(e){
578
- if ( this.isMobile() || this.isMegaMenu() ) return;
518
+ if ( this.breakPoints.isMobile() || this.isMegaMenu() ) return;
579
519
  this.closeSubNav(e.target.key);
580
520
  }
581
521
 
@@ -585,7 +525,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
585
525
  * @description Attached to the top-level nav element. Closes subnav if it doesn't contain focused link.
586
526
  */
587
527
  _onNavFocusout(){
588
- if ( this.isMobile() ) return;
528
+ if ( this.breakPoints.isMobile() ) return;
589
529
  if ( this.isMegaMenu() ) {
590
530
  if ( this._megaTimeout ) clearTimeout(this._megaTimeout);
591
531
  requestAnimationFrame(() => {
@@ -630,18 +570,6 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
630
570
 
631
571
  }
632
572
 
633
- /**
634
- * @method _hasSubNav
635
- * @private
636
- * @description Utility function for determining if a menu has subitems
637
- * @param {Object} navItem - A member of the navItems array.
638
- * @returns {Boolean}
639
- */
640
- _hasSubNav(navItem){
641
- if ( navItem && navItem.subItems && navItem.subItems.length) return true;
642
- return false;
643
- }
644
-
645
573
  /**
646
574
  * @method _getItemMobileStyles
647
575
  * @private
@@ -650,10 +578,10 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
650
578
  * @returns {Object} - Style map
651
579
  */
652
580
  _getItemMobileStyles(location) {
653
- if ( this.isDesktop() ) return {};
581
+ if ( this.breakPoints.isDesktop() ) return {};
654
582
  let navItem = this.getNavItem(location);
655
- if ( !navItem.mobileStyles ) return {};
656
- return navItem.mobileStyles;
583
+ if ( !navItem.inlineStyles ) return {};
584
+ return navItem.inlineStyles;
657
585
  }
658
586
 
659
587
  }