@internetarchive/collection-browser 0.4.12 → 0.4.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.
Files changed (43) hide show
  1. package/dist/src/collection-browser.js +3 -0
  2. package/dist/src/collection-browser.js.map +1 -1
  3. package/dist/src/collection-facets.js +1 -10
  4. package/dist/src/collection-facets.js.map +1 -1
  5. package/dist/src/models.d.ts +5 -1
  6. package/dist/src/models.js +19 -8
  7. package/dist/src/models.js.map +1 -1
  8. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +1 -2
  9. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js.map +1 -1
  10. package/dist/src/sort-filter-bar/img/list.js +1 -1
  11. package/dist/src/sort-filter-bar/img/list.js.map +1 -1
  12. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -0
  13. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +15 -0
  14. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js.map +1 -0
  15. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -0
  16. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +17 -0
  17. package/dist/src/sort-filter-bar/img/sort-toggle-down.js.map +1 -0
  18. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -0
  19. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +17 -0
  20. package/dist/src/sort-filter-bar/img/sort-toggle-up.js.map +1 -0
  21. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +95 -14
  22. package/dist/src/sort-filter-bar/sort-filter-bar.js +386 -292
  23. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  24. package/dist/src/tiles/grid/item-tile.js +9 -5
  25. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  26. package/dist/src/tiles/grid/tile-stats.d.ts +1 -0
  27. package/dist/src/tiles/grid/tile-stats.js +5 -1
  28. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  29. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +241 -68
  30. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  31. package/package.json +2 -1
  32. package/src/collection-browser.ts +3 -0
  33. package/src/collection-facets.ts +1 -10
  34. package/src/models.ts +23 -8
  35. package/src/sort-filter-bar/alpha-bar-tooltip.ts +1 -2
  36. package/src/sort-filter-bar/img/list.ts +1 -1
  37. package/src/sort-filter-bar/img/sort-toggle-disabled.ts +15 -0
  38. package/src/sort-filter-bar/img/sort-toggle-down.ts +17 -0
  39. package/src/sort-filter-bar/img/sort-toggle-up.ts +17 -0
  40. package/src/sort-filter-bar/sort-filter-bar.ts +433 -303
  41. package/src/tiles/grid/item-tile.ts +6 -1
  42. package/src/tiles/grid/tile-stats.ts +3 -1
  43. package/test/sort-filter-bar/sort-filter-bar.test.ts +377 -101
@@ -1,30 +1,51 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { LitElement, html, css, nothing, } from 'lit';
3
3
  import { customElement, property, query, state } from 'lit/decorators.js';
4
- import { SortField, SortFieldDisplayName, } from '../models';
4
+ import '@internetarchive/ia-dropdown';
5
+ import { DefaultSortDirection, SortField, SortFieldDisplayName, } from '../models';
5
6
  import './alpha-bar';
6
- import { sortIcon } from './img/sort-triangle';
7
+ import { sortUpIcon } from './img/sort-toggle-up';
8
+ import { sortDownIcon } from './img/sort-toggle-down';
9
+ import { sortDisabledIcon } from './img/sort-toggle-disabled';
7
10
  import { tileIcon } from './img/tile';
8
11
  import { listIcon } from './img/list';
9
12
  import { compactIcon } from './img/compact';
