@ucd-lib/theme-elements 1.2.9 → 2.1.0

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.
@@ -6,7 +6,7 @@ import { MutationObserverController, WaitController } from '../../utils/controll
6
6
  /**
7
7
  * @class UcdThemeQuickLinks
8
8
  * @classdesc Component class for displaying a quick links nav
9
- *
9
+ *
10
10
  * Patternlab Url:
11
11
  * - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-quick-links
12
12
  * - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-quick-links-2-columns
@@ -16,6 +16,7 @@ import { MutationObserverController, WaitController } from '../../utils/controll
16
16
  * @property {String} styleModifiers - Apply alternate styles with a space-separated list.
17
17
  * @property {Boolean} opened - Menu is open
18
18
  * @property {Number} animationDuration - Length of animation when opening/closing menu
19
+ * @property {Boolean} useIcon - Show a custom icon next to the title
19
20
  */
20
21
  export default class UcdThemeQuickLinks extends LitElement {
21
22
 
@@ -25,6 +26,7 @@ export default class UcdThemeQuickLinks extends LitElement {
25
26
  styleModifiers: {type: String, attribute: "style-modifiers"},
26
27
  opened: {type: Boolean},
27
28
  animationDuration: {type: Number, attribute: "animation-duration"},
29
+ useIcon: {type: Boolean, attribute: "use-icon"},
28
30
  _links: {type: Array, state: true},
29
31
  _hasCustomIcons: {type: Boolean, state: true},
30
32
  _transitioning: {type: Boolean, state: true},
@@ -46,6 +48,7 @@ export default class UcdThemeQuickLinks extends LitElement {
46
48
  this.styleModifiers = "";
47
49
  this.opened = false;
48
50
  this.animationDuration = 300;
51
+ this.useIcon = false;
49
52
 
50
53
  this._links = [];
51
54
  this._classPrefix = "quick-links";
@@ -102,7 +105,7 @@ export default class UcdThemeQuickLinks extends LitElement {
102
105
  */
103
106
  ingestChildren(){
104
107
  // remove any slotted icons created from a previous render
105
- this.querySelectorAll('[slot]').forEach(ele => ele.remove());
108
+ this.querySelectorAll('slot:not([name="custom-icon"])').forEach(ele => ele.remove());
106
109
  this._hasCustomIcons = false;
107
110
 
108
111
  let links = [];
@@ -111,8 +114,8 @@ export default class UcdThemeQuickLinks extends LitElement {
111
114
  let link = {};
112
115
 
113
116
  // if first child exists, we assume it is an icon
114
- if (
115
- child.childElementCount > 0 &&
117
+ if (
118
+ child.childElementCount > 0 &&
116
119
  index < 3 &&
117
120
  child.children[0].tagName !== 'A'
118
121
  ){
@@ -157,7 +160,7 @@ export default class UcdThemeQuickLinks extends LitElement {
157
160
  * @method _onItemClick
158
161
  * @private
159
162
  * @description Attached to menu item links without an href
160
- * @param {Event} e
163
+ * @param {Event} e
161
164
  */
162
165
  _onItemClick(e){
163
166
  this._dispatchItemClick(e.target.index);
@@ -167,7 +170,7 @@ export default class UcdThemeQuickLinks extends LitElement {
167
170
  * @method _onItemKeyup
168
171
  * @private
169
172
  * @description Attached to menu item links without an href
170
- * @param {Event} e
173
+ * @param {Event} e
171
174
  */
172
175
  _onItemKeyup(e){
173
176
  if( e.which !== 13 ) return;
@@ -199,7 +202,7 @@ export default class UcdThemeQuickLinks extends LitElement {
199
202
  _getNavClasses(){
200
203
  let classes = {};
201
204
  classes[`${this._classPrefix}__menu`] = true;
202
-
205
+
203
206
  if ( this.styleModifiers ) {
204
207
  this.styleModifiers.split(" ").forEach(mod => {
205
208
  if (mod) classes[`${this._classPrefix}--${mod}`] = true;
@@ -265,4 +268,4 @@ export default class UcdThemeQuickLinks extends LitElement {
265
268
 
266
269
  }
267
270
 
268
- customElements.define('ucd-theme-quick-links', UcdThemeQuickLinks);
271
+ customElements.define('ucd-theme-quick-links', UcdThemeQuickLinks);
@@ -13,6 +13,9 @@ export function styles() {
13
13
  :host {
14
14
  display: block;
15
15
  }
16
+ [hidden] {
17
+ display: none !important;
18
+ }
16
19
  .slot-parent {
17
20
  display: none;
18
21
  }
@@ -43,8 +46,44 @@ export function styles() {
43
46
  margin-right: .75rem;
44
47
  color: #13639e;
45
48
  font-size: .875em;
49
+ }
50
+
51
+ .quick-links__title.show-icon:after {
52
+ content: "";
53
+ }
54
+
55
+ .quick-links__title.show-icon .custom-icon {
56
+ display: flex;
57
+ align-items: center;
58
+ flex-wrap: wrap;
59
+ overflow: hidden;
60
+ width: 2.4375rem;
61
+ height: 2.4375rem;
62
+ padding: 0px;
63
+ border: 0px;
64
+ border-radius: 50%;
65
+ background-color: #ffbf00;
66
+ background-size: 50%;
67
+ color: rgb(255, 255, 255);
68
+ text-indent: inherit;
69
+ margin-left: .75rem;
70
+ }
71
+
72
+ .quick-links__title.show-icon .custom-icon ::slotted(svg) {
73
+ fill: white;
74
+ height: 65%;
75
+ width: 65%;
76
+ margin: 0 auto;
77
+ }
78
+
79
+ .quick-links__title.show-icon:hover .custom-icon, .quick-links__title.show-icon:focus .custom-icon {
80
+ background-color: #13639e;
81
+ }
82
+
83
+ .quick-links__title.show-icon {
84
+ padding-right: 0;
85
+ }
46
86
  }
47
- }
48
87
  `;
49
88
 
50
89
  return [
@@ -57,7 +96,7 @@ export function styles() {
57
96
  ];
58
97
  }
59
98
 
60
- export function render() {
99
+ export function render() {
61
100
  return html`
62
101
  ${this._hasCustomIcons ? html`
63
102
  <style>
@@ -81,17 +120,20 @@ return html`
81
120
  }
82
121
  </style>
83
122
  <div class="quick-links">
84
- <button
85
- class="quick-links__title"
123
+ <button
124
+ class="quick-links__title ${this.useIcon ? 'show-icon' : ''}"
86
125
  @click=${this._onBtnClick}
87
- aria-controls="quick-links"
88
- aria-expanded="${this.opened}"
126
+ aria-controls="quick-links"
127
+ aria-expanded="${this.opened}"
89
128
  aria-label="Toggle ${this.title} Menu">
90
129
  ${this.title}<span class="submenu-toggle ${this.opened ? 'submenu-toggle--open' : ''}"><span class="submenu-toggle__icon">+</span></span>
130
+ <div class="custom-icon" ?hidden="${!this.useIcon}">
131
+ <slot name="custom-icon"></slot>
132
+ </div>
91
133
  </button>
92
- <nav
93
- id="quick-links"
94
- class=${classMap(this._getNavClasses())}
134
+ <nav
135
+ id="quick-links"
136
+ class=${classMap(this._getNavClasses())}
95
137
  style=${styleMap(this._getNavStyles())}
96
138
  aria-label="Quick Links Menu">
97
139
  <ul class="menu" id="menu">
@@ -100,8 +142,8 @@ return html`
100
142
  ${link.href ? html`
101
143
  <a href="${link.href}">${this._renderSlot(link)}${link.text}</a>
102
144
  ` : html`
103
- <a
104
- class="click-attached"
145
+ <a
146
+ class="click-attached"
105
147
  tabindex="0"
106
148
  @click=${this._onItemClick}
107
149
  @keyup=${this._onItemKeyup}
@@ -111,7 +153,7 @@ return html`
111
153
  `)}
112
154
  </ul>
113
155
  </nav>
114
-
156
+
115
157
  </div>
116
158
 
117
- `;}
159
+ `;}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucd-lib/theme-elements",
3
- "version": "1.2.9",
3
+ "version": "2.1.0",
4
4
  "description": "Custom elements for the UCD brand theme",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,10 +10,10 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@lit-labs/task": "^1.0.0",
13
- "@ucd-lib/theme-sass": "^5.0.15",
13
+ "@ucd-lib/theme-sass": "^6.0.1",
14
14
  "dompurify": "^2.3.9",
15
15
  "ip-cidr": "^3.0.4",
16
- "lit": "^2.0.2",
16
+ "lit": "^3.0.2",
17
17
  "marked": "^4.0.18",
18
18
  "photoswipe": "^4.1.3",
19
19
  "slim-select": "^1.26.2"
@@ -1,6 +1,7 @@
1
1
  import { BreakPointsController } from "./break-points";
2
2
  import { IntersectionObserverController } from "./intersection-observer";
3
3
  import { MutationObserverController } from "./mutation-observer";
4
+ import { PageWidthController } from "./page-width";
4
5
  import { PopStateObserverController } from "./popstate-observer";
5
6
  import { SilsPrimoController } from "./sils-primo";
6
7
  import { WaitController } from "./wait";
@@ -10,7 +11,8 @@ export {
10
11
  BreakPointsController,
11
12
  IntersectionObserverController,
12
13
  MutationObserverController,
14
+ PageWidthController,
13
15
  PopStateObserverController,
14
16
  SilsPrimoController,
15
17
  WaitController,
16
- };
18
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @class PageWidthController
3
+ * @description Sets the page width as a CSS variable (--page-width), which is needed for some layout classes.
4
+ *
5
+ * @example
6
+ * const pageWidthController = new PageWidthController();
7
+ * pageWidthController.init();
8
+ */
9
+ export class PageWidthController {
10
+
11
+ constructor(){
12
+ this.documentRoot = document.documentElement;
13
+ this.propertyName = '--page-width';
14
+ this.fullWidthPropertyName = '--full-width';
15
+ }
16
+
17
+ /**
18
+ * @description Initialize the controller.
19
+ * @returns
20
+ */
21
+ init(){
22
+ if ( this.isInitialized() ) {
23
+ return;
24
+ }
25
+
26
+ // set initial state
27
+ this.setPageWidthProperty();
28
+ this.setFullWidthProperty();
29
+
30
+ // set up resize listener
31
+ this.resizeListener = window.addEventListener('resize', () => {
32
+ this.setPageWidthProperty();
33
+ });
34
+
35
+ }
36
+
37
+ /**
38
+ * @description Check if the controller has been initialized.
39
+ * @returns {Boolean}
40
+ */
41
+ isInitialized(){
42
+ return this.resizeListener !== undefined;
43
+ }
44
+
45
+ /**
46
+ * @description Destroy the controller.
47
+ */
48
+ destroy(){
49
+ window.removeEventListener('resize', this.resizeListener);
50
+ this.documentRoot.style.removeProperty(this.propertyName);
51
+ this.documentRoot.style.removeProperty(this.fullWidthPropertyName);
52
+ this.resizeListener = undefined;
53
+ }
54
+
55
+ /**
56
+ * @description Get the '--page-width' CSS variable from document root.
57
+ * @returns {String}
58
+ */
59
+ getPageWidthProperty(){
60
+ return this.documentRoot.style.getPropertyValue(this.propertyName);
61
+ }
62
+
63
+ /**
64
+ * @description Set the '--page-width' CSS variable on document root.
65
+ */
66
+ setPageWidthProperty(){
67
+ this.documentRoot.style.setProperty(this.propertyName, `${this.documentRoot.clientWidth}px`);
68
+ }
69
+
70
+ /**
71
+ * @description Set the '--full-width' CSS variable on document root.
72
+ */
73
+ setFullWidthProperty(){
74
+ const value = 'min(var(--page-width, 100vw), 100vw)';
75
+ this.documentRoot.style.setProperty(this.fullWidthPropertyName, value);
76
+ }
77
+
78
+ }