@internetarchive/collection-browser 2.0.0 → 2.0.1-alpha.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.
@@ -11,6 +11,7 @@ import { BaseTileComponent } from '../base-tile-component';
11
11
 
12
12
  import { baseTileStyles } from './styles/tile-grid-shared-styles';
13
13
  import '../image-block';
14
+ import '../review-block';
14
15
  import '../text-snippet-block';
15
16
  import '../item-image';
16
17
  import '../mediatype-icon';
@@ -59,6 +60,7 @@ export class ItemTile extends BaseTileComponent {
59
60
  ? this.sortedDateInfoTemplate
60
61
  : this.creatorTemplate}
61
62
  ${this.webArchivesCaptureDatesTemplate} ${this.textSnippetsTemplate}
63
+ ${this.reviewBlockTemplate}
62
64
  </div>
63
65
 
64
66
  <tile-stats
@@ -152,6 +154,21 @@ export class ItemTile extends BaseTileComponent {
152
154
  : nothing;
153
155
  }
154
156
 
157
+ private get reviewBlockTemplate(): TemplateResult | typeof nothing {
158
+ if (!this.model?.review) return nothing;
159
+
160
+ const { title, body, stars } = this.model.review;
161
+ return html`
162
+ <review-block
163
+ viewsize="grid"
164
+ .title=${title}
165
+ .body=${body}
166
+ .starRating=${stars}
167
+ >
168
+ </review-block>
169
+ `;
170
+ }
171
+
155
172
  private get textSnippetsTemplate(): TemplateResult | typeof nothing {
156
173
  if (!this.hasSnippets) return nothing;
157
174
 
@@ -239,6 +256,7 @@ export class ItemTile extends BaseTileComponent {
239
256
  list-style-type: none;
240
257
  }
241
258
 
259
+ review-block,
242
260
  text-snippet-block {
243
261
  --containerLeftMargin: 5px;
244
262
  --containerTopMargin: 5px;
@@ -16,6 +16,8 @@ import { formatDate, DateFormat } from '../../utils/format-date';
16
16
  import { isFirstMillisecondOfUTCYear } from '../../utils/local-date-from-utc';
17
17
 
18
18
  import '../image-block';
19
+ import '../review-block';
20
+ import '../text-snippet-block';
19
21
  import '../mediatype-icon';
20
22
 
21
23
  @customElement('tile-list')
@@ -114,6 +116,7 @@ export class TileList extends BaseTileComponent {
114
116
  </div>
115
117
  ${this.topicsTemplate} ${this.collectionsTemplate}
116
118
  ${this.descriptionTemplate} ${this.textSnippetsTemplate}
119
+ ${this.reviewBlockTemplate}
117
120
  `;
118
121
  }
119
122
 
@@ -298,6 +301,21 @@ export class TileList extends BaseTileComponent {
298
301
  );
299
302
  }
300
303
 
304
+ private get reviewBlockTemplate(): TemplateResult | typeof nothing {
305
+ if (!this.model?.review) return nothing;
306
+
307
+ const { title, body, stars } = this.model.review;
308
+ return html`
309
+ <review-block
310
+ viewsize="list"
311
+ .title=${title}
312
+ .body=${body}
313
+ .starRating=${stars}
314
+ >
315
+ </review-block>
316
+ `;
317
+ }
318
+
301
319
  private get textSnippetsTemplate(): TemplateResult | typeof nothing {
302
320
  if (!this.hasSnippets) return nothing;
303
321
 
@@ -0,0 +1,129 @@
1
+ import {
2
+ css,
3
+ CSSResultGroup,
4
+ html,
5
+ LitElement,
6
+ nothing,
7
+ TemplateResult,
8
+ } from 'lit';
9
+ import { customElement, property } from 'lit/decorators.js';
10
+ import { msg } from '@lit/localize';
11
+ import { favoriteFilledIcon } from '../assets/img/icons/favorite-filled';
12
+ import { favoriteUnfilledIcon } from '../assets/img/icons/favorite-unfilled';
13
+ import { srOnlyStyle } from '../styles/sr-only';
14
+
15
+ @customElement('review-block')
16
+ export class ReviewBlock extends LitElement {
17
+ @property({ type: String }) title = '';
18
+
19
+ @property({ type: String }) body = '';
20
+
21
+ @property({ type: Number }) starRating = 0;
22
+
23
+ @property({ type: String }) viewSize = 'desktop';
24
+
25
+ render() {
26
+ if (!this.title && !this.body && !this.starRating) return nothing;
27
+
28
+ return html`
29
+ <div class="review-container">
30
+ <div class="snippet-view ${this.viewSize}">
31
+ ${this.starsTemplate}
32
+ <p class="review-title">${this.title}</p>
33
+ <p class="review-body">${this.body}</p>
34
+ </div>
35
+ </div>
36
+ `;
37
+ }
38
+
39
+ private get starsTemplate(): TemplateResult | typeof nothing {
40
+ if (this.starRating <= 0) return nothing;
41
+
42
+ const numFilledStars = Math.min(5, this.starRating);
43
+ const numUnfilledStars = Math.min(5, 5 - this.starRating);
44
+ return html`
45
+ <div class="star-rating">
46
+ <span class="sr-only">${this.starRating} ${msg('out of 5 stars')}</span>
47
+ ${Array(numFilledStars).fill(this.filledStarTemplate)}
48
+ ${Array(numUnfilledStars).fill(this.unfilledStarTemplate)}
49
+ </div>
50
+ `;
51
+ }
52
+
53
+ private get filledStarTemplate(): TemplateResult {
54
+ return html`<span aria-hidden="true">${favoriteFilledIcon}</span>`;
55
+ }
56
+
57
+ private get unfilledStarTemplate(): TemplateResult {
58
+ return html`
59
+ <span class="unfilled-star" aria-hidden="true">
60
+ ${favoriteUnfilledIcon}
61
+ </span>
62
+ `;
63
+ }
64
+
65
+ static get styles(): CSSResultGroup {
66
+ return [
67
+ srOnlyStyle,
68
+ css`
69
+ .review-container {
70
+ display: flex;
71
+ flex-direction: row;
72
+ flex-wrap: wrap;
73
+ width: calc(100% - 10px);
74
+ border: 1px solid #ccc;
75
+ margin-top: var(--containerTopMargin, 10px);
76
+ margin-left: var(--containerLeftMargin, 0px);
77
+ padding: 5px;
78
+ box-sizing: border-box;
79
+ }
80
+
81
+ .review-title,
82
+ .review-body {
83
+ display: -webkit-box;
84
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
85
+ overflow: hidden;
86
+ overflow-wrap: break-word;
87
+ -webkit-line-clamp: var(--maxLines, 3);
88
+ -webkit-box-orient: vertical;
89
+ margin: 0;
90
+ }
91
+
92
+ .review-title {
93
+ font-size: 1.4rem;
94
+ line-height: 2rem;
95
+ max-height: 6rem;
96
+ }
97
+
98
+ .review-title > a[href] {
99
+ color: inherit;
100
+ text-decoration: none;
101
+ }
102
+
103
+ .review-title > a[href]:hover {
104
+ text-decoration: underline;
105
+ }
106
+
107
+ .review-body {
108
+ font-size: 1rem;
109
+ line-height: 1.4rem;
110
+ max-height: 4.2rem;
111
+ }
112
+
113
+ .star-rating svg {
114
+ width: 10px;
115
+ height: 10px;
116
+ }
117
+
118
+ .unfilled-star {
119
+ fill: #ccc;
120
+ }
121
+
122
+ .list {
123
+ margin: 0;
124
+ padding-left: 5px;
125
+ }
126
+ `,
127
+ ];
128
+ }
129
+ }