@internetarchive/ia-book-actions 0.0.5-4 → 0.0.5-4-01
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/demo/index.html +24 -1
- package/package.json +1 -1
- package/src/assets/data/archive-logo.js +32 -0
- package/src/assets/styles/collapsible-action-group.js +2 -0
- package/src/components/book-title-bar.js +90 -0
- package/src/core/config/analytics-event-and-category.js +1 -0
- package/src/core/services/actions-handler/actions-handler.js +5 -0
- package/src/core/services/get-lending-actions.js +0 -1
- package/src/ia-book-actions.js +33 -16
- package/test/components/book-title-bar.test.js +22 -0
- package/test/core/services/get-lending-actions.test.js +1 -1
- package/test/ia-book-actions.test.js +1 -1
package/demo/index.html
CHANGED
|
@@ -95,11 +95,23 @@
|
|
|
95
95
|
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
96
96
|
iaBookActions.userid = '';
|
|
97
97
|
iaBookActions.identifier = identifier;
|
|
98
|
+
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
98
99
|
iaBookActions.lendingStatus = defaultLendingStatus;
|
|
99
100
|
iaBookActions.bwbPurchaseUrl = '';
|
|
101
|
+
iaBookActions.barType = '';
|
|
100
102
|
|
|
101
103
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
102
104
|
|
|
105
|
+
document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
|
|
106
|
+
item.addEventListener('click', (e) => {
|
|
107
|
+
if (e.target.checked) {
|
|
108
|
+
iaBookActions.barType = 'title';
|
|
109
|
+
} else {
|
|
110
|
+
iaBookActions.barType = 'action';
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
103
115
|
document.querySelectorAll('.userState input[type=checkbox]').forEach((item) => {
|
|
104
116
|
item.addEventListener('click', (e) => {
|
|
105
117
|
if (e.target.checked) {
|
|
@@ -194,7 +206,18 @@
|
|
|
194
206
|
|
|
195
207
|
<div>
|
|
196
208
|
<fieldset>
|
|
197
|
-
<legend>Dev
|
|
209
|
+
<legend>Dev testing for book title bar</legend>
|
|
210
|
+
<table class="initial">
|
|
211
|
+
<tr>
|
|
212
|
+
<td class="titleBar">
|
|
213
|
+
<label><input type="checkbox" name="title" value="title" />Title Bar</label>
|
|
214
|
+
</td>
|
|
215
|
+
</tr>
|
|
216
|
+
</table>
|
|
217
|
+
</fieldset>
|
|
218
|
+
|
|
219
|
+
<fieldset>
|
|
220
|
+
<legend>Dev testing for book action bar</legend>
|
|
198
221
|
<table class="initial">
|
|
199
222
|
<tr>
|
|
200
223
|
<td class="userState">
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { html } from 'lit-element';
|
|
2
|
+
|
|
3
|
+
export const archiveLogo = html`
|
|
4
|
+
<svg
|
|
5
|
+
class="ia-logo"
|
|
6
|
+
width="26"
|
|
7
|
+
height="26"
|
|
8
|
+
viewBox="0 0 27 30"
|
|
9
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
10
|
+
aria-labelledby="logoTitleID logoDescID"
|
|
11
|
+
>
|
|
12
|
+
<title id="logoTitleID">Internet Archive logo</title>
|
|
13
|
+
<desc id="logoDescID">
|
|
14
|
+
A line drawing of the Internet Archive headquarters building façade.
|
|
15
|
+
</desc>
|
|
16
|
+
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
17
|
+
<mask id="mask-2" fill="white">
|
|
18
|
+
<path
|
|
19
|
+
d="M26.6666667,28.6046512 L26.6666667,30 L0,30 L0.000283687943,28.6046512 L26.6666667,28.6046512 Z M25.6140351,26.5116279 L25.6140351,28.255814 L1.05263158,28.255814 L1.05263158,26.5116279 L25.6140351,26.5116279 Z M3.62469203,7.6744186 L3.91746909,7.82153285 L4.0639977,10.1739544 L4.21052632,13.9963932 L4.21052632,17.6725617 L4.0639977,22.255044 L4.03962296,25.3421929 L3.62469203,25.4651163 L2.16024641,25.4651163 L1.72094074,25.3421929 L1.55031755,22.255044 L1.40350877,17.6970339 L1.40350877,14.0211467 L1.55031755,10.1739544 L1.68423854,7.80887484 L1.98962322,7.6744186 L3.62469203,7.6744186 Z M24.6774869,7.6744186 L24.9706026,7.82153285 L25.1168803,10.1739544 L25.2631579,13.9963932 L25.2631579,17.6725617 L25.1168803,22.255044 L25.0927809,25.3421929 L24.6774869,25.4651163 L23.2130291,25.4651163 L22.7736357,25.3421929 L22.602418,22.255044 L22.4561404,17.6970339 L22.4561404,14.0211467 L22.602418,10.1739544 L22.7369262,7.80887484 L23.0420916,7.6744186 L24.6774869,7.6744186 Z M9.94042303,7.6744186 L10.2332293,7.82153285 L10.3797725,10.1739544 L10.5263158,13.9963932 L10.5263158,17.6725617 L10.3797725,22.255044 L10.3556756,25.3421929 L9.94042303,25.4651163 L8.47583122,25.4651163 L8.0362015,25.3421929 L7.86556129,22.255044 L7.71929825,17.6970339 L7.71929825,14.0211467 L7.86556129,10.1739544 L8.00005604,7.80887484 L8.30491081,7.6744186 L9.94042303,7.6744186 Z M18.0105985,7.6744186 L18.3034047,7.82153285 L18.449948,10.1739544 L18.5964912,13.9963932 L18.5964912,17.6725617 L18.449948,22.255044 L18.425851,25.3421929 L18.0105985,25.4651163 L16.5460067,25.4651163 L16.1066571,25.3421929 L15.9357367,22.255044 L15.7894737,17.6970339 L15.7894737,14.0211467 L15.9357367,10.1739544 L16.0702315,7.80887484 L16.3753664,7.6744186 L18.0105985,7.6744186 Z M25.6140351,4.53488372 L25.6140351,6.97674419 L1.05263158,6.97674419 L1.05263158,4.53488372 L25.6140351,4.53488372 Z M13.0806755,0 L25.9649123,2.93331338 L25.4484139,3.8372093 L0.771925248,3.8372093 L0,3.1041615 L13.0806755,0 Z"
|
|
20
|
+
id="path-1"
|
|
21
|
+
></path>
|
|
22
|
+
</mask>
|
|
23
|
+
<use fill="#FFFFFF" xlink:href="#path-1"></use>
|
|
24
|
+
<g mask="url(#mask-2)" fill="#FFFFFF">
|
|
25
|
+
<path
|
|
26
|
+
d="M0,0 L26.6666667,0 L26.6666667,30 L0,30 L0,0 Z"
|
|
27
|
+
id="swatch"
|
|
28
|
+
></path>
|
|
29
|
+
</g>
|
|
30
|
+
</g>
|
|
31
|
+
</svg>
|
|
32
|
+
`;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { html, css } from 'lit-element';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
analyticsCategories,
|
|
5
|
+
analyticsActions,
|
|
6
|
+
} from '../core/config/analytics-event-and-category.js';
|
|
7
|
+
import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
|
|
8
|
+
|
|
9
|
+
import { archiveLogo } from '../assets/data/archive-logo.js';
|
|
10
|
+
|
|
11
|
+
export class BookTitleBar extends ActionsHandler {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
identifier: { type: String },
|
|
15
|
+
bookTitle: { type: String },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.identifier = '';
|
|
22
|
+
this.bookTitle = '';
|
|
23
|
+
this.analyticsCategories = analyticsCategories;
|
|
24
|
+
this.analyticsActions = analyticsActions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Click handler to emit custom event on action click
|
|
29
|
+
*/
|
|
30
|
+
clickHandler() {
|
|
31
|
+
const { category, action } = {
|
|
32
|
+
category: this.analyticsCategories.bookReaderHeader,
|
|
33
|
+
action: this.analyticsActions.titleBar,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
this.dispatchEvent(
|
|
37
|
+
new CustomEvent('bookTitleBar', {
|
|
38
|
+
detail: {
|
|
39
|
+
event: { category, action },
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
render() {
|
|
46
|
+
return html`
|
|
47
|
+
<a
|
|
48
|
+
class="embed-link"
|
|
49
|
+
@click=${() => {
|
|
50
|
+
this.clickHandler();
|
|
51
|
+
}}
|
|
52
|
+
href="/details/${this.identifier}"
|
|
53
|
+
>
|
|
54
|
+
<span>${archiveLogo}</span>
|
|
55
|
+
<span class="title">${this.bookTitle}</span>
|
|
56
|
+
</a>
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static get styles() {
|
|
61
|
+
return css`
|
|
62
|
+
:host {
|
|
63
|
+
padding: 0 10px;
|
|
64
|
+
}
|
|
65
|
+
.embed-link {
|
|
66
|
+
display: inline-flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
text-decoration: none;
|
|
69
|
+
color: var(--primaryTextColor, #fff);
|
|
70
|
+
font-size: 1.4rem;
|
|
71
|
+
height: 3.4rem;
|
|
72
|
+
}
|
|
73
|
+
.embed-link .title {
|
|
74
|
+
display: -webkit-box;
|
|
75
|
+
-webkit-box-orient: vertical;
|
|
76
|
+
-webkit-line-clamp: 2;
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
text-align: left;
|
|
79
|
+
}
|
|
80
|
+
.embed-link svg {
|
|
81
|
+
margin-right: 0.5rem;
|
|
82
|
+
}
|
|
83
|
+
.embed-link:hover {
|
|
84
|
+
text-decoration: underline;
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
window.customElements.define('book-title-bar', BookTitleBar);
|
|
@@ -82,6 +82,11 @@ export default class ActionsHandler extends LitElement {
|
|
|
82
82
|
const { category, action } = detail.event;
|
|
83
83
|
this.sendEvent(category, action);
|
|
84
84
|
});
|
|
85
|
+
|
|
86
|
+
this.addEventListener('bookTitleBar', ({ detail }) => {
|
|
87
|
+
const { category, action } = detail.event;
|
|
88
|
+
this.sendEvent(category, action);
|
|
89
|
+
});
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
handleBrowseIt() {
|
package/src/ia-book-actions.js
CHANGED
|
@@ -4,6 +4,7 @@ import { html, css, LitElement } from 'lit-element';
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
5
5
|
|
|
6
6
|
import './components/collapsible-action-group.js';
|
|
7
|
+
import './components/book-title-bar.js';
|
|
7
8
|
import './components/text-group.js';
|
|
8
9
|
import './components/info-icon.js';
|
|
9
10
|
|
|
@@ -15,9 +16,11 @@ export default class IABookActions extends LitElement {
|
|
|
15
16
|
return {
|
|
16
17
|
userid: { type: String },
|
|
17
18
|
identifier: { type: String },
|
|
19
|
+
bookTitle: { type: String },
|
|
18
20
|
lendingStatus: { type: Object },
|
|
19
21
|
width: { type: Number },
|
|
20
22
|
bwbPurchaseUrl: { type: String },
|
|
23
|
+
barType: { type: String },
|
|
21
24
|
sharedObserver: { attribute: false },
|
|
22
25
|
};
|
|
23
26
|
}
|
|
@@ -26,15 +29,17 @@ export default class IABookActions extends LitElement {
|
|
|
26
29
|
super();
|
|
27
30
|
this.userid = '';
|
|
28
31
|
this.identifier = '';
|
|
32
|
+
this.bookTitle = '';
|
|
29
33
|
this.lendingStatus = {};
|
|
34
|
+
this.width = 0;
|
|
35
|
+
this.bwbPurchaseUrl = '';
|
|
36
|
+
this.barType = 'action';
|
|
37
|
+
this.sharedObserver = undefined;
|
|
30
38
|
this.primaryActions = [];
|
|
31
39
|
this.primaryTitle = '';
|
|
32
40
|
this.primaryColor = 'primary';
|
|
33
41
|
this.secondaryActions = [];
|
|
34
|
-
this.width = 0;
|
|
35
|
-
this.bwbPurchaseUrl = '';
|
|
36
42
|
this.lendingOptions = {};
|
|
37
|
-
this.sharedObserver = undefined;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
disconnectedCallback() {
|
|
@@ -146,21 +151,34 @@ export default class IABookActions extends LitElement {
|
|
|
146
151
|
render() {
|
|
147
152
|
return html`
|
|
148
153
|
<section class="lending-wrapper">
|
|
149
|
-
|
|
150
|
-
.userid=${this.userid}
|
|
151
|
-
.identifier=${this.identifier}
|
|
152
|
-
.primaryColor=${this.primaryColor}
|
|
153
|
-
.primaryActions=${this.primaryActions}
|
|
154
|
-
.secondaryActions=${this.secondaryActions}
|
|
155
|
-
.width=${this.width}
|
|
156
|
-
.hasAdminAccess=${this.hasAdminAccess}
|
|
157
|
-
>
|
|
158
|
-
</collapsible-action-group>
|
|
159
|
-
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
154
|
+
${this.barType === 'title' ? this.bookTitleBar : this.bookActionBar}
|
|
160
155
|
</section>
|
|
161
156
|
`;
|
|
162
157
|
}
|
|
163
158
|
|
|
159
|
+
get bookTitleBar() {
|
|
160
|
+
return html`<book-title-bar
|
|
161
|
+
.identifier=${this.identifier}
|
|
162
|
+
.bookTitle=${this.bookTitle}
|
|
163
|
+
></book-title-bar>`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get bookActionBar() {
|
|
167
|
+
return html`
|
|
168
|
+
<collapsible-action-group
|
|
169
|
+
.userid=${this.userid}
|
|
170
|
+
.identifier=${this.identifier}
|
|
171
|
+
.primaryColor=${this.primaryColor}
|
|
172
|
+
.primaryActions=${this.primaryActions}
|
|
173
|
+
.secondaryActions=${this.secondaryActions}
|
|
174
|
+
.width=${this.width}
|
|
175
|
+
.hasAdminAccess=${this.hasAdminAccess}
|
|
176
|
+
>
|
|
177
|
+
</collapsible-action-group>
|
|
178
|
+
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
|
|
164
182
|
get iconClass() {
|
|
165
183
|
return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
|
|
166
184
|
}
|
|
@@ -176,7 +194,7 @@ export default class IABookActions extends LitElement {
|
|
|
176
194
|
get textGroupTemplate() {
|
|
177
195
|
return html`<text-group
|
|
178
196
|
textClass=${this.textClass}
|
|
179
|
-
texts
|
|
197
|
+
texts=${this.primaryTitle}
|
|
180
198
|
>
|
|
181
199
|
</text-group>`;
|
|
182
200
|
}
|
|
@@ -195,7 +213,6 @@ export default class IABookActions extends LitElement {
|
|
|
195
213
|
.lending-wrapper {
|
|
196
214
|
width: 100%;
|
|
197
215
|
margin: 0 auto;
|
|
198
|
-
padding: 10px 0;
|
|
199
216
|
display: inline-flex;
|
|
200
217
|
align-items: center;
|
|
201
218
|
justify-content: center;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { html, fixture, expect } from '@open-wc/testing';
|
|
2
|
+
import '../../src/components/book-title-bar.js';
|
|
3
|
+
|
|
4
|
+
const container = ({ identifier, bookTitle } = {}) =>
|
|
5
|
+
html`<book-title-bar
|
|
6
|
+
.identifier=${identifier}
|
|
7
|
+
.bookTitle=${bookTitle}
|
|
8
|
+
></book-title-bar>`;
|
|
9
|
+
|
|
10
|
+
describe('<book-title-bar>', () => {
|
|
11
|
+
it('check inner texts of title bar', async () => {
|
|
12
|
+
const el = await fixture(
|
|
13
|
+
container({
|
|
14
|
+
identifier: 'goody',
|
|
15
|
+
bookTitle: 'this is test booktitle',
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
const link = el.shadowRoot.querySelector('a');
|
|
19
|
+
expect(link.innerText).to.equal('this is test booktitle');
|
|
20
|
+
expect(link.getAttribute('href')).to.equal('/details/goody');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -36,7 +36,7 @@ describe('Get Lending Actions', () => {
|
|
|
36
36
|
);
|
|
37
37
|
const actions = lendingOptions.getCurrentLendingActions();
|
|
38
38
|
|
|
39
|
-
expect(actions.primaryActions.length).to.equal(
|
|
39
|
+
expect(actions.primaryActions.length).to.equal(2);
|
|
40
40
|
expect(actions.primaryTitle).to.equal(
|
|
41
41
|
'This book can be borrowed for 14 days.'
|
|
42
42
|
);
|
|
@@ -127,7 +127,7 @@ describe('Borrow status actions', () => {
|
|
|
127
127
|
expect(el.primaryTitle).to.equal(
|
|
128
128
|
'Renewable every hour, pending availability.'
|
|
129
129
|
);
|
|
130
|
-
expect(el.primaryActions.length).to.equal(
|
|
130
|
+
expect(el.primaryActions.length).to.equal(2);
|
|
131
131
|
expect(el.primaryActions[0].text).to.equal('Log In and Borrow');
|
|
132
132
|
expect(el.primaryActions[0].text).to.equal(expectedPrimaryActions[0].text);
|
|
133
133
|
});
|