@ucd-lib/theme-elements 0.0.11 → 0.0.14

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.
@@ -55,6 +55,22 @@ export default class UcdThemeBrandTextbox extends LitElement {
55
55
  return out;
56
56
  }
57
57
 
58
+ /**
59
+ * @method _onSlotchange
60
+ * @param {Event} e
61
+ * @description fires when a slot value changes.
62
+ * assigns category-brand__background class so that slotted children are correct color
63
+ * @private
64
+ */
65
+ _onSlotchange(e){
66
+ const childNodes = e.target.assignedNodes({flatten: true});
67
+ childNodes.forEach(child => {
68
+ if ( child.nodeType === Node.ELEMENT_NODE ){
69
+ child.classList.add('category-brand__background');
70
+ }
71
+ });
72
+ }
73
+
58
74
  }
59
75
 
60
76
  customElements.define('ucd-theme-brand-textbox', UcdThemeBrandTextbox);
@@ -17,6 +17,12 @@ export function styles() {
17
17
  .brand-textbox--collapsible .brand-textbox__button {
18
18
  display: block;
19
19
  }
20
+ ::slotted(*:last-child) {
21
+ margin-bottom: 0 !important;
22
+ }
23
+ ::slotted(blockquote) {
24
+ --category-brand-contrast-color: #fff !important;
25
+ }
20
26
  `;
21
27
 
22
28
  return [
@@ -29,7 +35,7 @@ export function render() {
29
35
  return html`
30
36
  <section class=${classMap(this._getBaseClasses())}>
31
37
  <div class="brand-textbox__content">
32
- <slot></slot>
38
+ <slot @slotchange=${this._onSlotchange}></slot>
33
39
  </div>
34
40
  <button
35
41
  class="brand-textbox__button"
@@ -17,6 +17,7 @@ import { MutationObserverController, WaitController } from '../../utils/controll
17
17
  *
18
18
  * @property {String} navTitle - Subnav header text
19
19
  * @property {String} titleHref - Link for subnav header (optional)
20
+ * @property {Boolean} titleClickEvent - If navTitle, will fire an event when clicked.
20
21
  *
21
22
  * @example
22
23
  * <ucd-theme-subnav nav-title="A subnav">
@@ -36,6 +37,7 @@ export default class UcdThemeSubnav extends Mixin(LitElement)
36
37
  return {
37
38
  navTitle: {type: String, attribute: "nav-title"},
38
39
  titleHref: {type: String, attribute: "title-href"},
40
+ titleClickEvent: {type: Boolean, attribute: 'title-click-event'},
39
41
  navItems: {type: Array},
40
42
  animationDuration: {type: Number, attribute: "animation-duration"}
41
43
  };
@@ -53,6 +55,7 @@ export default class UcdThemeSubnav extends Mixin(LitElement)
53
55
 
54
56
  this.navTitle = "";
55
57
  this.titleHref = "";
58
+ this.titleClickEvent = false;
56
59
  this.animationDuration = 300;
57
60
  }
58
61
 
@@ -140,6 +143,41 @@ export default class UcdThemeSubnav extends Mixin(LitElement)
140
143
  if ( navItems.length ) this.navItems = navItems;
141
144
  }
142
145
 
