@ucd-lib/theme-elements 1.2.8 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucd-lib/theme-elements",
3
- "version": "1.2.8",
3
+ "version": "2.0.1",
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"
@@ -9,12 +9,13 @@ import bookLogo from "./book.js";
9
9
  /**
10
10
  * @class UcdlibBrandingBar
11
11
  * @classdesc Component class for displaying a Library branding bar in a header
12
- *
13
- * @property {String} figure - Figure to display: 'book' or 'logo'
12
+ *
13
+ * @property {String} figure - Figure to display: 'book', 'logo', or 'custom'
14
+ * @property {String} figureSrc - Url of image to use for custom figure
14
15
  * @property {String} siteName - Name of website to display
15
16
  * @property {String} slogan - Optional text to display below site name
16
17
  * @property {String} siteUrl - Url to use for links around site name and figure
17
- *
18
+ *
18
19
  * @examples
19
20
  * <ucdlib-branding-bar>
20
21
  * <a href="#">My Account</a>
@@ -28,7 +29,8 @@ export default class UcdlibBrandingBar extends Mixin(LitElement)
28
29
  static get properties() {
29
30
  return {
30
31
  figure: {type: String},
31
- figureUrl: {type: String, attribute: "figure-url"},
32
+ figureSrc: {type: String, attribute: "figure-src"},
33
+ figureCustomWidth: {type: String, attribute: "figure-custom-width"},
32
34
  siteName: {type: String, attribute: "site-name"},
33
35
  slogan: {type: String},
34
36
  siteUrl: {type: String, attribute: "site-url"},
@@ -49,6 +51,8 @@ export default class UcdlibBrandingBar extends Mixin(LitElement)
49
51
  );
50
52
 
51
53
  this.figure = "book";
54
+ this.figureSrc = '';
55
+ this.figureCustomWidth = '150px';
52
56
  this.siteName = "UC Davis Library";
53
57
  this.slogan = "";
54
58
  this.siteUrl = "/";
@@ -81,7 +85,7 @@ export default class UcdlibBrandingBar extends Mixin(LitElement)
81
85
  */
82
86
  _renderFigure(){
83
87
  if( this.figure === 'custom' ) {
84
- return html`<img src="${this.figureUrl}" />`;
88
+ return html`<img src="${this.figureSrc}" />`;
85
89
  }
86
90
  if ( this.figure === 'logo') return logo;
87
91
  if ( this.figure === 'book' ) return bookLogo;
@@ -106,4 +110,4 @@ export default class UcdlibBrandingBar extends Mixin(LitElement)
106
110
 
107
111
  }
108
112
 
109
- customElements.define('ucdlib-branding-bar', UcdlibBrandingBar);
113
+ customElements.define('ucdlib-branding-bar', UcdlibBrandingBar);
@@ -27,10 +27,6 @@ export function styles() {
27
27
  width: 70px;
28
28
  min-width: 70px;
29
29
  }
30
- .figure--custom img {
31
- width: 150px;
32
- min-width: 150px;
33
- }
34
30
  .figure--logo svg {
35
31
  width: 375px;
36
32
  min-width: 375px;
@@ -66,7 +62,7 @@ export function styles() {
66
62
  display: none;
67
63
  }
68
64
  }
69
-
65
+
70
66
  `;
71
67
 
72
68
  return [
@@ -76,8 +72,14 @@ export function styles() {
76
72
  elementStyles];
77
73
  }
78
74
 
79
- export function render() {
75
+ export function render() {
80
76
  return html`
77
+ <style>
78
+ .figure--custom img {
79
+ width: ${this.figureCustomWidth};
80
+ min-width: ${this.figureCustomWidth};
81
+ }
82
+ </style>
81
83
  <div class="container figure--${this.figure}">
82
84
  <div class="site-branding">
83
85
  <div class="site-branding__figure">
@@ -93,7 +95,7 @@ return html`
93
95
  ${this.navItems.length ? html`
94
96
  <nav class="menu">
95
97
  ${this.navItems.map(link => html`
96
- <a
98
+ <a
97
99
  href=${ifDefined(link.href ? link.href : null)}
98
100
  target=${ifDefined(link.newTab ? "_blank": null)}
99
101
  >${link.linkText}</a>
@@ -103,4 +105,4 @@ return html`
103
105
 
104
106
  </div>
105
107
 
106
- `;}
108
+ `;}
@@ -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
+ }