@ucd-lib/theme-elements 0.0.10 → 0.0.13
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.
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import {render, styles} from "./ucd-theme-brand-textbox.tpl.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @class UcdThemeBrandTextbox
|
|
6
|
+
* @classdesc Component class for displaying a collapsible content in a colored box
|
|
7
|
+
* Pattern Lab Url:
|
|
8
|
+
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=organisms-branding-textbox-collapse
|
|
9
|
+
* @property {String} brandColor - A UCD brand color slug
|
|
10
|
+
* @property {Boolean} collapsible - Content can be collapsed/expanded
|
|
11
|
+
* @property {Boolean} collapsed - Content is collapsed
|
|
12
|
+
*
|
|
13
|
+
* @examples
|
|
14
|
+
* <ucd-theme-brand-textbox collapsible brand-color="primary">
|
|
15
|
+
* <p>hello world!</p>
|
|
16
|
+
* </ucd-theme-brand-textbox>
|
|
17
|
+
*/
|
|
18
|
+
export default class UcdThemeBrandTextbox extends LitElement {
|
|
19
|
+
|
|
20
|
+
static get properties() {
|
|
21
|
+
return {
|
|
22
|
+
brandColor: {type: String, attribute: 'brand-color'},
|
|
23
|
+
collapsible: {type: Boolean},
|
|
24
|
+
collapsed: {type: Boolean, reflect: true}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static get styles() {
|
|
29
|
+
return styles();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this.collapsible = false;
|
|
35
|
+
this.collapsed = false;
|
|
36
|
+
this.brandColor = "";
|
|
37
|
+
this.render = render.bind(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @method _getBaseClasses
|
|
42
|
+
* @description Returns CSS classes for this element's first child
|
|
43
|
+
* @private
|
|
44
|
+
* @returns {Object}
|
|
45
|
+
*/
|
|
46
|
+
_getBaseClasses(){
|
|
47
|
+
const out = {
|
|
48
|
+
"brand-textbox": true,
|
|
49
|
+
"category-brand__background": true,
|
|
50
|
+
};
|
|
51
|
+
out[`category-brand--${this.brandColor}`] = this.brandColor;
|
|
52
|
+
out['brand-textbox--collapsible'] = this.collapsible;
|
|
53
|
+
out['brand-textbox--closed'] = this.collapsible && this.collapsed;
|
|
54
|
+
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
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
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
customElements.define('ucd-theme-brand-textbox', UcdThemeBrandTextbox);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { html, css } from 'lit';
|
|
2
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
3
|
+
import brandStyles from "@ucd-lib/theme-sass/4_component/_category-brand.css.js"
|
|
4
|
+
import textBoxStyles from "@ucd-lib/theme-sass/4_component/_brand-textbox.css.js"
|
|
5
|
+
|
|
6
|
+
export function styles() {
|
|
7
|
+
const elementStyles = css`
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
}
|
|
11
|
+
*, ::before, ::after {
|
|
12
|
+
box-sizing: inherit;
|
|
13
|
+
}
|
|
14
|
+
.brand-textbox__button{
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
.brand-textbox--collapsible .brand-textbox__button {
|
|
18
|
+
display: block;
|
|
19
|
+
}
|
|
20
|
+
::slotted(*:last-child) {
|
|
21
|
+
margin-bottom: 0 !important;
|
|
22
|
+
}
|
|
23
|
+
::slotted(blockquote) {
|
|
24
|
+
--category-brand-contrast-color: #fff !important;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
return [
|
|
29
|
+
brandStyles,
|
|
30
|
+
textBoxStyles,
|
|
31
|
+
elementStyles];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function render() {
|
|
35
|
+
return html`
|
|
36
|
+
<section class=${classMap(this._getBaseClasses())}>
|
|
37
|
+
<div class="brand-textbox__content">
|
|
38
|
+
<slot @slotchange=${this._onSlotchange}></slot>
|
|
39
|
+
</div>
|
|
40
|
+
<button
|
|
41
|
+
class="brand-textbox__button"
|
|
42
|
+
@click=${() => this.collapsed = !this.collapsed}
|
|
43
|
+
title="Open/Close Message">Toggle this message area open and closed.</button>
|
|
44
|
+
</section>
|
|
45
|
+
|
|
46
|
+
`;}
|
|
@@ -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 :
|
|
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">
|