146
+ /**
147
+ * @method _dispatchItemClick
148
+ * @private
149
+ * @description Fires an 'item-click' event
150
+ * @param {Object} item - The link item
151
+ * @param {Array} location - The link location in links array
152
+ * @returns
153
+ */
154
+ _dispatchItemClick(item, location){
155
+ if (item.href) return;
156
+ const options = {
157
+ detail: {
158
+ linkText: item.linkText,
159
+ location
160
+ },
161
+ bubbles: true,
162
+ composed: true,
163
+ };
164
+ this.dispatchEvent(new CustomEvent('item-click', options));
165
+ }
166
+
167
+ /**
168
+ * @method _dispatchTitleClick
169
+ * @private
170
+ * @description fires a 'title-click' ecent
171
+ */
172
+ _dispatchTitleClick(){
173
+ if ( !this.titleClickEvent ) return;
174
+ const options = {
175
+ bubbles: true,
176
+ composed: true,
177
+ };
178
+ this.dispatchEvent(new CustomEvent('title-click', options));
179
+ }
180
+
143
181
  /**
144
182
  * @method _renderNavItem
145
183
  * @private
@@ -155,7 +193,7 @@ export default class UcdThemeSubnav extends Mixin(LitElement)
155
193
  return html`
156
194
  <li id="nav--${location.join("-")}">
157
195
  <div class="submenu-toggle__wrapper">
158
- <a href=${ifDefined(item.href ? item.href : null)}>${item.linkText}</a>
196
+ <a href=${ifDefined(item.href ? item.href : undefined)} @click=${() => this._dispatchItemClick(item, location)}>${item.linkText}</a>
159
197
  <button
160
198
  @click=${() => this._toggleItemMenu(location)}
161
199
  class="submenu-toggle ${item.isOpen ? "submenu-toggle--open" : ""}"
@@ -171,7 +209,7 @@ export default class UcdThemeSubnav extends Mixin(LitElement)
171
209
  `;
172
210
  }
173
211
  return html`
174
- <li id="nav--${location.join("-")}"><a href=${item.href}>${item.linkText}</a></li>
212
+ <li id="nav--${location.join("-")}"><a href=${ifDefined(item.href ? item.href : undefined)} @click=${() => this._dispatchItemClick(item, location)}>${item.linkText}</a></li>
175
213
  `;
176
214
  }
177
215
 
@@ -1,4 +1,5 @@
1
1
  import { html, css } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
2
3
 
3
4
  import normalizeStyles from "@ucd-lib/theme-sass/normalize.css.js";
4
5
  import headerStyles from "@ucd-lib/theme-sass/1_base_html/_headings.css.js";
@@ -25,6 +26,9 @@ export function styles() {
25
26
  ul.sub-nav__menu ul.is-open {
26
27
  display: block;
27
28
  }
29
+ a {
30
+ cursor: pointer;
31
+ }
28
32
  `;
29
33
 
30
34
  return [
@@ -48,8 +52,8 @@ export function render() {
48
52
  </style>
49
53
  <nav class="sub-nav">
50
54
  ${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}
55
+ <h2 class="sub-nav__title${this.titleHref || this.titleClickEvent ? "-linked" : ""}">
56
+ ${this.titleHref || this.titleClickEvent ? html`<a href=${ifDefined(this.titleHref ? this.titleHref : undefined)} @click=${() => this._dispatchTitleClick()}>${this.navTitle}</a>` : this.navTitle}
53
57
  </h2>
54
58
  ` : html``}
55
59
  <ul class="sub-nav__menu">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucd-lib/theme-elements",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "Custom elements for the UCD brand theme",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -44,17 +44,19 @@ export default class UcdlibIcon extends LitElement {
44
44
  * @private
45
45
  */
46
46
  disconnectedCallback() {
47
- window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
47
+ if ( this._setListener ){
48
+ window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
49
+ }
48
50
  super.disconnectedCallback();
49
51
  }
50
52
 
51
53
  /**
52
- * @method updated
53
- * @description Lit lifecyle method called after element updates
54
+ * @method willUpdate
55
+ * @description Lit lifecyle method called right before element updates
54
56
  * @param {Map} props - Updated properties
55
57
  * @private
56
58
  */
