@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.
- package/brand/ucd-theme-header/ucd-theme-header.js +67 -31
- package/brand/ucd-theme-header/ucd-theme-header.tpl.js +58 -23
- package/brand/ucd-theme-pagination/ucd-theme-pagination.js +12 -6
- package/brand/ucd-theme-primary-nav/ucd-theme-primary-nav.js +32 -104
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.js +9 -34
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.tpl.js +1 -1
- package/brand/ucd-theme-search-form/ucd-theme-search-form.js +7 -1
- package/brand/ucd-theme-search-form/ucd-theme-search-form.tpl.js +8 -3
- package/brand/ucd-theme-search-popup/ucd-theme-search-popup.js +3 -3
- package/brand/ucd-theme-slim-select/ucd-theme-slim-select.js +62 -0
- package/brand/ucd-theme-slim-select/ucd-theme-slim-select.tpl.js +26 -0
- package/brand/ucd-theme-subnav/ucd-theme-subnav.js +196 -0
- package/brand/ucd-theme-subnav/ucd-theme-subnav.tpl.js +60 -0
- package/package.json +5 -4
- package/ucdlib/ucdlib-branding-bar/book.js +4 -0
- package/ucdlib/ucdlib-branding-bar/logo.js +67 -0
- package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.js +101 -0
- package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.tpl.js +102 -0
- package/ucdlib/ucdlib-icon/ucdlib-icon.tpl.js +2 -0
- package/ucdlib/ucdlib-icons/sitefarm.js +107 -0
- package/ucdlib/ucdlib-icons/ucdlib-icons.js +7 -1
- package/ucdlib/ucdlib-icons/utils.js +3 -3
- package/ucdlib/ucdlib-iconset/ucdlib-iconset.js +5 -2
- package/ucdlib/ucdlib-pages/ucdlib-pages.js +4 -4
- package/utils/{break-points.js → controllers/break-points.js} +8 -9
- package/utils/controllers/index.js +11 -0
- package/utils/controllers/intersection-observer.js +58 -0
- package/utils/controllers/mutation-observer.js +52 -0
- package/utils/controllers/wait.js +43 -0
- package/utils/mixins/index.js +8 -0
- package/utils/{main-dom-element.js → mixins/main-dom-element.js} +0 -0
- package/utils/{mixin.js → mixins/mixin.js} +0 -0
- package/utils/mixins/nav-element.js +103 -0
- package/utils/index.js +0 -6
- package/utils/mutation-observer.js +0 -47
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LitElement, html } from 'lit';
|
|
2
2
|
import {render, styles} from "./ucd-theme-quick-links.tpl.js";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { MutationObserverController, WaitController } from '../../utils/controllers';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @class UcdThemeQuickLinks
|
|
@@ -17,8 +17,10 @@ import { Mixin, BreakPoints } from "../../utils/index.js";
|
|
|
17
17
|
* @property {Boolean} opened - Menu is open
|
|
18
18
|
* @property {Number} animationDuration - Length of animation when opening/closing menu
|
|
19
19
|
*/
|
|
20
|
-
export default class UcdThemeQuickLinks extends
|
|
21
|
-
|
|
20
|
+
export default class UcdThemeQuickLinks extends LitElement {
|
|
21
|
+
|
|
22
|
+
mutationObserver = new MutationObserverController(this);
|
|
23
|
+
wait = new WaitController(this);
|
|
22
24
|
|
|
23
25
|
static get properties() {
|
|
24
26
|
return {
|
|
@@ -67,7 +69,7 @@ export default class UcdThemeQuickLinks extends Mixin(LitElement)
|
|
|
67
69
|
this._openedHeight = this.renderRoot.getElementById('menu').scrollHeight + "px";
|
|
68
70
|
await this.updateComplete;
|
|
69
71
|
|
|
70
|
-
await this.
|
|
72
|
+
await this.wait.wait(this.animationDuration);
|
|
71
73
|
this._transitioning = false;
|
|
72
74
|
this.opened = true;
|
|
73
75
|
return true;
|
|
@@ -84,11 +86,11 @@ export default class UcdThemeQuickLinks extends Mixin(LitElement)
|
|
|
84
86
|
|
|
85
87
|
this._openedHeight = this.renderRoot.getElementById('menu').scrollHeight + "px";
|
|
86
88
|
await this.updateComplete;
|
|
87
|
-
await this.
|
|
89
|
+
await this.wait.waitForFrames(2);
|
|
88
90
|
this._openedHeight = 0;
|
|
89
91
|
await this.updateComplete;
|
|
90
92
|
|
|
91
|
-
await this.
|
|
93
|
+
await this.wait.wait(this.animationDuration);
|
|
92
94
|
|
|
93
95
|
this._transitioning = false;
|
|
94
96
|
this.opened = false;
|
|
@@ -229,7 +231,7 @@ export default class UcdThemeQuickLinks extends Mixin(LitElement)
|
|
|
229
231
|
* @method _onChildListMutation
|
|
230
232
|
* @param {Array} mutationsList - List of mutation records
|
|
231
233
|
* @private
|
|
232
|
-
* @description Fires when light dom child list changes. Injected by
|
|
234
|
+
* @description Fires when light dom child list changes. Injected by MutationObserverController.
|
|
233
235
|
* Sets the '_links' property.
|
|
234
236
|
*/
|
|
235
237
|
_onChildListMutation(mutationsList){
|
|
@@ -262,33 +264,6 @@ export default class UcdThemeQuickLinks extends Mixin(LitElement)
|
|
|
262
264
|
return html``;
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
/**
|
|
266
|
-
* @method _waitForAnimation
|
|
267
|
-
* @private
|
|
268
|
-
* @description Wait for time designated for open/close animation
|
|
269
|
-
* @returns {Promise}
|
|
270
|
-
*/
|
|
271
|
-
async _waitForAnimation() {
|
|
272
|
-
return new Promise(resolve => {
|
|
273
|
-
setTimeout(resolve, this.animationDuration);
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @method _waitForFrames
|
|
279
|
-
* @private
|
|
280
|
-
* @description Wait for specified number of animation frames
|
|
281
|
-
* @param {Number} ct Number of frames
|
|
282
|
-
*/
|
|
283
|
-
async _waitForFrames(ct=1) {
|
|
284
|
-
for (let i = 0; i < ct; i++) {
|
|
285
|
-
await new Promise(resolve => {
|
|
286
|
-
requestAnimationFrame(resolve);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
267
|
}
|
|
293
268
|
|
|
294
269
|
customElements.define('ucd-theme-quick-links', UcdThemeQuickLinks);
|
|
@@ -84,7 +84,7 @@ return html`
|
|
|
84
84
|
aria-controls="quick-links"
|
|
85
85
|
aria-expanded="${this.opened}"
|
|
86
86
|
aria-label="Toggle ${this.title} Menu">
|
|
87
|
-
${this.title}<span class="submenu-toggle"><span class="submenu-toggle__icon">+</span></span>
|
|
87
|
+
${this.title}<span class="submenu-toggle ${this.opened ? 'submenu-toggle--open' : ''}"><span class="submenu-toggle__icon">+</span></span>
|
|
88
88
|
</button>
|
|
89
89
|
<nav
|
|
90
90
|
id="quick-links"
|
|
@@ -11,6 +11,8 @@ import {render, styles } from "./ucd-theme-search-form.tpl.js";
|
|
|
11
11
|
* @property {String} value - The search string
|
|
12
12
|
* @property {String} placeholder - The input placeholder
|
|
13
13
|
* @property {String} formAction - The action to be taken on form submit (optional)
|
|
14
|
+
* @property {String} formMethod - The http method used on submit (default=POST)
|
|
15
|
+
* @property {String} queryParam - The URL query parameter to use (default=searchterm)
|
|
14
16
|
*
|
|
15
17
|
* @example
|
|
16
18
|
* <ucd-theme-form-search form-action="/url/to/post/to"></ucd-theme-form-search>
|
|
@@ -23,9 +25,11 @@ export default class UcdThemeSearchForm extends LitElement {
|
|
|
23
25
|
value: {type: String},
|
|
24
26
|
placeholder: {type: String, attribute: "placeholder"},
|
|
25
27
|
formAction: {type: String, attribute: "form-action"},
|
|
28
|
+
formMethod: {type: String, attribute: "form-method"},
|
|
26
29
|
formClass: {type: String, attribute: "form-class"},
|
|
27
30
|
labelText: {type: String, attribute: "label-text"},
|
|
28
|
-
inputClass: {type: String, attribute: "input-class"}
|
|
31
|
+
inputClass: {type: String, attribute: "input-class"},
|
|
32
|
+
queryParam: {type: String, attribute: "query-param"}
|
|
29
33
|
};
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -37,11 +41,13 @@ export default class UcdThemeSearchForm extends LitElement {
|
|
|
37
41
|
super();
|
|
38
42
|
this.render = render.bind(this);
|
|
39
43
|
this.formAction = "";
|
|
44
|
+
this.formMethod = "POST";
|
|
40
45
|
this.formClass = "";
|
|
41
46
|
this.labelText = "Search";
|
|
42
47
|
this.placeholder = "Search...";
|
|
43
48
|
this.inputClass = "";
|
|
44
49
|
this.value = "";
|
|
50
|
+
this.queryParam = "searchterm";
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -14,6 +14,10 @@ export function styles() {
|
|
|
14
14
|
[hidden] {
|
|
15
15
|
display: none !important;
|
|
16
16
|
}
|
|
17
|
+
.search-form__submit {
|
|
18
|
+
line-height: 1.9;
|
|
19
|
+
text-indent: .2em;
|
|
20
|
+
}
|
|
17
21
|
`;
|
|
18
22
|
return [
|
|
19
23
|
normalizeCss,
|
|
@@ -29,7 +33,7 @@ return html`
|
|
|
29
33
|
<form
|
|
30
34
|
@submit="${this._onSubmit}"
|
|
31
35
|
action="${this.formAction}"
|
|
32
|
-
method
|
|
36
|
+
method=${this.formMethod}
|
|
33
37
|
class="search-form ${this.formClass}">
|
|
34
38
|
|
|
35
39
|
<label for="search" class="u-hidden--visually">${this.labelText}</label>
|
|
@@ -38,10 +42,11 @@ return html`
|
|
|
38
42
|
placeholder="${this.placeholder}"
|
|
39
43
|
id="search"
|
|
40
44
|
class="search-form__input ${this.inputClass}"
|
|
41
|
-
name
|
|
45
|
+
name=${this.queryParam}
|
|
42
46
|
@input="${this._onInput}"
|
|
43
47
|
value="${this.value}">
|
|
44
|
-
<
|
|
48
|
+
<button type="submit" class="search-form__submit"> Submit
|
|
49
|
+
</button>
|
|
45
50
|
|
|
46
51
|
</form>
|
|
47
52
|
`;}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import {render, styles} from "./ucd-theme-search-popup.tpl.js";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { MutationObserverController } from '../../utils/controllers';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @class UcdThemeSearchPopup
|
|
@@ -24,8 +24,8 @@ import { Mixin, MutationObserverElement } from "../../utils/index.js";
|
|
|
24
24
|
* <input placeholder="A custom search element">
|
|
25
25
|
* </ucd-theme-search-popup>
|
|
26
26
|
*/
|
|
27
|
-
export default class UcdThemeSearchPopup extends
|
|
28
|
-
|
|
27
|
+
export default class UcdThemeSearchPopup extends LitElement {
|
|
28
|
+
mutationObserver = new MutationObserverController(this);
|
|
29
29
|
|
|
30
30
|
static get properties() {
|
|
31
31
|
return {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import {render, styles} from "./ucd-theme-slim-select.tpl.js";
|
|
3
|
+
|
|
4
|
+
import SlimSelect from 'slim-select';
|
|
5
|
+
|
|
6
|
+
import { MutationObserverController } from '../../utils/controllers';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class UcdThemeSlimSelect
|
|
10
|
+
* @classdesc UI component class for displaying a fancy select. This is a wrapper element around the 'slim-select' package.
|
|
11
|
+
*
|
|
12
|
+
* Patternlab URL:
|
|
13
|
+
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=atoms-select-menu
|
|
14
|
+
*/
|
|
15
|
+
export default class UcdThemeSlimSelect extends LitElement {
|
|
16
|
+
mutationObserver = new MutationObserverController(
|
|
17
|
+
this,
|
|
18
|
+
{subtree: true, childList: true, attributes: true, characterData: true},
|
|
19
|
+
"_onLightDomMutation"
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
static get properties() {
|
|
23
|
+
return {
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static get styles() {
|
|
29
|
+
return styles();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this.render = render.bind(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @method _onLightDomMutation
|
|
39
|
+
* @private
|
|
40
|
+
* @description Fires when light dom child list changes. Called by MutationObserverController.
|
|
41
|
+
*/
|
|
42
|
+
_onLightDomMutation(){
|
|
43
|
+
const children = Array.from(this.children);
|
|
44
|
+
if (children.length == 0 || children[0].tagName != "SELECT") return;
|
|
45
|
+
const select = children[0].cloneNode(true);
|
|
46
|
+
if ( this.slimSelect ){
|
|
47
|
+
this.slimSelect.destroy();
|
|
48
|
+
this.renderRoot.querySelector('.ss-main').remove();
|
|
49
|
+
this.renderRoot.querySelector('select').remove();
|
|
50
|
+
}
|
|
51
|
+
this.renderRoot.appendChild(select);
|
|
52
|
+
|
|
53
|
+
this.slimSelect = new SlimSelect({
|
|
54
|
+
select: select,
|
|
55
|
+
onChange: (info) => this.dispatchEvent(new CustomEvent("change", {detail: info}))
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
customElements.define('ucd-theme-slim-select', UcdThemeSlimSelect);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { html, css } from 'lit';
|
|
2
|
+
|
|
3
|
+
import formStyles from "@ucd-lib/theme-sass/2_base_class/_forms.css.js";
|
|
4
|
+
import slimSelectStyles from "@ucd-lib/theme-sass/slim-select.css.js"
|
|
5
|
+
import selectStyles from "@ucd-lib/theme-sass/4_component/_slim-select.css.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export function styles() {
|
|
10
|
+
const elementStyles = css`
|
|
11
|
+
:host {
|
|
12
|
+
display: block;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
return [
|
|
17
|
+
formStyles,
|
|
18
|
+
slimSelectStyles,
|
|
19
|
+
selectStyles,
|
|
20
|
+
elementStyles];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function render() {
|
|
24
|
+
return html`
|
|
25
|
+
|
|
26
|
+
`;}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { LitElement, html } from 'lit';
|
|
2
|
+
import {render, styles} from "./ucd-theme-subnav.tpl.js";
|
|
3
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
|
+
|
|
5
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
6
|
+
|
|
7
|
+
import {Mixin, NavElement} from "../../utils/mixins";
|
|
8
|
+
import { MutationObserverController, WaitController } from '../../utils/controllers';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class UcdThemeSubnav
|
|
12
|
+
* @classdesc Component class for displaying a subnav
|
|
13
|
+
*
|
|
14
|
+
* Patternlab url:
|
|
15
|
+
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-sub-nav
|
|
16
|
+
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-sub-nav-linked-title
|
|
17
|
+
*
|
|
18
|
+
* @property {String} navTitle - Subnav header text
|
|
19
|
+
* @property {String} titleHref - Link for subnav header (optional)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <ucd-theme-subnav nav-title="A subnav">
|
|
23
|
+
* <li><a href="#">Link 1</a></li>
|
|
24
|
+
* <li><a href="#">Link 2</a></li>
|
|
25
|
+
* <ul link-text="Link with Children" href="#">
|
|
26
|
+
* <li><a href="#">Child 1</a></li>
|
|
27
|
+
* <li><a href="#">Child 2</a></li>
|
|
28
|
+
* <li><a href="#">Child 3</a></li>
|
|
29
|
+
* </ul>
|
|
30
|
+
* </ucd-theme-subnav>
|
|
31
|
+
*/
|
|
32
|
+
export default class UcdThemeSubnav extends Mixin(LitElement)
|
|
33
|
+
.with(NavElement) {
|
|
34
|
+
|
|
35
|
+
mutationObserver = new MutationObserverController(this, {subtree: true, childList: true});
|
|
36
|
+
wait = new WaitController(this);
|
|
37
|
+
|
|
38
|
+
static get properties() {
|
|
39
|
+
return {
|
|
40
|
+
navTitle: {type: String, attribute: "nav-title"},
|
|
41
|
+
titleHref: {type: String, attribute: "title-href"},
|
|
42
|
+
navItems: {type: Array},
|
|
43
|
+
animationDuration: {type: Number, attribute: "animation-duration"}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static get styles() {
|
|
48
|
+
return styles();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
constructor() {
|
|
52
|
+
super();
|
|
53
|
+
this.render = render.bind(this);
|
|
54
|
+
|
|
55
|
+
this.navTitle = "";
|
|
56
|
+
this.titleHref = "";
|
|
57
|
+
this.animationDuration = 300;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @method openNavItem
|
|
62
|
+
* @description Shows children of a nav item (if applicable)
|
|
63
|
+
* @param {Array} navLocation - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4].
|
|
64
|
+
* @returns {Boolean}
|
|
65
|
+
*/
|
|
66
|
+
async openNavItem(navLocation){
|
|
67
|
+
let navItem = this.getNavItem(navLocation);
|
|
68
|
+
if ( !navItem || navItem.isTransitioning ) return false;
|
|
69
|
+
|
|
70
|
+
let navEle = this.renderRoot.getElementById(`nav--${navLocation.join("-")}`);
|
|
71
|
+
if ( !navEle ) return false;
|
|
72
|
+
let navUL = navEle.querySelector('ul');
|
|
73
|
+
if ( !navUL ) return false;
|
|
74
|
+
navItem.isTransitioning = true;
|
|
75
|
+
|
|
76
|
+
// Get expanded height
|
|
77
|
+
navItem.inlineStyles.display = "block";
|
|
78
|
+
navItem.inlineStyles.height = "0px";
|
|
79
|
+
await this.wait.waitForUpdate();
|
|
80
|
+
const expandedHeight = navUL.scrollHeight + "px";
|
|
81
|
+
|
|
82
|
+
// Set expanded height
|
|
83
|
+
navItem.inlineStyles.height = expandedHeight;
|
|
84
|
+
await this.wait.waitForUpdate();
|
|
85
|
+
|
|
86
|
+
// Complete animation
|
|
87
|
+
await this.wait.wait(this.animationDuration);
|
|
88
|
+
navItem.inlineStyles = {};
|
|
89
|
+
navItem.isOpen = true;
|
|
90
|
+
navItem.isTransitioning = false;
|
|
91
|
+
this.requestUpdate();
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @method closeNavItem
|
|
98
|
+
* @description Hides children of a nav item (if applicable)
|
|
99
|
+
* @param {Array} navLocation - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4].
|
|
100
|
+
* @returns {Boolean}
|
|
101
|
+
*/
|
|
102
|
+
async closeNavItem(navLocation){
|
|
103
|
+
let navItem = this.getNavItem(navLocation);
|
|
104
|
+
if ( !navItem || navItem.isTransitioning ) return false;
|
|
105
|
+
|
|
106
|
+
let navEle = this.renderRoot.getElementById(`nav--${navLocation.join("-")}`);
|
|
107
|
+
if ( !navEle ) return false;
|
|
108
|
+
let navUL = navEle.querySelector('ul');
|
|
109
|
+
if ( !navUL ) return false;
|
|
110
|
+
navItem.isTransitioning = true;
|
|
111
|
+
|
|
112
|
+
// Set expanded height
|
|
113
|
+
navItem.inlineStyles.height = navUL.scrollHeight + "px";
|
|
114
|
+
navItem.inlineStyles.display = "block";
|
|
115
|
+
await this.wait.waitForUpdate();
|
|
116
|
+
|
|
117
|
+
// Set height to zero
|
|
118
|
+
await this.wait.waitForFrames(2);
|
|
119
|
+
navItem.inlineStyles.height = "0px";
|
|
120
|
+
await this.wait.waitForUpdate();
|
|
121
|
+
|
|
122
|
+
// Complete animation
|
|
123
|
+
await this.wait.wait(this.animationDuration);
|
|
124
|
+
navItem.inlineStyles = {};
|
|
125
|
+
navItem.isOpen = false;
|
|
126
|
+
navItem.isTransitioning = false;
|
|
127
|
+
this.requestUpdate();
|
|
128
|
+
|
|
129
|
+
return true;
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @method _onChildListMutation
|
|
135
|
+
* @private
|
|
136
|
+
* @description Fires when light dom child list changes. Injected by MutationObserverController.
|
|
137
|
+
* Sets the 'navItems' property.
|
|
138
|
+
*/
|
|
139
|
+
_onChildListMutation(){
|
|
140
|
+
let navItems = this.parseNavChildren();
|
|
141
|
+
if ( navItems.length ) this.navItems = navItems;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @method _renderNavItem
|
|
146
|
+
* @private
|
|
147
|
+
* @description Renders a menu item and all its children to the specified max depth
|
|
148
|
+
* @param {Object} item - An item from the 'navItems' element property
|
|
149
|
+
* @param {Array} location - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4]
|
|
150
|
+
* @returns {TemplateResult}
|
|
151
|
+
*/
|
|
152
|
+
_renderNavItem(item, location){
|
|
153
|
+
const depth = location.length - 1;
|
|
154
|
+
|
|
155
|
+
if ( this.itemHasSubNav(item) && depth < this.maxDepth) {
|
|
156
|
+
return html`
|
|
157
|
+
<li id="nav--${location.join("-")}">
|
|
158
|
+
<div class="submenu-toggle__wrapper">
|
|
159
|
+
<a href=${ifDefined(item.href ? item.href : null)}>${item.linkText}</a>
|
|
160
|
+
<button
|
|
161
|
+
@click=${() => this._toggleItemMenu(location)}
|
|
162
|
+
class="submenu-toggle ${item.isOpen ? "submenu-toggle--open" : ""}"
|
|
163
|
+
?disabled=${item.isTransitioning}
|
|
164
|
+
aria-label="Toggle Submenu">
|
|
165
|
+
<span class="submenu-toggle__icon"></span>
|
|
166
|
+
</button>
|
|
167
|
+
</div>
|
|
168
|
+
<ul style=${styleMap(item.inlineStyles)} class="${item.isOpen ? "is-open": "" }">
|
|
169
|
+
${item.subItems.map((subItem, i) => this._renderNavItem(subItem, location.concat([i])))}
|
|
170
|
+
</ul>
|
|
171
|
+
</li>
|
|
172
|
+
`;
|
|
173
|
+
}
|
|
174
|
+
return html`
|
|
175
|
+
<li id="nav--${location.join("-")}"><a href=${item.href}>${item.linkText}</a></li>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @method _toggleItemMenu
|
|
181
|
+
* @private
|
|
182
|
+
* @description Attached to nav item button click. Shows/hides children.
|
|
183
|
+
* @param {Array} navLocation - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4]
|
|
184
|
+
*/
|
|
185
|
+
_toggleItemMenu(navLocation){
|
|
186
|
+
let navItem = this.getNavItem(navLocation);
|
|
187
|
+
if ( navItem.isOpen ) {
|
|
188
|
+
this.closeNavItem(navLocation);
|
|
189
|
+
} else {
|
|
190
|
+
this.openNavItem(navLocation);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
customElements.define('ucd-theme-subnav', UcdThemeSubnav);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { html, css } from 'lit';
|
|
2
|
+
|
|
3
|
+
import normalizeStyles from "@ucd-lib/theme-sass/normalize.css.js";
|
|
4
|
+
import headerStyles from "@ucd-lib/theme-sass/1_base_html/_headings.css.js";
|
|
5
|
+
import formStyles from "@ucd-lib/theme-sass/1_base_html/_forms.css.js";
|
|
6
|
+
import menuStyles from "@ucd-lib/theme-sass/2_base_class/_misc.css.js";
|
|
7
|
+
import subNavStyles from "@ucd-lib/theme-sass/4_component/_nav-sub.css.js";
|
|
8
|
+
import subNavToggleStyles from "@ucd-lib/theme-sass/4_component/_submenu-toggle.css.js";
|
|
9
|
+
|
|
10
|
+
export function styles() {
|
|
11
|
+
const elementStyles = css`
|
|
12
|
+
:host {
|
|
13
|
+
display: block;
|
|
14
|
+
}
|
|
15
|
+
ul.sub-nav__menu ul {
|
|
16
|
+
display: none;
|
|
17
|
+
overflow-y: hidden;
|
|
18
|
+
visibility: visible;
|
|
19
|
+
height: auto;
|
|
20
|
+
border-top-width: 0px;
|
|
21
|
+
border-bottom-width: 0px;
|
|
22
|
+
padding-top: 0px;
|
|
23
|
+
padding-bottom: 0px;
|
|
24
|
+
}
|
|
25
|
+
ul.sub-nav__menu ul.is-open {
|
|
26
|
+
display: block;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
normalizeStyles,
|
|
32
|
+
headerStyles,
|
|
33
|
+
formStyles,
|
|
34
|
+
menuStyles,
|
|
35
|
+
subNavStyles,
|
|
36
|
+
subNavToggleStyles,
|
|
37
|
+
elementStyles
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function render() {
|
|
42
|
+
return html`
|
|
43
|
+
<style>
|
|
44
|
+
ul.sub-nav__menu ul {
|
|
45
|
+
transition: height ${this.animationDuration + "ms"};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
</style>
|
|
49
|
+
<nav class="sub-nav">
|
|
50
|
+
${this.navTitle ? html`
|
|
51
|
+
<h2 class="sub-nav__title${this.titleHref ? "-linked" : ""}">
|
|
52
|
+
${this.titleHref ? html`<a href=${this.titleHref}>${this.navTitle}</a>` : this.navTitle}
|
|
53
|
+
</h2>
|
|
54
|
+
` : html``}
|
|
55
|
+
<ul class="sub-nav__menu">
|
|
56
|
+
${this.navItems.map((item, i) => this._renderNavItem(item, [i]))}
|
|
57
|
+
</ul>
|
|
58
|
+
</nav>
|
|
59
|
+
|
|
60
|
+
`;}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucd-lib/theme-elements",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Custom elements for the UCD brand theme",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"author": "jrmerz@ucdavis.edu",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@ucd-lib/theme-sass": "^5.0.
|
|
13
|
-
"lit": "^2.0.
|
|
14
|
-
"photoswipe": "^4.1.3"
|
|
12
|
+
"@ucd-lib/theme-sass": "^5.0.15",
|
|
13
|
+
"lit": "^2.0.2",
|
|
14
|
+
"photoswipe": "^4.1.3",
|
|
15
|
+
"slim-select": "^1.26.2"
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { svg } from "lit";
|
|
2
|
+
export default svg`
|
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 276.31 432.01"><path d="M102.37,337.79,148,325.38c13.66-3.71,24-17.44,24-31.94V121.15l-69.56-11Z" style="fill:#ffbf00"/><path d="M171.94,87.9V0L24.87,31.15C10.69,34.15,0,47.81,0,63v302.7l69.55-18.93v-275Z" style="fill:#ffbf00"/><path d="M250.56,100.25,171.94,87.9v33.26l71.49,11.24V393.6l-141-22.18V337.8l-32.84,8.94v25.48c0,15.3,11.3,29.06,25.72,31.33l181,28.46V131.58C276.27,116.28,265,102.52,250.56,100.25Z" style="fill:#022851"/></svg>
|
|
4
|
+
`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { svg } from "lit";
|
|
2
|
+
export default svg`
|
|
3
|
+
|
|
4
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
5
|
+
viewBox="0 0 1512 436.8" style="enable-background:new 0 0 1512 436.8;" xml:space="preserve">
|
|
6
|
+
<style type="text/css">
|
|
7
|
+
.st0{fill:#DAAA00;}
|
|
8
|
+
.st1{fill:#002855;}
|
|
9
|
+
.st2{fill:none;}
|
|
10
|
+
</style>
|
|
11
|
+
<g>
|
|
12
|
+
<g>
|
|
13
|
+
<g>
|
|
14
|
+
<g>
|
|
15
|
+
<g>
|
|
16
|
+
<g>
|
|
17
|
+
<path class="st0" d="M1369.7,174.7l18.4-48.8l3.2,2.8c11.3,9.2,26.7,17.1,41.2,17.4c13,0.3,19.3-3.2,17.6-14.1
|
|
18
|
+
c-1.3-8.2-10.5-9.6-16.3-10.8l-12.7-2.5c-24.7-4.6-45.4-19.8-45.4-48.7c0-43.6,37.6-68.1,75.4-68.1c19.9,0,38.1,5.1,55.1,16.1
|
|
19
|
+
l-16,43.3c-8.8-6.3-22.1-15.2-38.9-15.8c-5.5-0.2-18.2,2.7-14.1,15.6c1.8,5.5,9.6,7.8,14.4,8.9l14.3,3.4
|
|
20
|
+
c26.7,6.2,46.1,21.5,46.1,52.6c0,43.8-37.8,65.5-75.4,65.5C1414.7,191.5,1389.3,185.3,1369.7,174.7"/>
|
|
21
|
+
<rect x="1291.7" y="4.9" class="st0" width="64.4" height="183.9"/>
|
|
22
|
+
<polygon class="st0" points="1219.1,4.9 1285.1,4.9 1217.8,188.8 1164.2,188.8 1097.1,4.9 1162.8,4.9 1191,115.8 "/>
|
|
23
|
+
<path class="st0" d="M941,188.8h66.9l5.1-23.1h47.7l6.3,23.1h66.9L1071.3,4.9h-70.2L941,188.8z M1036.9,57.9L1036.9,57.9
|
|
24
|
+
c1.2,7.8,12.7,64.1,12.7,64.1h-25.3L1036.9,57.9z"/>
|
|
25
|
+
<path class="st0" d="M840.4,135.9h4.3c21.2,0,37-12.7,37-36.7c0-25.8-13.9-40.3-37.2-40.3h-4V135.9z M775.6,4.9h65.9
|
|
26
|
+
c58.8,0,103.8,27,103.8,94.6c0,54.5-36.7,89.3-88.1,89.3l-81.6-0.1V4.9z"/>
|
|
27
|
+
<path class="st0" d="M737.1,10.6l3.4,30.2c0.8,7.2,4.9,24.4-0.2,22.1c-3.2-1.4-5.8-9.2-8.4-16.1c-1.3-3.5-7.6-20.1-9.2-21.4
|
|
28
|
+
c-7.9-5.9-27.7-12.6-41.1-12.7c-40.5-0.2-67.4,29.8-67.4,82.8c0,38.1,18.2,83.7,64.6,83.7c16.6,0,48.4-5.2,57.1-28.9
|
|
29
|
+
c3.9-10.7,7.5-20.2,10.1-17.3c1.9,2.1-0.6,10.7-1.7,15.3c-5.5,21.9-5.8,28.6-7.5,29.4c-20.9,10.5-47.8,14-71.3,14
|
|
30
|
+
c-74.8,0-100.6-43.6-100.6-87.2C565,28.9,611.5-3,683.6,0.2C701.8,0.9,720,4.2,737.1,10.6"/>
|
|
31
|
+
<path class="st0" d="M516.4,14l-12-4.2c-4-3.6,0.9-4.6,0.9-4.6s17.3,3.2,60.4-0.4c0,0,3.7,0.7,1.2,3.8l-14.1,6
|
|
32
|
+
c-9.2,4-9.2,1.7-9.2,11.8l-0.1,93.7c0,73.3-74.6,71.7-89.1,71.7c-6.9,0-75.3,0-75.3-58.9V33.7c0-17.3,1.8-16.8-3.9-18.9
|
|
33
|
+
l-17.3-6.5c0,0-2.9-4.2,2.3-3.9c14.1,0.7,34.6,3.8,82.7,0.3c0,0,4.2,1,1.4,4l-14.4,4c-11,4.9-9.5,1.2-9.8,12.4l0.3,97.8
|
|
34
|
+
c0,24,12.3,53.7,51.2,53.7c52.8,0,53.3-45.7,53.3-55.9l0.1-96.9C525.6,14.8,524.4,17.4,516.4,14"/>
|
|
35
|
+
</g>
|
|
36
|
+
</g>
|
|
37
|
+
<rect x="379.1" y="229.5" class="st0" width="1132.9" height="7.7"/>
|
|
38
|
+
</g>
|
|
39
|
+
</g>
|
|
40
|
+
</g>
|
|
41
|
+
<g>
|
|
42
|
+
<path class="st1" d="M419,403h48v33.9h-88V282.9h40V403z"/>
|
|
43
|
+
<path class="st1" d="M551.3,436.8h-40V282.9h40V436.8z"/>
|
|
44
|
+
<path class="st1" d="M601.9,436.8V282.9H659c27.4,0,45.7,10.6,45.7,40c0,13.9-4.5,25.1-16.9,31.4v0.4c22,2.9,31.4,17.8,31.4,39.2
|
|
45
|
+
c0,32.3-27.6,42.9-55.7,42.9H601.9z M641.9,343.3h4.5c10.6,0,21.6-1.8,21.6-14.9c0-14.1-12.5-14.9-23.3-14.9h-2.9V343.3z
|
|
46
|
+
M641.9,406.2h5.1c11.8,0,31.8,0.6,31.8-16.3c0-18.6-19.8-16.7-32.9-16.7h-4.1V406.2z"/>
|
|
47
|
+
<path class="st1" d="M886.7,436.8h-49.8l-37.8-59.2h-0.4v59.2h-40V282.9h59.8c30.4,0,53.5,14.5,53.5,47.4
|
|
48
|
+
c0,21.2-11.8,39.6-33.7,43.5L886.7,436.8z M798.7,351.9h3.9c13.1,0,27.8-2.4,27.8-19.2c0-16.7-14.7-19.2-27.8-19.2h-3.9V351.9z"/>
|
|
49
|
+
<path class="st1" d="M951.6,410.1L941,436.8h-42.5l59.2-153.9h43.7l58,153.9h-42.7l-10-26.7H951.6z M979.6,330.5h-0.4l-16.5,49
|
|
50
|
+
h33.3L979.6,330.5z"/>
|
|
51
|
+
<path class="st1" d="M1210.9,436.8h-49.8l-37.8-59.2h-0.4v59.2h-40V282.9h59.8c30.4,0,53.5,14.5,53.5,47.4
|
|
52
|
+
c0,21.2-11.8,39.6-33.7,43.5L1210.9,436.8z M1122.9,351.9h3.9c13.1,0,27.8-2.4,27.8-19.2c0-16.7-14.7-19.2-27.8-19.2h-3.9V351.9z"
|
|
53
|
+
/>
|
|
54
|
+
<path class="st1" d="M1216.4,282.9h48l28.8,41.8l28.8-41.8h48l-56.8,80v73.9h-40v-73.9L1216.4,282.9z"/>
|
|
55
|
+
</g>
|
|
56
|
+
</g>
|
|
57
|
+
<g>
|
|
58
|
+
<path class="st2" d="M148,330.2l-45.6,12.4v33.6l141,22.2V137.2L171.9,126v172.3C171.9,312.8,161.6,326.5,148,330.2z"/>
|
|
59
|
+
<path class="st0" d="M102.4,342.6l45.6-12.4c13.7-3.7,24-17.4,24-31.9V126L102.4,115V342.6z"/>
|
|
60
|
+
<path class="st0" d="M171.9,92.7V4.8L24.9,36C10.7,39,0,52.7,0,67.8v302.7l69.6-18.9V76.6L171.9,92.7z"/>
|
|
61
|
+
<path class="st1" d="M250.6,105.1l-78.6-12.4V126l71.5,11.2v261.2l-141-22.2v-33.6l-32.8,8.9v25.5c0,15.3,11.3,29.1,25.7,31.3
|
|
62
|
+
l181,28.5V136.4C276.3,121.1,265,107.4,250.6,105.1z"/>
|
|
63
|
+
</g>
|
|
64
|
+
<rect class="st2" width="1512" height="436.8"/>
|
|
65
|
+
<rect class="st2" width="1512" height="436.8"/>
|
|
66
|
+
</svg>
|
|
67
|
+
`;
|