@ucd-lib/theme-elements 0.0.1 → 0.0.5
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/{ucd-theme-alert → brand/ucd-theme-alert}/ucd-theme-alert.js +0 -0
- package/{ucd-theme-alert → brand/ucd-theme-alert}/ucd-theme-alert.tpl.js +0 -0
- package/{ucd-theme-collapse → brand/ucd-theme-collapse}/ucd-theme-collapse.js +20 -21
- package/{ucd-theme-collapse → brand/ucd-theme-collapse}/ucd-theme-collapse.tpl.js +1 -1
- package/brand/ucd-theme-header/ucd-theme-header.js +268 -0
- package/brand/ucd-theme-header/ucd-theme-header.tpl.js +146 -0
- package/{ucd-theme-image-gallery → brand/ucd-theme-image-gallery}/ucd-theme-image-gallery.js +0 -0
- package/{ucd-theme-image-gallery → brand/ucd-theme-image-gallery}/ucd-theme-image-gallery.tpl.js +0 -0
- package/{ucd-theme-list-accordion → brand/ucd-theme-list-accordion}/ucd-theme-list-accordion.js +47 -44
- package/{ucd-theme-list-accordion → brand/ucd-theme-list-accordion}/ucd-theme-list-accordion.tpl.js +2 -2
- package/{ucd-theme-message-area → brand/ucd-theme-message-area}/ucd-theme-message-area.js +0 -0
- package/{ucd-theme-message-area → brand/ucd-theme-message-area}/ucd-theme-message-area.tpl.js +0 -0
- package/brand/ucd-theme-pagination/ucd-theme-pagination.js +284 -0
- package/brand/ucd-theme-pagination/ucd-theme-pagination.tpl.js +93 -0
- package/brand/ucd-theme-primary-nav/ucd-theme-primary-nav.js +589 -0
- package/brand/ucd-theme-primary-nav/ucd-theme-primary-nav.tpl.js +106 -0
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.js +269 -0
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.tpl.js +114 -0
- package/{ucd-theme-form-search/ucd-theme-form-search.js → brand/ucd-theme-search-form/ucd-theme-search-form.js} +14 -15
- package/{ucd-theme-form-search/ucd-theme-form-search.tpl.js → brand/ucd-theme-search-form/ucd-theme-search-form.tpl.js} +0 -0
- package/brand/ucd-theme-search-popup/ucd-theme-search-popup.js +91 -0
- package/{ucd-theme-header-search-popup/ucd-theme-header-search-popup.tpl.js → brand/ucd-theme-search-popup/ucd-theme-search-popup.tpl.js} +8 -1
- package/brand/ucd-theme-slim-select/ucd-theme-slim-select.js +58 -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 +6 -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.js +138 -0
- package/ucdlib/ucdlib-icon/ucdlib-icon.tpl.js +22 -0
- package/ucdlib/ucdlib-icons/academic.js +154 -0
- package/ucdlib/ucdlib-icons/ucdlib-icons.js +78 -0
- package/ucdlib/ucdlib-icons/utils.js +29 -0
- package/ucdlib/ucdlib-iconset/ucdlib-iconset.js +170 -0
- package/ucdlib/ucdlib-pages/ucdlib-pages.js +150 -0
- package/utils/controllers/break-points.js +26 -0
- 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/directives/motion-collapse.js +1 -1
- package/utils/mixins/index.js +8 -0
- package/utils/mixins/main-dom-element.js +23 -0
- package/utils/mixins/mixin.js +21 -0
- package/utils/mixins/nav-element.js +103 -0
- package/ucd-theme-header-search-popup/ucd-theme-header-search-popup.js +0 -40
package/{ucd-theme-list-accordion → brand/ucd-theme-list-accordion}/ucd-theme-list-accordion.js
RENAMED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import {render, styles} from
|
|
2
|
+
import { render, styles } from './ucd-theme-list-accordion.tpl.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @class UcdThemeListAccordion
|
|
6
6
|
* @classdesc Component class for displaying lists with accordion collapse/expand functionality.
|
|
7
|
-
* Pattern Lab Url:
|
|
7
|
+
* Pattern Lab Url:
|
|
8
8
|
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=atoms-list-accordion
|
|
9
9
|
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=atoms-list-faq
|
|
10
|
-
*
|
|
11
|
-
* @property {String}
|
|
12
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* @property {String} list-style - 'accordion' or 'faq'
|
|
12
|
+
*
|
|
13
13
|
* @example
|
|
14
14
|
* html`
|
|
15
15
|
* <ucd-theme-list-accordion>
|
|
16
|
-
* <
|
|
17
|
-
* <
|
|
18
|
-
* <
|
|
19
|
-
* <
|
|
16
|
+
* <li>Click me to expand div below</li>
|
|
17
|
+
* <li>I will be toggled when the above item is clicked.</li>
|
|
18
|
+
* <li>The direct children of this element must be divs</li>
|
|
19
|
+
* <li>But you can pass through <a href="#">rich text</a> within.</li >
|
|
20
20
|
* </ucd-theme-list-accordion>
|
|
21
21
|
* `
|
|
22
22
|
*/
|
|
23
23
|
export default class UcdThemeListAccordion extends LitElement {
|
|
24
|
-
|
|
25
24
|
static get properties() {
|
|
26
25
|
return {
|
|
27
|
-
listStyle: {type: String, attribute:
|
|
28
|
-
_listItems: {attribute: false, state: true},
|
|
29
|
-
_availableStyles: {attribute: false, state: true},
|
|
30
|
-
_expandedItems: {attribute: false, state: true}
|
|
26
|
+
listStyle: { type: String, attribute: 'list-style' },
|
|
27
|
+
_listItems: { attribute: false, state: true },
|
|
28
|
+
_availableStyles: { attribute: false, state: true },
|
|
29
|
+
_expandedItems: { attribute: false, state: true },
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -47,11 +46,11 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
47
46
|
/**
|
|
48
47
|
* @method updated
|
|
49
48
|
* @description Lit lifecycle method called after element has updated.
|
|
50
|
-
* @param {Map} props - properties that have changed
|
|
49
|
+
* @param {Map} props - properties that have changed
|
|
51
50
|
*/
|
|
52
|
-
updated(props){
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
51
|
+
updated(props) {
|
|
52
|
+
if (props.has('listStyle')) {
|
|
53
|
+
if (!this._availableStyles.includes(this.listStyle.toLowerCase())) {
|
|
55
54
|
this.listStyle = this._availableStyles[0];
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -61,18 +60,19 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
61
60
|
* @method connectedCallback
|
|
62
61
|
* @description Native lifecycle method called when element is connected
|
|
63
62
|
*/
|
|
64
|
-
connectedCallback(){
|
|
63
|
+
connectedCallback() {
|
|
65
64
|
super.connectedCallback();
|
|
66
|
-
this._childListObserver = new MutationObserver(
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
this._childListObserver = new MutationObserver((mutationsList, observer) =>
|
|
66
|
+
this._onChildListMutation(mutationsList, observer)
|
|
67
|
+
);
|
|
68
|
+
this._childListObserver.observe(this, { childList: true });
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* @method disconnectedCallback
|
|
73
73
|
* @description Native lifecycle method called when element is disconnected
|
|
74
74
|
*/
|
|
75
|
-
disconnectedCallback(){
|
|
75
|
+
disconnectedCallback() {
|
|
76
76
|
this._childListObserver.disconnect();
|
|
77
77
|
super.disconnectedCallback();
|
|
78
78
|
}
|
|
@@ -88,9 +88,9 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
88
88
|
* 0: first pair, 1: second pair, etc
|
|
89
89
|
* @param {Boolean} dispatchEvent - Will dispatch custom 'item-toggle' event
|
|
90
90
|
*/
|
|
91
|
-
async toggleItemVisiblity(index, isPairIndex=true, dispatchEvent=false){
|
|
91
|
+
async toggleItemVisiblity(index, isPairIndex = true, dispatchEvent = false) {
|
|
92
92
|
let pairIndex = isPairIndex ? index : Math.floor(index / 2);
|
|
93
|
-
if (
|
|
93
|
+
if (this._expandedItems.has(pairIndex)) {
|
|
94
94
|
this._expandedItems.delete(pairIndex);
|
|
95
95
|
} else {
|
|
96
96
|
this._expandedItems.add(pairIndex);
|
|
@@ -98,7 +98,7 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
98
98
|
|
|
99
99
|
this.requestUpdate();
|
|
100
100
|
await this.updateComplete;
|
|
101
|
-
if (
|
|
101
|
+
if (dispatchEvent) this._dispatchItemToggleEvent(index);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -108,7 +108,7 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
108
108
|
* @param {Boolean} isPairIndex - Does the index param refer to Q/A pair or the flattened index?
|
|
109
109
|
* @returns {Boolean}
|
|
110
110
|
*/
|
|
111
|
-
itemIsExpanded(index, isPairIndex=true) {
|
|
111
|
+
itemIsExpanded(index, isPairIndex = true) {
|
|
112
112
|
let pairIndex = isPairIndex ? index : Math.floor(index / 2);
|
|
113
113
|
return this._expandedItems.has(pairIndex);
|
|
114
114
|
}
|
|
@@ -116,21 +116,21 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
116
116
|
/**
|
|
117
117
|
* @method _onTitleClick
|
|
118
118
|
* @description Attached to item title
|
|
119
|
-
* @param {Event} e
|
|
119
|
+
* @param {Event} e
|
|
120
120
|
*/
|
|
121
121
|
_onTitleClick(e) {
|
|
122
|
-
let index = parseInt(e.target.getAttribute(
|
|
122
|
+
let index = parseInt(e.target.getAttribute('item-index'));
|
|
123
123
|
this.toggleItemVisiblity(index, false, true);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* @method _onTitleKeyUp
|
|
128
128
|
* @description Attached to item title
|
|
129
|
-
* @param {Event} e
|
|
129
|
+
* @param {Event} e
|
|
130
130
|
*/
|
|
131
131
|
_onTitleKeyUp(e) {
|
|
132
|
-
if(
|
|
133
|
-
let index = parseInt(e.target.getAttribute(
|
|
132
|
+
if (e.which !== 13) return;
|
|
133
|
+
let index = parseInt(e.target.getAttribute('item-index'));
|
|
134
134
|
this.toggleItemVisiblity(index, false, true);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -141,13 +141,13 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
141
141
|
_onChildListMutation() {
|
|
142
142
|
let listItems = [];
|
|
143
143
|
Array.from(this.children).forEach((child, index) => {
|
|
144
|
-
if (child.tagName !==
|
|
145
|
-
child.setAttribute('slot', 'list-item-'+index);
|
|
146
|
-
if(
|
|
144
|
+
if (child.tagName !== 'DIV') return;
|
|
145
|
+
child.setAttribute('slot', 'list-item-' + index);
|
|
146
|
+
if (this.listStyle === 'faq') {
|
|
147
147
|
child.style.display = 'inline';
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
listItems.push({child, slotName:'list-item-'+index});
|
|
150
|
+
listItems.push({ child, slotName: 'list-item-' + index });
|
|
151
151
|
});
|
|
152
152
|
this._listItems = listItems;
|
|
153
153
|
}
|
|
@@ -159,15 +159,19 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
159
159
|
*/
|
|
160
160
|
_dispatchItemToggleEvent(index) {
|
|
161
161
|
let e = new CustomEvent('item-toggle', {
|
|
162
|
-
detail: {
|
|
163
|
-
message: 'A list item has been expanded or collapsed',
|
|
162
|
+
detail: {
|
|
163
|
+
message: 'A list item has been expanded or collapsed',
|
|
164
164
|
isExpanded: this.itemIsExpanded(index, false),
|
|
165
|
-
item: {
|
|
165
|
+
item: {
|
|
166
|
+
title: this._listItems[index],
|
|
167
|
+
content: this._listItems[index + 1],
|
|
168
|
+
},
|
|
166
169
|
listItemIndex: index,
|
|
167
|
-
listItemPairIndex: Math.floor(index / 2)
|
|
170
|
+
listItemPairIndex: Math.floor(index / 2),
|
|
168
171
|
},
|
|
169
172
|
bubbles: true,
|
|
170
|
-
composed: true
|
|
173
|
+
composed: true,
|
|
174
|
+
});
|
|
171
175
|
this.dispatchEvent(e);
|
|
172
176
|
}
|
|
173
177
|
|
|
@@ -187,10 +191,9 @@ export default class UcdThemeListAccordion extends LitElement {
|
|
|
187
191
|
* @param {Number} i - Array index.
|
|
188
192
|
* @returns {Boolean}
|
|
189
193
|
*/
|
|
190
|
-
_isContent(i){
|
|
194
|
+
_isContent(i) {
|
|
191
195
|
return !this._isTitle(i);
|
|
192
196
|
}
|
|
193
|
-
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
customElements.define('ucd-theme-list-accordion', UcdThemeListAccordion);
|
|
199
|
+
customElements.define('ucd-theme-list-accordion', UcdThemeListAccordion);
|
package/{ucd-theme-list-accordion → brand/ucd-theme-list-accordion}/ucd-theme-list-accordion.tpl.js
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html, css } from 'lit';
|
|
2
2
|
|
|
3
3
|
import listCss from "@ucd-lib/theme-sass/2_base_class/_lists.css.js";
|
|
4
|
-
import { motionCollapse } from "
|
|
4
|
+
import { motionCollapse } from "../../utils/directives/motion-collapse";
|
|
5
5
|
|
|
6
6
|
export function styles() {
|
|
7
7
|
let customStyles = css`
|
|
@@ -28,7 +28,7 @@ ${this._listItems.map((item, index) => html`
|
|
|
28
28
|
${this._isTitle(index) ? html`
|
|
29
29
|
<li
|
|
30
30
|
id="accordion-${index}"
|
|
31
|
-
class="item-title"
|
|
31
|
+
class="item-title ${this.itemIsExpanded(index, false) ? 'active' : ''}"
|
|
32
32
|
item-index="${index}"
|
|
33
33
|
tabindex="0"
|
|
34
34
|
@click=${this._onTitleClick}
|
|
File without changes
|
package/{ucd-theme-message-area → brand/ucd-theme-message-area}/ucd-theme-message-area.tpl.js
RENAMED
|
File without changes
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { LitElement, html } from 'lit';
|
|
2
|
+
//import { Page } from 'puppeteer';
|
|
3
|
+
import {render, styles} from "./ucd-theme-pagination.tpl.js";
|
|
4
|
+
|
|
5
|
+
import { BreakPointsController } from '../../utils/controllers';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @class UcdThemePagination
|
|
9
|
+
* @classdesc Component class for pagination
|
|
10
|
+
*
|
|
11
|
+
* Pattern Lab Url:
|
|
12
|
+
* - http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-pagination
|
|
13
|
+
*
|
|
14
|
+
* @property {String} base-path - for anchor tag href
|
|
15
|
+
* @property {String} current-page - Page to show and highlight
|
|
16
|
+
* @property {String} max-pages - Max number of total pages
|
|
17
|
+
* @property {String} visible-link-count - How many page links to show
|
|
18
|
+
*
|
|
19
|
+
* @examples
|
|
20
|
+
* change!!!
|
|
21
|
+
* <ucd-theme-pagination
|
|
22
|
+
* current-page="50"
|
|
23
|
+
* max-pages="100"
|
|
24
|
+
* use-hash>
|
|
25
|
+
* </ucd-theme-pagination>
|
|
26
|
+
* <ucd-theme-pagination
|
|
27
|
+
* current-page="1"
|
|
28
|
+
* max-pages="10">
|
|
29
|
+
* </ucd-theme-pagination>
|
|
30
|
+
* <ucd-theme-pagination
|
|
31
|
+
* current-page="2"
|
|
32
|
+
* max-pages="33"
|
|
33
|
+
* base-path="/foo/bar/">
|
|
34
|
+
* </ucd-theme-pagination>
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
export default class UcdThemePagination extends LitElement {
|
|
38
|
+
breakPoints = new BreakPointsController(this);
|
|
39
|
+
|
|
40
|
+
static get properties() {
|
|
41
|
+
return {
|
|
42
|
+
basePath : {
|
|
43
|
+
type: String,
|
|
44
|
+
attribute: 'base-path'
|
|
45
|
+
},
|
|
46
|
+
useHash : {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
attribute: 'use-hash'
|
|
49
|
+
},
|
|
50
|
+
currentPage : {
|
|
51
|
+
type : Number,
|
|
52
|
+
attribute: 'current-page',
|
|
53
|
+
reflect: true
|
|
54
|
+
},
|
|
55
|
+
maxPages : {
|
|
56
|
+
type : Number,
|
|
57
|
+
attribute : 'max-pages'
|
|
58
|
+
},
|
|
59
|
+
visibleLinkCount : {
|
|
60
|
+
type : Number,
|
|
61
|
+
attribute : 'visible-link-count'
|
|
62
|
+
},
|
|
63
|
+
disableLabel : {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
attribute : 'disable-label'
|
|
66
|
+
},
|
|
67
|
+
_pages : {
|
|
68
|
+
type: Array
|
|
69
|
+
},
|
|
70
|
+
ellipses : {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
attribute : 'ellipses'
|
|
73
|
+
},
|
|
74
|
+
xs_screen : {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
attribute : 'xs-screen'
|
|
77
|
+
},
|
|
78
|
+
size : {
|
|
79
|
+
type: String,
|
|
80
|
+
attribute : 'size'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static get styles() {
|
|
87
|
+
return styles();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
|
|
93
|
+
this._pages = [];
|
|
94
|
+
this.useHash = false;
|
|
95
|
+
this.disableLabel = false;
|
|
96
|
+
this.type = 'virtual';
|
|
97
|
+
this.basePath = '';
|
|
98
|
+
this.visibleLinkCount = 7;
|
|
99
|
+
this.currentPage = 1;
|
|
100
|
+
this.maxPages = 1;
|
|
101
|
+
this.ellipses = false;
|
|
102
|
+
this.xs_screen = false;
|
|
103
|
+
this.size = '';
|
|
104
|
+
|
|
105
|
+
this.screen_check = (window.innerWidth <= this.breakPoints.mobileBreakPoint) ? true : false;
|
|
106
|
+
|
|
107
|
+
this.render = render.bind(this);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @method updated()
|
|
112
|
+
* @description Changes occur on update
|
|
113
|
+
*/
|
|
114
|
+
updated(props3) {
|
|
115
|
+
if( props3.has('currentPage') ) {
|
|
116
|
+
|
|
117
|
+
if(this.xs_screen && this.screen_check) {
|
|
118
|
+
let pages = [this.currentPage];
|
|
119
|
+
this._pages = pages; // Mobile Pagination
|
|
120
|
+
}else{
|
|
121
|
+
if(this.ellipses && this.maxPages >= 8){
|
|
122
|
+
this._pages = this._renderEllipse();
|
|
123
|
+
}else if(this.ellipses && this.maxPages < 8){
|
|
124
|
+
this._pages = this._renderOriginal();
|
|
125
|
+
}else {
|
|
126
|
+
let startIndex = Math.floor(this.currentPage - (this.visibleLinkCount/2));
|
|
127
|
+
|
|
128
|
+
if( startIndex < 0 ) {
|
|
129
|
+
startIndex = 0;
|
|
130
|
+
} else if( (this.currentPage + (this.visibleLinkCount/2)) > this.maxPages ) {
|
|
131
|
+
startIndex -= Math.ceil(this.currentPage + (this.visibleLinkCount/2)) - this.maxPages - 1;
|
|
132
|
+
}
|
|
133
|
+
if( startIndex < 0 ) {
|
|
134
|
+
startIndex = 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let endIndex = startIndex + this.visibleLinkCount;
|
|
138
|
+
if( endIndex > this.maxPages ) endIndex = this.maxPages;
|
|
139
|
+
|
|
140
|
+
let pages = [];
|
|
141
|
+
for( let i = startIndex; i < endIndex; i++ ) {
|
|
142
|
+
pages.push(i+1);
|
|
143
|
+
}
|
|
144
|
+
this._pages = pages;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
} // Desktop Pagination
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @method _constructClasses
|
|
154
|
+
* @description Makes a class map object based on element properties/attributes.
|
|
155
|
+
* Classes are applied to the element.
|
|
156
|
+
*
|
|
157
|
+
* @returns {Object} - {class1: true, class2: false}
|
|
158
|
+
*/
|
|
159
|
+
_constructClasses() {
|
|
160
|
+
let classes = {'main': true};
|
|
161
|
+
|
|
162
|
+
if (this.size) {
|
|
163
|
+
classes['size-' + this.size] = true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return classes;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @method _renderLink
|
|
172
|
+
* @description render the links on the pagination
|
|
173
|
+
* @returns {HTML}
|
|
174
|
+
*/
|
|
175
|
+
_renderLink(page, args={}) {
|
|
176
|
+
if( page < 1 ) page = 1;
|
|
177
|
+
if( page > this.maxPages ) page = this.maxPages;
|
|
178
|
+
|
|
179
|
+
if( args.noHighlight !== true && page === this.currentPage ) {
|
|
180
|
+
if( !args.class ) args.class = '';
|
|
181
|
+
args.class += ' pager__item--current';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if( !this.basePath && !this.useHash ) {
|
|
185
|
+
return html `<li class="pager__item ${args.class || ''}">
|
|
186
|
+
${((this.currentPage == 1 && args.label == "Prev") || (this.currentPage == this.maxPages && args.label == "Next") ) ?
|
|
187
|
+
html`<a style="pointer-events: none; cursor: default; color:#999999; background: white" tabindex="1" @click="${this._onPageClicked}" page="${page}">${args.label || page}</a>`:
|
|
188
|
+
html`<a style="cursor:pointer;" tabindex="1" @click="${this._onPageClicked}" page="${page}">${args.label || page}</a>`
|
|
189
|
+
}
|
|
190
|
+
</li>`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let href = (this.useHash ? '#' : '') + (this.basePath || '/') + page;
|
|
194
|
+
return html`<li class="pager__item ${args.class || ''}">
|
|
195
|
+
${((this.currentPage == 1 && args.label == "Prev") || (this.currentPage == this.maxPages && args.label == "Next") ) ?
|
|
196
|
+
html` <a style="pointer-events: none; cursor: default; color:#999999; background:white;" href="${href}">${args.label || page}</a>`:
|
|
197
|
+
html` <a href="${href}">${args.label || page}</a>`
|
|
198
|
+
}
|
|
199
|
+
</li>`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @method _renderOriginal
|
|
204
|
+
* @description render the ellipses pattern in pagination
|
|
205
|
+
* @returns {Array} pages
|
|
206
|
+
*/
|
|
207
|
+
_renderOriginal(){
|
|
208
|
+
let startIndex = Math.floor(this.currentPage - (this.visibleLinkCount/2));
|
|
209
|
+
|
|
210
|
+
if( startIndex < 0 ) {
|
|
211
|
+
startIndex = 0;
|
|
212
|
+
} else if( (this.currentPage + (this.visibleLinkCount/2)) > this.maxPages ) {
|
|
213
|
+
startIndex -= Math.ceil(this.currentPage + (this.visibleLinkCount/2)) - this.maxPages - 1;
|
|
214
|
+
}
|
|
215
|
+
if( startIndex < 0 ) {
|
|
216
|
+
startIndex = 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let endIndex = startIndex + this.visibleLinkCount;
|
|
220
|
+
if( endIndex > this.maxPages ) endIndex = this.maxPages;
|
|
221
|
+
|
|
222
|
+
let pages = [];
|
|
223
|
+
for( let i = startIndex; i < endIndex; i++ ) {
|
|
224
|
+
pages.push(i+1);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return pages;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @method _renderEllipse
|
|
232
|
+
* @description render the ellipses pattern in pagination
|
|
233
|
+
* @returns {Array} pages
|
|
234
|
+
*/
|
|
235
|
+
_renderEllipse(){
|
|
236
|
+
let startIndex = 0;
|
|
237
|
+
let endIndex = this.maxPages;
|
|
238
|
+
|
|
239
|
+
let pages = [];
|
|
240
|
+
if ((this.currentPage <= endIndex - 4) && (this.currentPage >= startIndex + 4)){
|
|
241
|
+
for( let i = startIndex; i < endIndex; i++ ) {
|
|
242
|
+
if(i == 0) pages.push(i+1);
|
|
243
|
+
else if (i == (startIndex + 1)) pages.push("...");
|
|
244
|
+
else if (i > (startIndex + 1) && i < this.currentPage - 3) continue;
|
|
245
|
+
else if (i >= (this.currentPage - 3) && i < (this.currentPage + 2)) pages.push(i+1);
|
|
246
|
+
else if (i < 4 && i < this.currentPage + 2) continue;
|
|
247
|
+
else if (i == (endIndex - 2)) pages.push("...");
|
|
248
|
+
else if (i == endIndex - 1) pages.push(i+1);
|
|
249
|
+
}
|
|
250
|
+
} //Middle ellipses
|
|
251
|
+
else if(this.currentPage >= startIndex + 4){
|
|
252
|
+
for( let i = startIndex; i < endIndex; i++ ) {
|
|
253
|
+
if (i == 0) pages.push(i+1);
|
|
254
|
+
else if(i > 0 && i < (endIndex - 6)) continue;
|
|
255
|
+
else if (i == (endIndex - 6)) pages.push("...");
|
|
256
|
+
else pages.push(i+1);
|
|
257
|
+
}
|
|
258
|
+
} //Left ellipses
|
|
259
|
+
else if(this.currentPage <= endIndex - 4){
|
|
260
|
+
for( let i = startIndex; i < endIndex; i++ ) {
|
|
261
|
+
if(i < 6) pages.push(i+1);
|
|
262
|
+
else if (i == 6) pages.push("...");
|
|
263
|
+
else if (i > 6 && i < (endIndex - 2)) continue;
|
|
264
|
+
else if (i == endIndex - 1) pages.push(i+1);
|
|
265
|
+
}
|
|
266
|
+
} //Right ellipses
|
|
267
|
+
return pages;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @method _onPageClicked
|
|
272
|
+
* @description event fires on page click
|
|
273
|
+
*
|
|
274
|
+
*/
|
|
275
|
+
_onPageClicked(e) {
|
|
276
|
+
this.dispatchEvent(new CustomEvent('page-change', {
|
|
277
|
+
detail : {page: parseInt(e.currentTarget.getAttribute('page'))}
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
customElements.define('ucd-theme-pagination', UcdThemePagination);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { html, css } from 'lit';
|
|
2
|
+
|
|
3
|
+
import normalizeCss from "@ucd-lib/theme-sass/normalize.css.js";
|
|
4
|
+
import resetCss from "@ucd-lib/theme-sass/1_base_html/_reset.css.js";
|
|
5
|
+
import paginationCss from "@ucd-lib/theme-sass/4_component/_pagination.css"
|
|
6
|
+
|
|
7
|
+
export function styles() {
|
|
8
|
+
const elementStyles = css`
|
|
9
|
+
:host {
|
|
10
|
+
display: block;
|
|
11
|
+
}
|
|
12
|
+
.default {
|
|
13
|
+
display: inherit;
|
|
14
|
+
}
|
|
15
|
+
.xs-screen {
|
|
16
|
+
display:none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@media (min-width: 991px) {
|
|
20
|
+
.pager__item--next {
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
align-items: center;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
@media (max-width: 992px) {
|
|
27
|
+
.default {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
30
|
+
.xs-screen {
|
|
31
|
+
display: flex;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
align-items: center;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
return [normalizeCss, resetCss, paginationCss, elementStyles];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function render() {
|
|
42
|
+
return html`
|
|
43
|
+
|
|
44
|
+
<ul class="pager">
|
|
45
|
+
${this.xs_screen ?
|
|
46
|
+
html`
|
|
47
|
+
<div class="xs-screen">
|
|
48
|
+
${this._renderLink(
|
|
49
|
+
this.currentPage-1,
|
|
50
|
+
{label: 'Prev', class: 'pager__item--previous', noHighlight: false}
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
${this._renderLink(this.currentPage)}
|
|
54
|
+
<span>of ${this.maxPages}</span>
|
|
55
|
+
${this._renderLink(
|
|
56
|
+
this.currentPage+1,
|
|
57
|
+
{label: 'Next', class: 'pager__item--next', noHighlight: false}
|
|
58
|
+
)}
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div class="default">
|
|
62
|
+
${this._renderLink(
|
|
63
|
+
this.currentPage-1,
|
|
64
|
+
{label: 'Prev', class: 'pager__item--previous', noHighlight: false}
|
|
65
|
+
)}
|
|
66
|
+
|
|
67
|
+
${this._pages.map(page => this._renderLink(page))}
|
|
68
|
+
|
|
69
|
+
${this._renderLink(
|
|
70
|
+
this.currentPage+1,
|
|
71
|
+
{label: 'Next', class: 'pager__item--next', noHighlight: false}
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
`
|
|
75
|
+
:html`
|
|
76
|
+
${this._renderLink(
|
|
77
|
+
this.currentPage-1,
|
|
78
|
+
{label: 'Prev', class: 'pager__item--previous', noHighlight: false}
|
|
79
|
+
)}
|
|
80
|
+
|
|
81
|
+
${this._pages.map(page => this._renderLink(page))}
|
|
82
|
+
|
|
83
|
+
${this._renderLink(
|
|
84
|
+
this.currentPage+1,
|
|
85
|
+
{label: 'Next', class: 'pager__item--next', noHighlight: false}
|
|
86
|
+
)}
|
|
87
|
+
`
|
|
88
|
+
}
|
|
89
|
+
</ul>
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
`;}
|