57
- updated(props){
59
+ willUpdate(props){
58
60
  if ( props.has('icon') || props.has('src') ){
59
61
  if ( this.src ) {
60
62
  this._updateIcon();
@@ -85,17 +87,27 @@ export default class UcdlibIcon extends LitElement {
85
87
  _updateIcon(){
86
88
  // using the icon attribute
87
89
  if ( this._usesIconSet() ) {
90
+
91
+ // previously using the src attribute. remove it.
88
92
  if ( this._img && this._img.parentNode ) this.renderRoot.removeChild(this._img);
89
93
 
94
+ // empty icon name, remove it
90
95
  if ( this._iconName === '') {
91
96
  if ( this._iconset ) this._iconset.removeIcon(this);
97
+
98
+ // check if iconset exists, add event listener if it doesn't
92
99
  } else if ( this._iconsetName ){
93
100
  this._iconset = this._getIconset();
94
- if ( this._iconset ) {
101
+ if ( this._iconset && this._iconset.applyIcon ) {
95
102
  this._iconset.applyIcon(this, this._iconName);
96
- window.addEventListener('ucdlib-iconset-added', this._onAddedIconset);
103
+ if ( this._setListener ){
104
+ window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
105
+ this._setListener = false;
106
+ }
97
107
  } else {
98
- window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
108
+ if ( !this._setListener ){
109
+ this._setListener = window.addEventListener('ucdlib-iconset-added', this._onAddedIconset);
110
+ }
99
111
  }
100
112
  }
101
113
 
@@ -10,6 +10,7 @@ import { MutationObserverController } from '../../utils/controllers';
10
10
  * @property {String} name - Name of the icon set. Usage: <ucdlib-icon icon="{thisProperty}:{icon}"></ucdlib-icon>
11
11
  * @property {Number} size - The size of an individual icon. Note that icons must be square.
12
12
  * @property {String} label - Optional friendly label for iconset.
13
+ * @property {String} suppressWarnings - Suppress any "you're doing it wrong" console warnings
13
14
  * @example
14
15
  * <ucdlib-iconset name="arrows">
15
16
  <svg>
@@ -28,6 +29,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
28
29
  name: {type: String},
29
30
  size: {type: Number},
30
31
  label: {type: String},
32
+ suppressWarnings: {type: Boolean, attribute: 'suppress-warnings'},
31
33
  _iconMap: {type: Object, state: true}
32
34
  };
33
35
  }
@@ -40,7 +42,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
40
42
  this.label = "";
41
43
  this.size = 24;
42
44
  this._iconMap = {};
43
- this.style.display = "none";
45
+ this.suppressWarnings = false;
44
46
  }
45
47
 
46
48
  /**
@@ -51,12 +53,28 @@ export default class UcdlibIconset extends Mixin(LitElement)
51
53
  */
52
54
  updated( props ){
53
55
  if (props.has('name') && this.name ) {
54
- this.dispatchEvent(
55
- new CustomEvent('ucdlib-iconset-added', {bubbles: true, composed: true})
56
- );
56
+ this.dispatchLoadEvent();
57
57
  }
58
58
  }
59
59
 
60
+ /**
61
+ * @method firstUpdated
62
+ * @description Lit lifecycle method when element is first updated
63
+ */
64
+ firstUpdated(){
65
+ this.style.display = "none";
66
+ }
67
+
68
+ /**
69
+ * @method dispatchLoadEvent
70
+ * @description fires off a 'ucdlib-iconset-added' event so ucdlib-icon elements can re-render if applicable
71
+ */
72
+ dispatchLoadEvent(){
73
+ this.dispatchEvent(
74
+ new CustomEvent('ucdlib-iconset-added', {bubbles: true, composed: true})
75
+ );
76
+ }
77
+
60
78
  /**
61
79
  * @method getIconNames
62
80
  * @description Returns a list of icon names for this set
@@ -173,7 +191,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
173
191
  iconMap[icon.id] = icon;
174
192
  });
175
193
 
176
- if ( !Object.keys(iconMap).length ) {
194
+ if ( !Object.keys(iconMap).length && !this.suppressWarnings ) {
177
195
  console.warn('No g elements with an id attribute found!.');
178
196
  }
179
197
  this._iconMap = iconMap;