10
13
  let SortFilterBar = class SortFilterBar extends LitElement {
11
14
  constructor() {
12
15
  super(...arguments);
16
+ /** The current sort direction (asc/desc), or null if none is set */
13
17
  this.sortDirection = null;
18
+ /** The field currently being sorted on (e.g., 'title'). Defaults to relevance. */
14
19
  this.selectedSort = SortField.relevance;
20
+ /** The currently selected title letter filter, or null if none is set */
15
21
  this.selectedTitleFilter = null;
22
+ /** The currently selected creator letter filter, or null if none is set */
16
23
  this.selectedCreatorFilter = null;
24
+ /** Whether to show the Relevance sort option (default `true`) */
17
25
  this.showRelevance = true;
26
+ /**
27
+ * Which of the alphabet bars (title/creator) should be shown, or null if one
28
+ * should not currently be rendered.
29
+ */
18
30
  this.alphaSelectorVisible = null;
19
- this.dateSortSelectorVisible = false;
20
- this.viewSortSelectorVisible = false;
21
- this.desktopSelectorBarWidth = 0;
31
+ /**
32
+ * Whether the transparent backdrop to catch clicks outside the dropdown menu
33
+ * should be rendered.
34
+ */
35
+ this.dropdownBackdropVisible = false;
36
+ /**
37
+ * The width of the desktop view sort option container, updated upon each resize.
38
+ * Used for dynamically determining whether to use desktop or mobile view.
39
+ */
40
+ this.desktopSortContainerWidth = 0;
41
+ /**
42
+ * The width of the full sort bar, updated upon each resize.
43
+ * Used for dynamically determining whether to use desktop or mobile view.
44
+ */
22
45
  this.selectorBarContainerWidth = 0;
23
- this.hoveringOverDateSortOptions = false;
24
46
  this.boundSortBarSelectorEscapeListener = (e) => {
25
47
  if (e.key === 'Escape') {
26
- this.viewSortSelectorVisible = false;
27
- this.dateSortSelectorVisible = false;
48
+ this.closeDropdowns();
28
49
  }
29
50
  };
30
51
  }
@@ -32,9 +53,10 @@ let SortFilterBar = class SortFilterBar extends LitElement {
32
53
  return html `
33
54
  <div id="container">
34
55
  <div id="sort-bar">
35
- <div id="sort-direction-container">
56
+ <div class="sort-direction-container">
36
57
  ${this.sortDirectionSelectorTemplate}
37
58
  </div>
59
+ <span class="sort-by-text">Sort by:</span>
38
60
 
39
61
  <div id="sort-selector-container">
40
62
  ${this.mobileSortSelectorTemplate}
@@ -44,15 +66,8 @@ let SortFilterBar = class SortFilterBar extends LitElement {
44
66
  <div id="display-style-selector">${this.displayOptionTemplate}</div>
45
67
  </div>
46
68
 
47
- ${this.viewSortSelectorVisible && !this.mobileSelectorVisible
48
- ? this.viewSortSelector
49
- : nothing}
50
- ${this.dateSortSelectorVisible && !this.mobileSelectorVisible
51
- ? this.dateSortSelector
52
- : nothing}
69
+ ${this.dropdownBackdropVisible ? this.dropdownBackdrop : nothing}
53
70
  ${this.alphaBarTemplate}
54
-
55
- <div id="bottom-shadow"></div>
56
71
  </div>
57
72
  `;
58
73
  }
@@ -61,7 +76,7 @@ let SortFilterBar = class SortFilterBar extends LitElement {
61
76
  this.displayModeChanged();
62
77
  }
63
78
  if (changed.has('selectedSort') && this.sortDirection === null) {
64
- this.sortDirection = 'desc';
79
+ this.sortDirection = DefaultSortDirection[this.selectedSort];
65
80
  }
66
81
  if (changed.has('selectedTitleFilter') && this.selectedTitleFilter) {
67
82
  this.alphaSelectorVisible = 'title';
@@ -69,8 +84,7 @@ let SortFilterBar = class SortFilterBar extends LitElement {
69
84
  if (changed.has('selectedCreatorFilter') && this.selectedCreatorFilter) {
70
85
  this.alphaSelectorVisible = 'creator';
71
86
  }
72
- if (changed.has('dateSortSelectorVisible') ||
73
- changed.has('viewSortSelectorVisible')) {
87
+ if (changed.has('dropdownBackdropVisible')) {
74
88
  this.setupEscapeListeners();
75
89
  }
76
90
  if (changed.has('resizeObserver')) {
@@ -81,7 +95,7 @@ let SortFilterBar = class SortFilterBar extends LitElement {
81
95
  }
82
96
  }
83
97
  setupEscapeListeners() {
84
- if (this.dateSortSelectorVisible || this.viewSortSelectorVisible) {
98
+ if (this.dropdownBackdropVisible) {
85
99
  document.addEventListener('keydown', this.boundSortBarSelectorEscapeListener);
86
100
  }
87
101
  else {
@@ -99,7 +113,7 @@ let SortFilterBar = class SortFilterBar extends LitElement {
99
113
  handler: this,
100
114
  });
101
115
  resizeObserver.removeObserver({
102
- target: this.desktopSortSelector,
116
+ target: this.desktopSortContainer,
103
117
  handler: this,
104
118
  });
105
119
  }
@@ -111,13 +125,29 @@ let SortFilterBar = class SortFilterBar extends LitElement {
111
125
  handler: this,
112
126
  });
113
127
  this.resizeObserver.addObserver({
114
- target: this.desktopSortSelector,
128
+ target: this.desktopSortContainer,
115
129
  handler: this,
116
130
  });
117
131
  }
132
+ handleResize(entry) {
133
+ if (entry.target === this.desktopSortContainer) {
134
+ this.desktopSortContainerWidth = entry.contentRect.width;
135
+ }
136
+ else if (entry.target === this.sortSelectorContainer) {
137
+ this.selectorBarContainerWidth = entry.contentRect.width;
138
+ }
139
+ }
140
+ /**
141
+ * Whether to show the mobile sort bar because there is not enough space
142
+ * for the desktop sort bar.
143
+ */
118
144
  get mobileSelectorVisible() {
119
- return this.selectorBarContainerWidth - 10 < this.desktopSelectorBarWidth;
145
+ return this.selectorBarContainerWidth - 10 < this.desktopSortContainerWidth;
120
146
  }
147
+ /**
148
+ * Template to render the alphabet bar, or `nothing` if it should not be rendered
149
+ * for the current sort
150
+ */
121
151
  get alphaBarTemplate() {
122
152
  if (!['title', 'creator'].includes(this.selectedSort))
123
153
  return nothing;
@@ -134,120 +164,111 @@ let SortFilterBar = class SortFilterBar extends LitElement {
134
164
  }
135
165
  return nothing;
136
166
  }
137
- handleResize(entry) {
138
- if (entry.target === this.desktopSortSelector) {
139
- this.desktopSelectorBarWidth = entry.contentRect.width;
140
- }
141
- else if (entry.target === this.sortSelectorContainer) {
142
- this.selectorBarContainerWidth = entry.contentRect.width;
143
- }
144
- }
167
+ /** Template to render the sort direction toggle button */
145
168
  get sortDirectionSelectorTemplate() {
146
169
  return html `
147
- <div id="sort-direction-selector">
148
- <button
149
- id="sort-ascending-btn"
150
- class="sort-button ${this.sortDirection === 'asc' ? 'selected' : ''}"
151
- ?disabled=${this.selectedSort === 'relevance'}
152
- @click=${() => {
153
- this.setSortDirections('asc');
154
- }}
155
- >
156
- ${sortIcon}
157
- </button>
158
- <button
159
- id="sort-descending-btn"
160
- class="sort-button ${this.sortDirection === 'desc' ? 'selected' : ''}"
161
- ?disabled=${this.selectedSort === 'relevance'}
162
- @click=${() => {
163
- this.setSortDirections('desc');
164
- }}
165
- >
166
- ${sortIcon}
167
- </button>
170
+ <button
171
+ class="sort-direction-selector"
172
+ ?disabled=${this.selectedSort === 'relevance'}
173
+ @click=${this.toggleSortDirection}
174
+ >
175
+ ${this.sortDirectionIcon}
176
+ </button>
177
+ `;
178
+ }
179
+ /** Template to render the sort direction button's icon in the correct current state */
180
+ get sortDirectionIcon() {
181
+ // For relevance sort, show a fully disabled icon
182
+ if (this.selectedSort === 'relevance') {
183
+ return html `<div class="sort-direction-icon">${sortDisabledIcon}</div>`;
184
+ }
185
+ // For all other sorts, show the ascending/descending direction
186
+ return html `
187
+ <div class="sort-direction-icon">
188
+ ${this.sortDirection === 'asc' ? sortUpIcon : sortDownIcon}
168
189
  </div>
169
190
  `;
170
191
  }
192
+ /** The template to render all the sort options in desktop view */
171
193
  get desktopSortSelectorTemplate() {
172
194
  return html `
173
- <ul
174
- id="desktop-sort-selector"
195
+ <div
196
+ id="desktop-sort-container"
175
197
  class=${this.mobileSelectorVisible ? 'hidden' : 'visible'}
176
198
  >
177
- <li id="sort-by-text">Sort By</li>
178
- <li>
179
- ${this.showRelevance
180
- ? this.getSortDisplayOption(SortField.relevance)
199
+ <ul id="desktop-sort-selector">
200
+ <li>
201
+ ${this.showRelevance
202
+ ? this.getSortDisplayOption(SortField.relevance, {
203
+ onClick: () => {
204
+ this.clearAlphaBarFilters();
205
+ this.dropdownBackdropVisible = false;
206
+ this.setSelectedSort(SortField.relevance);
207
+ this.emitTitleLetterChangedEvent();
208
+ this.emitCreatorLetterChangedEvent();
209
+ },
210
+ })
181
211
  : nothing}
182
- </li>
183
- <li>
184
- ${this.getSortDisplayOption(SortField.weeklyview, {
185
- clickEvent: () => {
186
- if (!this.viewOptionSelected)
187
- this.setSelectedSort(SortField.weeklyview);
188
- this.viewSortSelectorVisible = !this.viewSortSelectorVisible;
189
- this.dateSortSelectorVisible = false;
190
- this.alphaSelectorVisible = null;
191
- this.selectedTitleFilter = null;
192
- this.selectedCreatorFilter = null;
193
- this.emitTitleLetterChangedEvent();
194
- this.emitCreatorLetterChangedEvent();
195
- },
196
- displayName: html `${this.viewSortField}`,
197
- isSelected: () => this.viewOptionSelected,
198
- })}
199
- </li>
200
- <li>
201
- ${this.getSortDisplayOption(SortField.title, {
202
- clickEvent: () => {
212
+ </li>
213
+ <li>${this.viewsDropdownTemplate}</li>
214
+ <li>
215
+ ${this.getSortDisplayOption(SortField.title, {
216
+ onClick: () => {
203
217
  this.alphaSelectorVisible = 'title';
204
218
  this.selectedCreatorFilter = null;
205
- this.dateSortSelectorVisible = false;
206
- this.viewSortSelectorVisible = false;
219
+ this.dropdownBackdropVisible = false;
207
220
  this.setSelectedSort(SortField.title);
208
221
  this.emitCreatorLetterChangedEvent();
209
222
  },
210
223
  })}
211
- </li>
212
- <li>
213
- ${this.getSortDisplayOption(SortField.date, {
214
- clickEvent: () => {
215
- if (!this.dateOptionSelected)
216
- this.setSelectedSort(SortField.date);
217
- this.dateSortSelectorVisible = !this.dateSortSelectorVisible;
218
- this.viewSortSelectorVisible = false;
219
- this.alphaSelectorVisible = null;
220
- this.selectedTitleFilter = null;
221
- this.selectedCreatorFilter = null;
222
- this.emitTitleLetterChangedEvent();
223
- this.emitCreatorLetterChangedEvent();
224
- },
225
- displayName: html `${this.dateSortField}`,
226
- isSelected: () => this.dateOptionSelected,
227
- })}
228
- </li>
229
- <li>
230
- ${this.getSortDisplayOption(SortField.creator, {
231
- clickEvent: () => {
224
+ </li>
225
+ <li>${this.dateDropdownTemplate}</li>
226
+ <li>
227
+ ${this.getSortDisplayOption(SortField.creator, {
228
+ onClick: () => {
232
229
  this.alphaSelectorVisible = 'creator';
233
230
  this.selectedTitleFilter = null;
234
- this.dateSortSelectorVisible = false;
231
+ this.dropdownBackdropVisible = false;
235
232
  this.setSelectedSort(SortField.creator);
236
233
  this.emitTitleLetterChangedEvent();
237
234
  },
238
235
  })}
239
- </li>
240
- </ul>
236
+ </li>
237
+ </ul>
238
+ </div>
239
+ `;
240
+ }
241
+ /** The template to render all the sort options in mobile view */
242
+ get mobileSortSelectorTemplate() {
243
+ var _a, _b;
244
+ return html `
245
+ <div
246
+ id="mobile-sort-container"
247
+ class=${this.mobileSelectorVisible ? 'visible' : 'hidden'}
248
+ >
249
+ ${this.getSortDropdown({
250
+ displayName: html `${(_a = SortFieldDisplayName[this.selectedSort]) !== null && _a !== void 0 ? _a : ''}`,
251
+ id: 'mobile-dropdown',
252
+ isSelected: () => true,
253
+ dropdownOptions: Object.keys(SortField).map(field => this.getDropdownOption(field)),
254
+ selectedOption: (_b = this.selectedSort) !== null && _b !== void 0 ? _b : SortField.relevance,
255
+ onOptionSelected: this.mobileSortChanged,
256
+ onDropdownClick: () => {
257
+ this.dropdownBackdropVisible = this.mobileDropdown.open;
258
+ this.mobileDropdown.classList.toggle('open', this.mobileDropdown.open);
259
+ },
260
+ })}
261
+ </div>
241
262
  `;
242
263
  }
243
264
  /**
244
- * This generates each of the sort option links.
265
+ * This generates each of the non-dropdown sort option links.
245
266
  *
246
267
  * It manages the display value and the selected state of the option.
247
268
  *
248
269
  * @param sortField
249
270
  * @param options {
250
- * additionalClickEvent?: () => void; If this is provided, it will also be called when the option is clicked.
271
+ * onClick?: (e: Event) => void; If this is provided, it will also be called when the option is clicked.
251
272
  * displayName?: TemplateResult; The name to display for the option. Defaults to the sortField display name.
252
273
  * isSelected?: () => boolean; A function that returns true if the option is selected. Defaults to the selectedSort === sortField.
253
274
  * }
@@ -261,44 +282,139 @@ let SortFilterBar = class SortFilterBar extends LitElement {
261
282
  <a
262
283
  href="#"
263
284
  @click=${(e) => {
285
+ var _a;
264
286
  e.preventDefault();
265
- if (options === null || options === void 0 ? void 0 : options.clickEvent) {
266
- options.clickEvent(e);
267
- }
268
- else {
269
- this.alphaSelectorVisible = null;
270
- this.dateSortSelectorVisible = false;
271
- this.selectedTitleFilter = null;
272
- this.selectedCreatorFilter = null;
273
- this.setSelectedSort(sortField);
274
- this.emitTitleLetterChangedEvent();
275
- this.emitCreatorLetterChangedEvent();
276
- }
287
+ (_a = options === null || options === void 0 ? void 0 : options.onClick) === null || _a === void 0 ? void 0 : _a.call(options, e);
277
288
  }}
278
- class=${isSelected() ? 'selected' : ''}
289
+ class=${isSelected() ? 'selected' : nothing}
279
290
  >
280
291
  ${displayName}
281
292
  </a>
282
293
  `;
283
294
  }
284
- get mobileSortSelectorTemplate() {
295
+ /**
296
+ * Generates a dropdown component containing multiple grouped sort options.
297
+ *
298
+ * @param options.displayName The name to use for the dropdown's visible label
299
+ * @param options.id The id to apply to the dropdown element
300
+ * @param options.dropdownOptions An array of option objects used to populate the dropdown
301
+ * @param options.selectedOption The id of the option that should be initially selected
302
+ * @param options.isSelected A function returning a boolean indicating whether this dropdown
303
+ * should use its selected appearance
304
+ * @param options.onOptionSelected A handler for optionSelected events coming from the dropdown
305
+ * @param options.onDropdownClick A handler for click events on the dropdown
306
+ * @param options.onLabelInteraction A handler for click events and Enter/Space keydown events
307
+ * on the dropdown's label
308
+ */
309
+ getSortDropdown(options) {
310
+ var _a, _b, _c, _d, _e, _f;
285
311
  return html `
286
- <select
287
- id="mobile-sort-selector"
288
- @change=${this.mobileSortChanged}
289
- class=${this.mobileSelectorVisible ? 'visible' : 'hidden'}
312
+ <ia-dropdown
313
+ id=${(_a = options.id) !== null && _a !== void 0 ? _a : nothing}
314
+ class=${((_b = options.isSelected) === null || _b === void 0 ? void 0 : _b.call(options)) ? 'selected' : nothing}
315
+ displayCaret
316
+ closeOnSelect
317
+ includeSelectedOption
318
+ .openViaButton=${false}
319
+ .options=${options.dropdownOptions}
320
+ .selectedOption=${(_c = options.selectedOption) !== null && _c !== void 0 ? _c : ''}
321
+ @optionSelected=${(_d = options.onOptionSelected) !== null && _d !== void 0 ? _d : nothing}
322
+ @click=${(_e = options.onDropdownClick) !== null && _e !== void 0 ? _e : nothing}
290
323
  >
291
- ${Object.keys(SortField).map(field => html `
292
- <option value="${field}" ?selected=${this.selectedSort === field}>
293
- ${SortFieldDisplayName[field]}
294
- </option>
295
- `)}
296
- </select>
324
+ <span
325
+ class="dropdown-label"
326
+ slot="dropdown-label"
327
+ @click=${(_f = options.onLabelInteraction) !== null && _f !== void 0 ? _f : nothing}
328
+ @keydown=${options.onLabelInteraction
329
+ ? (e) => {
330
+ var _a;
331
+ if (e.key === 'Enter' || e.key === ' ') {
332
+ (_a = options.onLabelInteraction) === null || _a === void 0 ? void 0 : _a.call(options);
333
+ }
334
+ }
335
+ : nothing}
336
+ >
337
+ ${options.displayName}
338
+ </span>
339
+ </ia-dropdown>
297
340
  `;
298
341
  }
342
+ /** Generates a single dropdown option object for the given sort field */
343
+ getDropdownOption(sortField) {
344
+ return {
345
+ id: sortField,
346
+ selectedHandler: () => {
347
+ this.selectDropdownSortField(sortField);
348
+ },
349
+ label: html `
350
+ <span class="dropdown-option-label">
351
+ ${SortFieldDisplayName[sortField]}
352
+ </span>
353
+ `,
354
+ };
355
+ }
356
+ /** Handler for when any sort dropdown option is selected */
357
+ dropdownOptionSelected(e) {
358
+ this.dropdownBackdropVisible = false;
359
+ this.clearAlphaBarFilters();
360
+ this.setSelectedSort(e.detail.option.id);
361
+ this.emitTitleLetterChangedEvent();
362
+ this.emitCreatorLetterChangedEvent();
363
+ }
364
+ /** The template to render for the views dropdown */
365
+ get viewsDropdownTemplate() {
366
+ return this.getSortDropdown({
367
+ displayName: html `${this.viewSortField}`,
368
+ id: 'views-dropdown',
369
+ isSelected: () => this.viewOptionSelected,
370
+ dropdownOptions: [
371
+ this.getDropdownOption(SortField.weeklyview),
372
+ this.getDropdownOption(SortField.alltimeview),
373
+ ],
374
+ selectedOption: this.viewOptionSelected ? this.selectedSort : '',
375
+ onOptionSelected: this.dropdownOptionSelected,
376
+ onDropdownClick: () => {
377
+ this.dateDropdown.open = false;
378
+ this.dropdownBackdropVisible = this.viewsDropdown.open;
379
+ this.viewsDropdown.classList.toggle('open', this.viewsDropdown.open);
380
+ },
381
+ onLabelInteraction: () => {
382
+ if (!this.viewsDropdown.open && !this.viewOptionSelected) {
383
+ this.setSelectedSort(SortField.weeklyview);
384
+ }
385
+ },
386
+ });
387
+ }
388
+ /** The template to render for the date dropdown */
389
+ get dateDropdownTemplate() {
390
+ return this.getSortDropdown({
391
+ displayName: html `${this.dateSortField}`,
392
+ id: 'date-dropdown',
393
+ isSelected: () => this.dateOptionSelected,
394
+ dropdownOptions: [
395
+ this.getDropdownOption(SortField.date),
396
+ this.getDropdownOption(SortField.datearchived),
397
+ this.getDropdownOption(SortField.datereviewed),
398
+ this.getDropdownOption(SortField.dateadded),
399
+ ],
400
+ selectedOption: this.dateOptionSelected ? this.selectedSort : '',
401
+ onOptionSelected: this.dropdownOptionSelected,
402
+ onDropdownClick: () => {
403
+ this.viewsDropdown.open = false;
404
+ this.dropdownBackdropVisible = this.dateDropdown.open;
405
+ this.dateDropdown.classList.toggle('open', this.dateDropdown.open);
406
+ },
407
+ onLabelInteraction: () => {
408
+ if (!this.dateDropdown.open && !this.dateOptionSelected) {
409
+ this.setSelectedSort(SortField.date);
410
+ }
411
+ },
412
+ });
413
+ }
414
+ /** Handler for when a new mobile sort dropdown option is selected */
299
415
  mobileSortChanged(e) {
300
- const target = e.target;
301
- const sortField = target.value;
416
+ this.dropdownBackdropVisible = false;
417
+ const sortField = e.detail.option.id;
302
418
  this.setSelectedSort(sortField);
303
419
  this.alphaSelectorVisible = null;
304
420
  if (sortField !== 'title' && this.selectedTitleFilter) {
@@ -310,6 +426,7 @@ let SortFilterBar = class SortFilterBar extends LitElement {
310
426
  this.emitCreatorLetterChangedEvent();
311
427
  }
312
428
  }
429
+ /** Template for rendering the three display mode options */
313
430
  get displayOptionTemplate() {
314
431
  return html `
315
432
  <ul>
@@ -352,69 +469,54 @@ let SortFilterBar = class SortFilterBar extends LitElement {
352
469
  </ul>
353
470
  `;
354
471
  }
355
- get dateSortSelector() {
472
+ /**
473
+ * Template for rendering the transparent backdrop to capture clicks outside the
474
+ * dropdown menu while it is open.
475
+ */
476
+ get dropdownBackdrop() {
356
477
  return html `
357
478
  <div
358
- id="date-sort-selector-backdrop"
359
- @keyup=${() => {
360
- this.dateSortSelectorVisible = false;
361
- }}
362
- @click=${() => {
363
- this.dateSortSelectorVisible = false;
364
- }}
479
+ id="sort-selector-backdrop"
480
+ @keyup=${this.closeDropdowns}
481
+ @click=${this.closeDropdowns}
365
482
  ></div>
366
- <div id="date-sort-selector">
367
- <ul>
368
- <li>${this.getDateSortButton(SortField.datearchived)}</li>
369
- <li>${this.getDateSortButton(SortField.date)}</li>
370
- <li>${this.getDateSortButton(SortField.datereviewed)}</li>
371
- <li>${this.getDateSortButton(SortField.dateadded)}</li>
372
- </ul>
373
- </div>
374
483
  `;
375
484
  }
376
- get viewSortSelector() {
377
- return html `
378
- <div
379
- id="view-sort-selector-backdrop"
380
- @keyup=${() => {
381
- this.viewSortSelectorVisible = false;
382
- }}
383
- @click=${() => {
384
- this.viewSortSelectorVisible = false;
385
- }}
386
- ></div>
387
- <div id="view-sort-selector">
388
- <ul>
389
- <li>${this.getDateSortButton(SortField.alltimeview)}</li>
390
- <li>${this.getDateSortButton(SortField.weeklyview)}</li>
391
- </ul>
392
- </div>
393
- `;
394
- }
395
- getDateSortButton(sortField) {
396
- return html `
397
- <button
398
- @click=${() => {
399
- this.selectDateSort(sortField);
400
- }}
401
- class=${this.selectedSort === sortField ? 'selected' : ''}
402
- >
403
- ${SortFieldDisplayName[sortField]}
404
- </button>
405
- `;
485
+ /** Closes all of the sorting dropdown components' menus */
486
+ closeDropdowns() {
487
+ this.dropdownBackdropVisible = false;
488
+ const allDropdowns = [
489
+ this.viewsDropdown,
490
+ this.dateDropdown,
491
+ this.mobileDropdown,
492
+ ];
493
+ for (const dropdown of allDropdowns) {
494
+ dropdown.open = false;
495
+ dropdown.classList.remove('open');
496
+ }
406
497
  }
407
- selectDateSort(sortField) {
408
- this.dateSortSelectorVisible = false;
409
- this.viewSortSelectorVisible = false;
498
+ selectDropdownSortField(sortField) {
499
+ // When a dropdown sort option is selected, we additionally need to clear the backdrop
500
+ this.dropdownBackdropVisible = false;
410
501
  this.setSelectedSort(sortField);
411
502
  }
412
- setSortDirections(sortDirection) {
503
+ clearAlphaBarFilters() {
504
+ this.alphaSelectorVisible = null;
505
+ this.selectedTitleFilter = null;
506
+ this.selectedCreatorFilter = null;
507
+ }
508
+ setSortDirection(sortDirection) {
413
509
  this.sortDirection = sortDirection;
414
510
  this.emitSortChangedEvent();
415
511
  }
512
+ /** Toggles the current sort direction between 'asc' and 'desc' */
513
+ toggleSortDirection() {
514
+ this.setSortDirection(this.sortDirection === 'desc' ? 'asc' : 'desc');
515
+ }
416
516
  setSelectedSort(sort) {
417
517
  this.selectedSort = sort;
518
+ // Apply this field's default sort direction
519
+ this.sortDirection = DefaultSortDirection[this.selectedSort];
418
520
  this.emitSortChangedEvent();
419
521
  }
420
522
  /**
@@ -547,57 +649,58 @@ SortFilterBar.styles = css `
547
649
  #sort-bar {
548
650
  display: flex;
549
651
  justify-content: space-between;
550
- border: 1px solid rgb(232, 232, 232);
551
652
  align-items: center;
552
- padding: 0.5rem 1.5rem;
553
- }
554
-
555
- #sort-direction-container {
556
- flex: 0;
557
- }
558
-
559
- #sort-by-text {
560
- text-transform: uppercase;
561
- }
562
-
563
- #bottom-shadow {
564
- height: 1px;
565
- width: 100%;
566
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
567
- background-color: #bbb;
653
+ border-bottom: 1px solid #2c2c2c;
654
+ font-size: 1.4rem;
568
655
  }
569
656
 
570
657
  ul {
571
658
  list-style: none;
572
659
  display: flex;
660
+ align-items: center;
573
661
  margin: 0;
574
662
  padding: 0;
575
- align-items: center;
576
663
  }
577
664
 
578
665
  li {
579
666
  padding: 0;
580
667
  }
581
668
 
582
- .sort-button {
583
- background: none;
584
- color: inherit;
585
- border: none;
669
+ .sort-by-text {
670
+ margin-right: 5px;
671
+ font-weight: bold;
672
+ white-space: nowrap;
673
+ }
674
+
675
+ .sort-direction-container {
676
+ display: flex;
677
+ align-self: stretch;
678
+ flex: 0;
679
+ margin: 0 5px;
680
+ }
681
+
682
+ .sort-direction-selector {
586
683
  padding: 0;
684
+ border: none;
685
+ appearance: none;
686
+ background: transparent;
587
687
  cursor: pointer;
588
- outline: inherit;
589
- width: 12px;
590
- height: 12px;
591
- opacity: 0.5;
592
688
  }
593
689
 
594
- .sort-button.selected {
595
- opacity: 1;
690
+ .sort-direction-selector:disabled {
691
+ cursor: default;
596
692
  }
597
693
 
598
- .sort-button:disabled {
599
- opacity: 0.25;
600
- cursor: default;
694
+ .sort-direction-icon {
695
+ display: flex;
696
+ align-items: center;
697
+ background: none;
698
+ color: inherit;
699
+ border: none;
700
+ padding: 0;
701
+ outline: inherit;
702
+ width: 14px;
703
+ height: 14px;
601
704
  }
602
705
 
603
706
  #date-sort-selector,
@@ -613,77 +716,45 @@ SortFilterBar.styles = css `
613
716
  border: 1px solid #404142;
614
717
  }
615
718
 
616
- #date-sort-selector button,
617
- #view-sort-selector button {
618
- background: none;
619
- border-radius: 15px;
620
- color: #404142;
621
- border: none;
622
- appearance: none;
623
- cursor: pointer;
624
- -webkit-appearance: none;
625
- font-size: 1.4rem;
626
- font-weight: 400;
627
- padding: 0.5rem 1.2rem;
628
- }
629
-
630
- #date-sort-selector button.selected,
631
- #view-sort-selector button.selected {
632
- background-color: #404142;
633
- color: white;
634
- }
635
-
636
- #show-details {
637
- text-transform: uppercase;
638
- cursor: pointer;
719
+ #sort-selector-container {
720
+ flex: 1;
639
721
  display: flex;
722
+ justify-content: flex-start;
723
+ align-items: center;
640
724
  }
641
725
 
642
- #show-details input {
643
- margin-right: 0.5rem;
644
- flex: 0 0 12px;
645
- }
646
-
647
- #sort-descending-btn {
648
- transform: rotate(180deg);
649
- }
650
-
651
- #sort-direction-selector {
726
+ #desktop-sort-container,
727
+ #mobile-sort-container {
652
728
  display: flex;
653
- flex-direction: column;
654
- gap: 3px;
655
- margin-right: 1rem;
656
- }
657
-
658
- #sort-selector-container {
659
- flex: 1;
729
+ justify-content: flex-start;
730
+ align-items: center;
660
731
  }
661
732
 
662
733
  /*
663
734
  we move the desktop sort selector offscreen instead of display: none
664
735
  because we need to observe the width of it vs its container to determine
665
- if it's wide enough to display the desktop version and if you displY: none,
736
+ if it's wide enough to display the desktop version and if you display: none,
666
737
  the width becomes 0
667
738
  */
668
- #desktop-sort-selector.hidden {
739
+ #desktop-sort-container.hidden {
669
740
  position: absolute;
670
741
  top: -9999px;
671
742
  left: -9999px;
743
+ visibility: hidden;
672
744
  }
673
745
 
674
- #mobile-sort-selector.hidden {
746
+ #mobile-sort-container.hidden {
675
747
  display: none;
676
748
  }
677
749
 
678
- #date-sort-selector-backdrop,
679
- #view-sort-selector-backdrop {
750
+ #sort-selector-backdrop {
680
751
  position: fixed;
681
752
  top: 0;
682
753
  left: 0;
683
- width: 100%;
684
- height: 100%;
754
+ width: 100vw;
755
+ height: 100vh;
685
756
  z-index: 1;
686
- background-color: rgba(255, 255, 255, 0.5);
757
+ background-color: transparent;
687
758
  }
688
759
 
689
760
  #desktop-sort-selector {
@@ -693,34 +764,21 @@ SortFilterBar.styles = css `
693
764
  #desktop-sort-selector li {
694
765
  display: flex;
695
766
  align-items: center;
767
+ padding-left: 5px;
768
+ padding-right: 5px;
696
769
  }
697
770
 
698
771
  #desktop-sort-selector li a {
772
+ padding: 0 5px;
699
773
  text-decoration: none;
700
- text-transform: uppercase;
701
- font-size: 1.4rem;
702
774
  color: #333;
703
- line-height: 2.5;
775
+ line-height: 2;
704
776
  }
705
777
 
706
778
  #desktop-sort-selector li a.selected {
707
779
  font-weight: bold;
708
780
  }
709
781
 
710
- #desktop-sort-selector li::after {
711
- content: '•';
712
- padding-left: 1rem;
713
- padding-right: 1rem;
714
- }
715
-
716
- #desktop-sort-selector li:first-child::after {
717
- content: '';
718
- }
719
-
720
- #desktop-sort-selector li:last-child::after {
721
- content: '';
722
- }
723
-
724
782
  #display-style-selector {
725
783
  flex: 0;
726
784
  }
@@ -732,17 +790,50 @@ SortFilterBar.styles = css `
732
790
  appearance: none;
733
791
  cursor: pointer;
734
792
  -webkit-appearance: none;
735
- opacity: 0.5;
793
+ fill: #bbbbbb;
736
794
  }
737
795
 
738
796
  #display-style-selector button.active {
739
- opacity: 1;
797
+ fill: var(--ia-theme-primary-text-color, #2c2c2c);
740
798
  }
741
799
 
742
800
  #display-style-selector button svg {
743
801
  width: 24px;
744
802
  height: 24px;
745
803
  }
804
+
805
+ ia-dropdown {
806
+ --dropdownTextColor: white;
807
+ --dropdownOffsetTop: 0;
808
+ --dropdownBorderTopWidth: 0;
809
+ --dropdownBorderTopLeftRadius: 0;
810
+ --dropdownBorderTopRightRadius: 0;
811
+ --dropdownWhiteSpace: nowrap;
812
+ --dropdownListZIndex: 2;
813
+ --dropdownCaretColor: var(--ia-theme-primary-text-color, #2c2c2c);
814
+ --dropdownSelectedTextColor: white;
815
+ --dropdownSelectedBgColor: rgba(255, 255, 255, 0.3);
816
+ --dropdownHoverBgColor: rgba(255, 255, 255, 0.3);
817
+ --caretHeight: 9px;
818
+ --caretWidth: 12px;
819
+ --caretPadding: 0 5px 0 0;
820
+ }
821
+ ia-dropdown.selected .dropdown-label {
822
+ font-weight: bold;
823
+ }
824
+ ia-dropdown.open {
825
+ z-index: 2;
826
+ }
827
+
828
+ .dropdown-label {
829
+ display: inline-block;
830
+ height: 100%;
831
+ padding-left: 5px;
832
+ font-size: 1.4rem;
833
+ line-height: 2;
834
+ color: var(--ia-theme-primary-text-color, #2c2c2c);
835
+ white-space: nowrap;
836
+ }
746
837
  `;
747
838
  __decorate([
748
839
  property({ type: String })
@@ -773,25 +864,28 @@ __decorate([
773
864
  ], SortFilterBar.prototype, "alphaSelectorVisible", void 0);
774
865
  __decorate([
775
866
  state()
776
- ], SortFilterBar.prototype, "dateSortSelectorVisible", void 0);
867
+ ], SortFilterBar.prototype, "dropdownBackdropVisible", void 0);
777
868
  __decorate([
778
869
  state()
779
- ], SortFilterBar.prototype, "viewSortSelectorVisible", void 0);
780
- __decorate([
781
- state()
782
- ], SortFilterBar.prototype, "desktopSelectorBarWidth", void 0);
870
+ ], SortFilterBar.prototype, "desktopSortContainerWidth", void 0);
783
871
  __decorate([
784
872
  state()
785
873
  ], SortFilterBar.prototype, "selectorBarContainerWidth", void 0);
786
874
  __decorate([
787
- state()
788
- ], SortFilterBar.prototype, "hoveringOverDateSortOptions", void 0);
789
- __decorate([
790
- query('#desktop-sort-selector')
791
- ], SortFilterBar.prototype, "desktopSortSelector", void 0);
875
+ query('#desktop-sort-container')
876
+ ], SortFilterBar.prototype, "desktopSortContainer", void 0);
792
877
  __decorate([
793
878
  query('#sort-selector-container')
794
879
  ], SortFilterBar.prototype, "sortSelectorContainer", void 0);
880
+ __decorate([
881
+ query('#views-dropdown')
882
+ ], SortFilterBar.prototype, "viewsDropdown", void 0);
883
+ __decorate([
884
+ query('#date-dropdown')
885
+ ], SortFilterBar.prototype, "dateDropdown", void 0);
886
+ __decorate([
887
+ query('#mobile-dropdown')
888
+ ], SortFilterBar.prototype, "mobileDropdown", void 0);
795
889
  SortFilterBar = __decorate([
796
890
  customElement('sort-filter-bar')
797
891
  ], SortFilterBar);