@internetarchive/collection-browser 4.1.0 → 4.2.0-alpha-webdev8164.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.
Files changed (62) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +1 -1
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/src/collection-browser.js +761 -761
  11. package/dist/src/collection-browser.js.map +1 -1
  12. package/dist/src/collection-facets/facets-template.js +5 -0
  13. package/dist/src/collection-facets/facets-template.js.map +1 -1
  14. package/dist/src/collection-facets/more-facets-content.d.ts +92 -8
  15. package/dist/src/collection-facets/more-facets-content.js +526 -84
  16. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  17. package/dist/src/collection-facets/more-facets-pagination.d.ts +12 -3
  18. package/dist/src/collection-facets/more-facets-pagination.js +69 -8
  19. package/dist/src/collection-facets/more-facets-pagination.js.map +1 -1
  20. package/dist/src/collection-facets/toggle-switch.js +1 -0
  21. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  22. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  23. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  24. package/dist/src/sort-filter-bar/sort-filter-bar.js +280 -280
  25. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  26. package/dist/test/collection-browser.test.js +189 -189
  27. package/dist/test/collection-browser.test.js.map +1 -1
  28. package/dist/test/collection-facets/more-facets-content.test.js +162 -3
  29. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  30. package/dist/test/collection-facets/more-facets-pagination.test.js +63 -3
  31. package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -1
  32. package/dist/test/mocks/mock-search-responses.d.ts +5 -0
  33. package/dist/test/mocks/mock-search-responses.js +44 -0
  34. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  35. package/dist/test/mocks/mock-search-service.js +2 -1
  36. package/dist/test/mocks/mock-search-service.js.map +1 -1
  37. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +22 -22
  38. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  39. package/eslint.config.mjs +53 -53
  40. package/index.html +24 -24
  41. package/local.archive.org.cert +86 -86
  42. package/local.archive.org.key +27 -27
  43. package/package.json +121 -120
  44. package/renovate.json +6 -6
  45. package/src/collection-browser.ts +3070 -3070
  46. package/src/collection-facets/facets-template.ts +5 -0
  47. package/src/collection-facets/more-facets-content.ts +566 -96
  48. package/src/collection-facets/more-facets-pagination.ts +80 -9
  49. package/src/collection-facets/toggle-switch.ts +1 -0
  50. package/src/data-source/collection-browser-data-source.ts +1444 -1444
  51. package/src/data-source/collection-browser-query-state.ts +60 -60
  52. package/src/sort-filter-bar/sort-filter-bar.ts +733 -733
  53. package/test/collection-browser.test.ts +2402 -2402
  54. package/test/collection-facets/more-facets-content.test.ts +251 -4
  55. package/test/collection-facets/more-facets-pagination.test.ts +87 -3
  56. package/test/mocks/mock-search-responses.ts +48 -0
  57. package/test/mocks/mock-search-service.ts +2 -0
  58. package/test/sort-filter-bar/sort-filter-bar.test.ts +443 -443
  59. package/tsconfig.json +25 -25
  60. package/web-dev-server.config.mjs +30 -30
  61. package/web-test-runner.config.mjs +52 -52
  62. package/.claude/settings.local.json +0 -8
@@ -1,733 +1,733 @@
1
- import {
2
- LitElement,
3
- html,
4
- css,
5
- nothing,
6
- PropertyValues,
7
- TemplateResult,
8
- } from 'lit';
9
- import { customElement, property, query, state } from 'lit/decorators.js';
10
- import { msg, str } from '@lit/localize';
11
- import type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';
12
- import type { SortDirection } from '@internetarchive/search-service';
13
- import {
14
- CollectionDisplayMode,
15
- defaultSortAvailability,
16
- PrefixFilterCounts,
17
- PrefixFilterType,
18
- SORT_OPTIONS,
19
- SortField,
20
- SortOption,
21
- } from '../models';
22
-
23
- import { sortUpIcon } from './img/sort-toggle-up';
24
- import { sortDownIcon } from './img/sort-toggle-down';
25
- import { sortDisabledIcon } from './img/sort-toggle-disabled';
26
- import { tileIcon } from './img/tile';
27
- import { listIcon } from './img/list';
28
- import { compactIcon } from './img/compact';
29
- import { srOnlyStyle } from '../styles/sr-only';
30
-
31
- import '@internetarchive/ia-dropdown';
32
- import './alpha-bar';
33
-
34
- type AlphaSelector = 'creator' | 'title';
35
-
36
- @customElement('sort-filter-bar')
37
- export class SortFilterBar extends LitElement {
38
- /** Which display mode the tiles are being rendered with (grid/list-detail/list-compact) */
39
- @property({ type: String }) displayMode?: CollectionDisplayMode;
40
-
41
- /** The default sort direction to use if none is set */
42
- @property({ type: String }) defaultSortDirection: SortDirection | null = null;
43
-
44
- /** The default sort field to use if none is set */
45
- @property({ type: String }) defaultSortField: Exclude<
46
- SortField,
47
- SortField.default
48
- > = SortField.relevance;
49
-
50
- /** The current sort direction (asc/desc), or null if none is set */
51
- @property({ type: String }) sortDirection: SortDirection | null = null;
52
-
53
- /** The field currently being sorted on (e.g., 'title'). Defaults to relevance. */
54
- @property({ type: String }) selectedSort: SortField = SortField.default;
55
-
56
- /** The currently selected title letter filter, or null if none is set */
57
- @property({ type: String }) selectedTitleFilter: string | null = null;
58
-
59
- /** The currently selected creator letter filter, or null if none is set */
60
- @property({ type: String }) selectedCreatorFilter: string | null = null;
61
-
62
- /**
63
- * Map defining which sortable fields should be included on the sort bar.
64
- *
65
- * E.g.,
66
- * ```
67
- * {
68
- * [SortField.relevance]: true,
69
- * [SortField.date]: false,
70
- * [SortField.title]: true,
71
- * ...
72
- * }
73
- * ```
74
- */
75
- @property({ type: Object }) sortFieldAvailability = defaultSortAvailability;
76
-
77
- /** Whether to replace the default sort options with a slot for customization (default `false`) */
78
- @property({ type: Boolean, reflect: true }) enableSortOptionsSlot: boolean =
79
- false;
80
-
81
- /** Whether to suppress showing the three display mode options on the right of the bar (default `false`) */
82
- @property({ type: Boolean, reflect: true })
83
- suppressDisplayModes: boolean = false;
84
-
85
- /** Maps of result counts for letters on the alphabet bar, for each letter filter type */
86
- @property({ type: Object }) prefixFilterCountMap?: Record<
87
- PrefixFilterType,
88
- PrefixFilterCounts
89
- >;
90
-
91
- /**
92
- * Which of the alphabet bars (title/creator) should be shown, or null if one
93
- * should not currently be rendered.
94
- */
95
- @state() alphaSelectorVisible: AlphaSelector | null = null;
96
-
97
- /**
98
- * Whether the transparent backdrop to catch clicks outside the dropdown menu
99
- * should be rendered.
100
- */
101
- @state() dropdownBackdropVisible = false;
102
-
103
- /** The single, consolidated dropdown component containing all available options */
104
- @query('#sort-dropdown')
105
- private sortOptionsDropdown!: IaDropdown;
106
-
107
- render() {
108
- return html`
109
- <div id="container">
110
- <section id="sort-bar" aria-label="Sorting options">
111
- <slot name="sort-options-left"></slot>
112
- <div id="sort-options">
113
- ${!this.enableSortOptionsSlot
114
- ? html`
115
- <div class="sort-direction-container">
116
- ${this.sortDirectionSelectorTemplate}
117
- </div>
118
- <span class="sort-by-text">${msg('Sort by:')}</span>
119
- <div id="sort-selector-container">
120
- ${this.sortSelectorTemplate}
121
- </div>
122
- `
123
- : html`<slot name="sort-options"></slot>`}
124
- </div>
125
- <slot name="sort-options-right"></slot>
126
-
127
- ${this.suppressDisplayModes
128
- ? nothing
129
- : html`<div id="display-style-selector">
130
- ${this.displayOptionTemplate}
131
- </div>`}
132
- </section>
133
-
134
- ${this.dropdownBackdropVisible ? this.dropdownBackdrop : nothing}
135
- ${this.alphaBarTemplate}
136
- </div>
137
- `;
138
- }
139
-
140
- willUpdate(changed: PropertyValues) {
141
- if (changed.has('selectedSort') || changed.has('defaultSortField')) {
142
- // If the sort is changed from its default without a direction set,
143
- // we adopt the default sort direction for that sort type.
144
- if (
145
- this.selectedSort &&
146
- this.selectedSort !== SortField.default &&
147
- this.sortDirection === null
148
- ) {
149
- const sortOption = SORT_OPTIONS[this.finalizedSortField];
150
- this.sortDirection = sortOption.defaultSortDirection;
151
- }
152
- }
153
- }
154
-
155
- updated(changed: PropertyValues) {
156
- if (changed.has('displayMode')) {
157
- this.displayModeChanged();
158
- }
159
-
160
- if (changed.has('selectedTitleFilter') && this.selectedTitleFilter) {
161
- this.alphaSelectorVisible = 'title';
162
- }
163
-
164
- if (changed.has('selectedCreatorFilter') && this.selectedCreatorFilter) {
165
- this.alphaSelectorVisible = 'creator';
166
- }
167
-
168
- if (changed.has('dropdownBackdropVisible')) {
169
- this.setupEscapeListeners();
170
- }
171
- }
172
-
173
- private setupEscapeListeners() {
174
- if (this.dropdownBackdropVisible) {
175
- document.addEventListener(
176
- 'keydown',
177
- this.boundSortBarSelectorEscapeListener,
178
- );
179
- } else {
180
- document.removeEventListener(
181
- 'keydown',
182
- this.boundSortBarSelectorEscapeListener,
183
- );
184
- }
185
- }
186
-
187
- private boundSortBarSelectorEscapeListener = (e: KeyboardEvent) => {
188
- if (e.key === 'Escape') {
189
- this.closeDropdown();
190
- }
191
- };
192
-
193
- /**
194
- * Template to render the alphabet bar, or `nothing` if it should not be rendered
195
- * for the current sort
196
- */
197
- private get alphaBarTemplate(): TemplateResult | typeof nothing {
198
- if (!['title', 'creator'].includes(this.selectedSort)) return nothing;
199
-
200
- if (this.alphaSelectorVisible === null) {
201
- if (this.selectedSort === 'creator') return this.creatorSelectorBar;
202
- if (this.selectedSort === 'title') return this.titleSelectorBar;
203
- } else {
204
- return this.alphaSelectorVisible === 'creator'
205
- ? this.creatorSelectorBar
206
- : this.titleSelectorBar;
207
- }
208
-
209
- return nothing;
210
- }
211
-
212
- /** Template to render the sort direction toggle button */
213
- private get sortDirectionSelectorTemplate(): TemplateResult {
214
- const oppositeSortDirectionReadable =
215
- this.sortDirection === 'asc' ? msg('descending') : msg('ascending');
216
- const buttonLabel = this.canChangeSortDirection
217
- ? msg(str`Change to ${oppositeSortDirectionReadable} sort`)
218
- : msg('Directions are not available for the current sort option');
219
-
220
- return html`
221
- <button
222
- class="sort-direction-selector"
223
- title=${buttonLabel}
224
- ?disabled=${!this.canChangeSortDirection}
225
- @click=${this.handleSortDirectionClicked}
226
- >
227
- <span class="sr-only">${buttonLabel}</span>
228
- ${this.sortDirectionIcon}
229
- </button>
230
- `;
231
- }
232
-
233
- /** Template to render the sort direction button's icon in the correct current state */
234
- private get sortDirectionIcon(): TemplateResult {
235
- // Show a fully disabled icon for sort options without direction support
236
- if (!this.canChangeSortDirection) {
237
- return html`<div class="sort-direction-icon">${sortDisabledIcon}</div>`;
238
- }
239
-
240
- // For all other sorts, show the ascending/descending direction
241
- return html`
242
- <div class="sort-direction-icon">
243
- ${this.finalizedSortDirection === 'asc' ? sortUpIcon : sortDownIcon}
244
- </div>
245
- `;
246
- }
247
-
248
- /** The template to render all the sort options in a single dropdown */
249
- private get sortSelectorTemplate() {
250
- const displayedOptions = Object.values(SORT_OPTIONS).filter(
251
- opt => opt.shownInSortBar && this.sortFieldAvailability[opt.field],
252
- );
253
-
254
- return html`
255
- <div id="sort-dropdown-container">
256
- ${this.getSortDropdown({
257
- displayName: SORT_OPTIONS[this.finalizedSortField].displayName,
258
- id: 'sort-dropdown',
259
- selected: true,
260
- dropdownOptions: displayedOptions.map(opt =>
261
- this.getDropdownOption(opt.field),
262
- ),
263
- selectedOption: this.finalizedSortField,
264
- onOptionSelected: this.sortOptionSelected,
265
- onDropdownClick: () => {
266
- this.dropdownBackdropVisible = this.sortOptionsDropdown.open;
267
- this.sortOptionsDropdown.classList.toggle(
268
- 'open',
269
- this.sortOptionsDropdown.open,
270
- );
271
- },
272
- })}
273
- </div>
274
- `;
275
- }
276
-
277
- /**
278
- * Generates a dropdown component containing multiple grouped sort options.
279
- *
280
- * @param options.displayName The name to use for the dropdown's visible label
281
- * @param options.id The id to apply to the dropdown element
282
- * @param options.dropdownOptions An array of option objects used to populate the dropdown
283
- * @param options.selectedOption The id of the option that should be initially selected
284
- * @param options.selected A boolean indicating whether this dropdown should use its
285
- * selected appearance
286
- * @param options.onOptionSelected A handler for optionSelected events coming from the dropdown
287
- * @param options.onDropdownClick A handler for click events on the dropdown
288
- */
289
- private getSortDropdown(options: {
290
- displayName: string;
291
- id: string;
292
- dropdownOptions: optionInterface[];
293
- selectedOption?: string;
294
- selected: boolean;
295
- onOptionSelected?: (e: CustomEvent<{ option: optionInterface }>) => void;
296
- onDropdownClick?: (e: PointerEvent) => void;
297
- }): TemplateResult {
298
- return html`
299
- <ia-dropdown
300
- id=${options.id}
301
- class=${options.selected ? 'selected' : ''}
302
- displayCaret
303
- closeOnSelect
304
- includeSelectedOption
305
- .openViaButton=${options.selected}
306
- .options=${options.dropdownOptions}
307
- .selectedOption=${options.selectedOption ?? ''}
308
- @optionSelected=${options.onOptionSelected ?? nothing}
309
- @click=${options.onDropdownClick ?? nothing}
310
- >
311
- <span
312
- class="dropdown-label"
313
- slot="dropdown-label"
314
- data-title=${options.displayName}
315
- >
316
- ${options.displayName}
317
- </span>
318
- </ia-dropdown>
319
- `;
320
- }
321
-
322
- /** Generates a single dropdown option object for the given sort field */
323
- private getDropdownOption(sortField: SortField): optionInterface {
324
- return {
325
- id: sortField,
326
- label: html`
327
- <span class="dropdown-option-label">
328
- ${SORT_OPTIONS[sortField].displayName}
329
- </span>
330
- `,
331
- };
332
- }
333
-
334
- /** Handler for when a new sort dropdown option is selected */
335
- private sortOptionSelected(e: CustomEvent<{ option: optionInterface }>) {
336
- this.dropdownBackdropVisible = false;
337
-
338
- const sortField = e.detail.option.id as SortField;
339
- this.setSelectedSort(sortField);
340
-
341
- this.alphaSelectorVisible = null;
342
- if (sortField !== 'title' && this.selectedTitleFilter) {
343
- this.selectedTitleFilter = null;
344
- this.emitTitleLetterChangedEvent();
345
- }
346
- if (sortField !== 'creator' && this.selectedCreatorFilter) {
347
- this.selectedCreatorFilter = null;
348
- this.emitCreatorLetterChangedEvent();
349
- }
350
- }
351
-
352
- /** Template for rendering the three display mode options */
353
- /** Added data-testid for Playwright testing * */
354
- private get displayOptionTemplate() {
355
- return html`
356
- <ul>
357
- <li>
358
- <button
359
- id="grid-button"
360
- @click=${() => {
361
- this.displayMode = 'grid';
362
- }}
363
- class=${this.displayMode === 'grid' ? 'active' : ''}
364
- title="Tile view"
365
- data-testid="grid-button"
366
- >
367
- ${tileIcon}
368
- </button>
369
- </li>
370
- <li>
371
- <button
372
- id="list-detail-button"
373
- @click=${() => {
374
- this.displayMode = 'list-detail';
375
- }}
376
- class=${this.displayMode === 'list-detail' ? 'active' : ''}
377
- title="List view"
378
- data-testid="list-detail-button"
379
- >
380
- ${listIcon}
381
- </button>
382
- </li>
383
- <li>
384
- <button
385
- id="list-compact-button"
386
- @click=${() => {
387
- this.displayMode = 'list-compact';
388
- }}
389
- class=${this.displayMode === 'list-compact' ? 'active' : ''}
390
- title="Compact list view"
391
- data-testid="list-compact-button"
392
- >
393
- ${compactIcon}
394
- </button>
395
- </li>
396
- </ul>
397
- `;
398
- }
399
-
400
- /**
401
- * Template for rendering the transparent backdrop to capture clicks outside the
402
- * dropdown menu while it is open.
403
- */
404
- private get dropdownBackdrop() {
405
- return html`
406
- <div
407
- id="sort-selector-backdrop"
408
- @keyup=${this.closeDropdown}
409
- @click=${this.closeDropdown}
410
- ></div>
411
- `;
412
- }
413
-
414
- /** Closes the sorting dropdown component's menus */
415
- private closeDropdown() {
416
- this.dropdownBackdropVisible = false;
417
-
418
- if (!this.sortOptionsDropdown) return;
419
- this.sortOptionsDropdown.open = false;
420
- this.sortOptionsDropdown.classList.remove('open');
421
- }
422
-
423
- setSortDirection(sortDirection: SortDirection) {
424
- this.sortDirection = sortDirection;
425
- this.emitSortChangedEvent();
426
- }
427
-
428
- /** Toggles the current sort direction between 'asc' and 'desc' */
429
- private toggleSortDirection() {
430
- this.setSortDirection(
431
- this.finalizedSortDirection === 'desc' ? 'asc' : 'desc',
432
- );
433
- }
434
-
435
- private handleSortDirectionClicked(): void {
436
- if (
437
- !this.sortDirection &&
438
- this.defaultSortField &&
439
- this.defaultSortDirection
440
- ) {
441
- // When the sort direction is merely defaulted (not set by the user), clicking
442
- // the toggled button should "promote" the default sort to an explicitly-set one
443
- // and then toggle it as usual.
444
- this.selectedSort = this.defaultSortField;
445
- this.sortDirection = this.defaultSortDirection;
446
- }
447
-
448
- this.toggleSortDirection();
449
- }
450
-
451
- setSelectedSort(sort: SortField) {
452
- this.selectedSort = sort;
453
- // Apply this field's default sort direction
454
- const sortOption = SORT_OPTIONS[sort];
455
- this.sortDirection = sortOption.defaultSortDirection;
456
- this.emitSortChangedEvent();
457
- }
458
-
459
- /** The current sort field, or the default one if no explicit sort is set */
460
- private get finalizedSortField(): SortField {
461
- const resolvedField =
462
- this.selectedSort === SortField.default
463
- ? this.defaultSortField
464
- : this.selectedSort;
465
- if (this.sortFieldAvailability[resolvedField]) return resolvedField;
466
-
467
- // Fall back to the first available sort option shown in the sort bar, if
468
- // the requested one isn't available
469
- return this.firstAvailableOption?.field ?? resolvedField;
470
- }
471
-
472
- /** The current sort direction, or the default one if no explicit direction is set */
473
- private get finalizedSortDirection(): SortDirection | null {
474
- return this.sortDirection === null
475
- ? this.defaultSortDirection
476
- : this.sortDirection;
477
- }
478
-
479
- /** The first option shown in the sort dropdown, or undefined if none are available */
480
- private get firstAvailableOption(): SortOption | undefined {
481
- return Object.values(SORT_OPTIONS).find(
482
- opt => opt.shownInSortBar && this.sortFieldAvailability[opt.field],
483
- );
484
- }
485
-
486
- /** Whether the sort direction button should be enabled for the current sort */
487
- private get canChangeSortDirection(): boolean {
488
- return SORT_OPTIONS[this.finalizedSortField].canSetDirection;
489
- }
490
-
491
- private get titleSelectorBar() {
492
- return html` <alpha-bar
493
- .selectedLetter=${this.selectedTitleFilter}
494
- .letterCounts=${this.prefixFilterCountMap?.title}
495
- ariaLandmarkLabel="Filter by title letter"
496
- @letterChanged=${this.titleLetterChanged}
497
- ></alpha-bar>`;
498
- }
499
-
500
- private get creatorSelectorBar() {
501
- return html` <alpha-bar
502
- .selectedLetter=${this.selectedCreatorFilter}
503
- .letterCounts=${this.prefixFilterCountMap?.creator}
504
- ariaLandmarkLabel="Filter by creator letter"
505
- @letterChanged=${this.creatorLetterChanged}
506
- ></alpha-bar>`;
507
- }
508
-
509
- private titleLetterChanged(
510
- e: CustomEvent<{ selectedLetter: string | undefined }>,
511
- ) {
512
- this.selectedTitleFilter = e.detail.selectedLetter ?? null;
513
- this.emitTitleLetterChangedEvent();
514
- }
515
-
516
- private creatorLetterChanged(
517
- e: CustomEvent<{ selectedLetter: string | undefined }>,
518
- ) {
519
- this.selectedCreatorFilter = e.detail.selectedLetter ?? null;
520
- this.emitCreatorLetterChangedEvent();
521
- }
522
-
523
- private emitTitleLetterChangedEvent() {
524
- const event = new CustomEvent<{ selectedLetter: string | null }>(
525
- 'titleLetterChanged',
526
- {
527
- detail: { selectedLetter: this.selectedTitleFilter },
528
- },
529
- );
530
- this.dispatchEvent(event);
531
- }
532
-
533
- private emitCreatorLetterChangedEvent() {
534
- const event = new CustomEvent<{ selectedLetter: string | null }>(
535
- 'creatorLetterChanged',
536
- {
537
- detail: { selectedLetter: this.selectedCreatorFilter },
538
- },
539
- );
540
- this.dispatchEvent(event);
541
- }
542
-
543
- private displayModeChanged() {
544
- const event = new CustomEvent<{
545
- displayMode?: CollectionDisplayMode;
546
- }>('displayModeChanged', {
547
- detail: { displayMode: this.displayMode },
548
- });
549
- this.dispatchEvent(event);
550
- }
551
-
552
- private emitSortChangedEvent() {
553
- const event = new CustomEvent<{
554
- selectedSort: SortField;
555
- sortDirection: SortDirection | null;
556
- }>('sortChanged', {
557
- detail: {
558
- selectedSort: this.selectedSort,
559
- sortDirection: this.sortDirection,
560
- },
561
- });
562
- this.dispatchEvent(event);
563
- }
564
-
565
- static get styles() {
566
- const disabledIconColor = css`#bbbbbb`;
567
-
568
- return [
569
- srOnlyStyle,
570
- css`
571
- #container {
572
- position: relative;
573
- }
574
-
575
- #sort-bar {
576
- display: flex;
577
- justify-content: flex-start;
578
- align-items: center;
579
- padding-bottom: 1px;
580
- border-bottom: 1px solid #2c2c2c;
581
- font-size: 1.4rem;
582
- }
583
-
584
- #sort-options {
585
- display: flex;
586
- align-items: center;
587
- flex-grow: 1;
588
- }
589
-
590
- ul {
591
- list-style: none;
592
- display: flex;
593
- align-items: center;
594
- margin: 0;
595
- padding: 0;
596
- }
597
-
598
- li {
599
- padding: 0;
600
- }
601
-
602
- .sort-by-text {
603
- margin-right: 5px;
604
- font-weight: bold;
605
- white-space: nowrap;
606
- }
607
-
608
- .sort-direction-container {
609
- display: flex;
610
- align-self: stretch;
611
- flex: 0;
612
- margin: 0 3px;
613
- }
614
-
615
- .sort-direction-selector {
616
- display: flex;
617
- justify-content: center;
618
- width: 30px;
619
- margin: 0 5px 0 0;
620
- padding: 7px 8px;
621
- max-height: fit-content;
622
- border-radius: 5px;
623
- background: white;
624
- border: 1px solid rgb(25, 72, 128);
625
- appearance: none;
626
- cursor: pointer;
627
- }
628
-
629
- .sort-direction-selector:disabled {
630
- cursor: not-allowed;
631
- border-color: ${disabledIconColor};
632
- }
633
-
634
- .sort-direction-icon {
635
- display: flex;
636
- align-items: center;
637
- background: none;
638
- color: inherit;
639
- border: none;
640
- padding: 0;
641
- outline: inherit;
642
- width: 12px;
643
- height: 12px;
644
- }
645
-
646
- .sort-direction-icon > svg {
647
- flex: 1;
648
- }
649
-
650
- #sort-selector-container {
651
- flex: 1;
652
- display: flex;
653
- justify-content: flex-start;
654
- align-items: center;
655
- }
656
-
657
- #sort-dropdown-container {
658
- display: flex;
659
- justify-content: flex-start;
660
- align-items: center;
661
- }
662
-
663
- #sort-selector-backdrop {
664
- position: fixed;
665
- top: 0;
666
- left: 0;
667
- width: 100vw;
668
- height: 100vh;
669
- z-index: 1;
670
- background-color: transparent;
671
- }
672
-
673
- #display-style-selector {
674
- flex: 0;
675
- }
676
-
677
- #display-style-selector button {
678
- background: none;
679
- color: inherit;
680
- border: none;
681
- appearance: none;
682
- cursor: pointer;
683
- -webkit-appearance: none;
684
- fill: ${disabledIconColor};
685
- }
686
-
687
- #display-style-selector button.active {
688
- fill: var(--ia-theme-primary-text-color, #2c2c2c);
689
- }
690
-
691
- #display-style-selector button svg {
692
- width: 24px;
693
- height: 24px;
694
- }
695
-
696
- ia-dropdown {
697
- --dropdownTextColor: white;
698
- --dropdownOffsetTop: 0;
699
- --dropdownBorderTopWidth: 0;
700
- --dropdownBorderTopLeftRadius: 0;
701
- --dropdownBorderTopRightRadius: 0;
702
- --dropdownWhiteSpace: nowrap;
703
- --dropdownListZIndex: 2;
704
- --dropdownCaretColor: var(--ia-theme-primary-text-color, #2c2c2c);
705
- --dropdownSelectedTextColor: white;
706
- --dropdownSelectedBgColor: rgba(255, 255, 255, 0.3);
707
- --dropdownHoverBgColor: rgba(255, 255, 255, 0.3);
708
- --caretHeight: 9px;
709
- --caretWidth: 12px;
710
- --caretPadding: 0 5px 0 0;
711
- }
712
- ia-dropdown.selected .dropdown-label {
713
- font-weight: bold;
714
- }
715
- ia-dropdown.open {
716
- z-index: 2;
717
- }
718
-
719
- .dropdown-label {
720
- display: inline-block;
721
- height: 100%;
722
- padding-left: 5px;
723
- font-size: 1.4rem;
724
- font-family: var(--ia-theme-base-font-family);
725
- line-height: 2;
726
- color: var(--ia-theme-primary-text-color, #2c2c2c);
727
- white-space: nowrap;
728
- user-select: none;
729
- }
730
- `,
731
- ];
732
- }
733
- }
1
+ import {
2
+ LitElement,
3
+ html,
4
+ css,
5
+ nothing,
6
+ PropertyValues,
7
+ TemplateResult,
8
+ } from 'lit';
9
+ import { customElement, property, query, state } from 'lit/decorators.js';
10
+ import { msg, str } from '@lit/localize';
11
+ import type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';
12
+ import type { SortDirection } from '@internetarchive/search-service';
13
+ import {
14
+ CollectionDisplayMode,
15
+ defaultSortAvailability,
16
+ PrefixFilterCounts,
17
+ PrefixFilterType,
18
+ SORT_OPTIONS,
19
+ SortField,
20
+ SortOption,
21
+ } from '../models';
22
+
23
+ import { sortUpIcon } from './img/sort-toggle-up';
24
+ import { sortDownIcon } from './img/sort-toggle-down';
25
+ import { sortDisabledIcon } from './img/sort-toggle-disabled';
26
+ import { tileIcon } from './img/tile';
27
+ import { listIcon } from './img/list';
28
+ import { compactIcon } from './img/compact';
29
+ import { srOnlyStyle } from '../styles/sr-only';
30
+
31
+ import '@internetarchive/ia-dropdown';
32
+ import './alpha-bar';
33
+
34
+ type AlphaSelector = 'creator' | 'title';
35
+
36
+ @customElement('sort-filter-bar')
37
+ export class SortFilterBar extends LitElement {
38
+ /** Which display mode the tiles are being rendered with (grid/list-detail/list-compact) */
39
+ @property({ type: String }) displayMode?: CollectionDisplayMode;
40
+
41
+ /** The default sort direction to use if none is set */
42
+ @property({ type: String }) defaultSortDirection: SortDirection | null = null;
43
+
44
+ /** The default sort field to use if none is set */
45
+ @property({ type: String }) defaultSortField: Exclude<
46
+ SortField,
47
+ SortField.default
48
+ > = SortField.relevance;
49
+
50
+ /** The current sort direction (asc/desc), or null if none is set */
51
+ @property({ type: String }) sortDirection: SortDirection | null = null;
52
+
53
+ /** The field currently being sorted on (e.g., 'title'). Defaults to relevance. */
54
+ @property({ type: String }) selectedSort: SortField = SortField.default;
55
+
56
+ /** The currently selected title letter filter, or null if none is set */
57
+ @property({ type: String }) selectedTitleFilter: string | null = null;
58
+
59
+ /** The currently selected creator letter filter, or null if none is set */
60
+ @property({ type: String }) selectedCreatorFilter: string | null = null;
61
+
62
+ /**
63
+ * Map defining which sortable fields should be included on the sort bar.
64
+ *
65
+ * E.g.,
66
+ * ```
67
+ * {
68
+ * [SortField.relevance]: true,
69
+ * [SortField.date]: false,
70
+ * [SortField.title]: true,
71
+ * ...
72
+ * }
73
+ * ```
74
+ */
75
+ @property({ type: Object }) sortFieldAvailability = defaultSortAvailability;
76
+
77
+ /** Whether to replace the default sort options with a slot for customization (default `false`) */
78
+ @property({ type: Boolean, reflect: true }) enableSortOptionsSlot: boolean =
79
+ false;
80
+
81
+ /** Whether to suppress showing the three display mode options on the right of the bar (default `false`) */
82
+ @property({ type: Boolean, reflect: true })
83
+ suppressDisplayModes: boolean = false;
84
+
85
+ /** Maps of result counts for letters on the alphabet bar, for each letter filter type */
86
+ @property({ type: Object }) prefixFilterCountMap?: Record<
87
+ PrefixFilterType,
88
+ PrefixFilterCounts
89
+ >;
90
+
91
+ /**
92
+ * Which of the alphabet bars (title/creator) should be shown, or null if one
93
+ * should not currently be rendered.
94
+ */
95
+ @state() alphaSelectorVisible: AlphaSelector | null = null;
96
+
97
+ /**
98
+ * Whether the transparent backdrop to catch clicks outside the dropdown menu
99
+ * should be rendered.
100
+ */
101
+ @state() dropdownBackdropVisible = false;
102
+
103
+ /** The single, consolidated dropdown component containing all available options */
104
+ @query('#sort-dropdown')
105
+ private sortOptionsDropdown!: IaDropdown;
106
+
107
+ render() {
108
+ return html`
109
+ <div id="container">
110
+ <section id="sort-bar" aria-label="Sorting options">
111
+ <slot name="sort-options-left"></slot>
112
+ <div id="sort-options">
113
+ ${!this.enableSortOptionsSlot
114
+ ? html`
115
+ <div class="sort-direction-container">
116
+ ${this.sortDirectionSelectorTemplate}
117
+ </div>
118
+ <span class="sort-by-text">${msg('Sort by:')}</span>
119
+ <div id="sort-selector-container">
120
+ ${this.sortSelectorTemplate}
121
+ </div>
122
+ `
123
+ : html`<slot name="sort-options"></slot>`}
124
+ </div>
125
+ <slot name="sort-options-right"></slot>
126
+
127
+ ${this.suppressDisplayModes
128
+ ? nothing
129
+ : html`<div id="display-style-selector">
130
+ ${this.displayOptionTemplate}
131
+ </div>`}
132
+ </section>
133
+
134
+ ${this.dropdownBackdropVisible ? this.dropdownBackdrop : nothing}
135
+ ${this.alphaBarTemplate}
136
+ </div>
137
+ `;
138
+ }
139
+
140
+ willUpdate(changed: PropertyValues) {
141
+ if (changed.has('selectedSort') || changed.has('defaultSortField')) {
142
+ // If the sort is changed from its default without a direction set,
143
+ // we adopt the default sort direction for that sort type.
144
+ if (
145
+ this.selectedSort &&
146
+ this.selectedSort !== SortField.default &&
147
+ this.sortDirection === null
148
+ ) {
149
+ const sortOption = SORT_OPTIONS[this.finalizedSortField];
150
+ this.sortDirection = sortOption.defaultSortDirection;
151
+ }
152
+ }
153
+ }
154
+
155
+ updated(changed: PropertyValues) {
156
+ if (changed.has('displayMode')) {
157
+ this.displayModeChanged();
158
+ }
159
+
160
+ if (changed.has('selectedTitleFilter') && this.selectedTitleFilter) {
161
+ this.alphaSelectorVisible = 'title';
162
+ }
163
+
164
+ if (changed.has('selectedCreatorFilter') && this.selectedCreatorFilter) {
165
+ this.alphaSelectorVisible = 'creator';
166
+ }
167
+
168
+ if (changed.has('dropdownBackdropVisible')) {
169
+ this.setupEscapeListeners();
170
+ }
171
+ }
172
+
173
+ private setupEscapeListeners() {
174
+ if (this.dropdownBackdropVisible) {
175
+ document.addEventListener(
176
+ 'keydown',
177
+ this.boundSortBarSelectorEscapeListener,
178
+ );
179
+ } else {
180
+ document.removeEventListener(
181
+ 'keydown',
182
+ this.boundSortBarSelectorEscapeListener,
183
+ );
184
+ }
185
+ }
186
+
187
+ private boundSortBarSelectorEscapeListener = (e: KeyboardEvent) => {
188
+ if (e.key === 'Escape') {
189
+ this.closeDropdown();
190
+ }
191
+ };
192
+
193
+ /**
194
+ * Template to render the alphabet bar, or `nothing` if it should not be rendered
195
+ * for the current sort
196
+ */
197
+ private get alphaBarTemplate(): TemplateResult | typeof nothing {
198
+ if (!['title', 'creator'].includes(this.selectedSort)) return nothing;
199
+
200
+ if (this.alphaSelectorVisible === null) {
201
+ if (this.selectedSort === 'creator') return this.creatorSelectorBar;
202
+ if (this.selectedSort === 'title') return this.titleSelectorBar;
203
+ } else {
204
+ return this.alphaSelectorVisible === 'creator'
205
+ ? this.creatorSelectorBar
206
+ : this.titleSelectorBar;
207
+ }
208
+
209
+ return nothing;
210
+ }
211
+
212
+ /** Template to render the sort direction toggle button */
213
+ private get sortDirectionSelectorTemplate(): TemplateResult {
214
+ const oppositeSortDirectionReadable =
215
+ this.sortDirection === 'asc' ? msg('descending') : msg('ascending');
216
+ const buttonLabel = this.canChangeSortDirection
217
+ ? msg(str`Change to ${oppositeSortDirectionReadable} sort`)
218
+ : msg('Directions are not available for the current sort option');
219
+
220
+ return html`
221
+ <button
222
+ class="sort-direction-selector"
223
+ title=${buttonLabel}
224
+ ?disabled=${!this.canChangeSortDirection}
225
+ @click=${this.handleSortDirectionClicked}
226
+ >
227
+ <span class="sr-only">${buttonLabel}</span>
228
+ ${this.sortDirectionIcon}
229
+ </button>
230
+ `;
231
+ }
232
+
233
+ /** Template to render the sort direction button's icon in the correct current state */
234
+ private get sortDirectionIcon(): TemplateResult {
235
+ // Show a fully disabled icon for sort options without direction support
236
+ if (!this.canChangeSortDirection) {
237
+ return html`<div class="sort-direction-icon">${sortDisabledIcon}</div>`;
238
+ }
239
+
240
+ // For all other sorts, show the ascending/descending direction
241
+ return html`
242
+ <div class="sort-direction-icon">
243
+ ${this.finalizedSortDirection === 'asc' ? sortUpIcon : sortDownIcon}
244
+ </div>
245
+ `;
246
+ }
247
+
248
+ /** The template to render all the sort options in a single dropdown */
249
+ private get sortSelectorTemplate() {
250
+ const displayedOptions = Object.values(SORT_OPTIONS).filter(
251
+ opt => opt.shownInSortBar && this.sortFieldAvailability[opt.field],
252
+ );
253
+
254
+ return html`
255
+ <div id="sort-dropdown-container">
256
+ ${this.getSortDropdown({
257
+ displayName: SORT_OPTIONS[this.finalizedSortField].displayName,
258
+ id: 'sort-dropdown',
259
+ selected: true,
260
+ dropdownOptions: displayedOptions.map(opt =>
261
+ this.getDropdownOption(opt.field),
262
+ ),
263
+ selectedOption: this.finalizedSortField,
264
+ onOptionSelected: this.sortOptionSelected,
265
+ onDropdownClick: () => {
266
+ this.dropdownBackdropVisible = this.sortOptionsDropdown.open;
267
+ this.sortOptionsDropdown.classList.toggle(
268
+ 'open',
269
+ this.sortOptionsDropdown.open,
270
+ );
271
+ },
272
+ })}
273
+ </div>
274
+ `;
275
+ }
276
+
277
+ /**
278
+ * Generates a dropdown component containing multiple grouped sort options.
279
+ *
280
+ * @param options.displayName The name to use for the dropdown's visible label
281
+ * @param options.id The id to apply to the dropdown element
282
+ * @param options.dropdownOptions An array of option objects used to populate the dropdown
283
+ * @param options.selectedOption The id of the option that should be initially selected
284
+ * @param options.selected A boolean indicating whether this dropdown should use its
285
+ * selected appearance
286
+ * @param options.onOptionSelected A handler for optionSelected events coming from the dropdown
287
+ * @param options.onDropdownClick A handler for click events on the dropdown
288
+ */
289
+ private getSortDropdown(options: {
290
+ displayName: string;
291
+ id: string;
292
+ dropdownOptions: optionInterface[];
293
+ selectedOption?: string;
294
+ selected: boolean;
295
+ onOptionSelected?: (e: CustomEvent<{ option: optionInterface }>) => void;
296
+ onDropdownClick?: (e: PointerEvent) => void;
297
+ }): TemplateResult {
298
+ return html`
299
+ <ia-dropdown
300
+ id=${options.id}
301
+ class=${options.selected ? 'selected' : ''}
302
+ displayCaret
303
+ closeOnSelect
304
+ includeSelectedOption
305
+ .openViaButton=${options.selected}
306
+ .options=${options.dropdownOptions}
307
+ .selectedOption=${options.selectedOption ?? ''}
308
+ @optionSelected=${options.onOptionSelected ?? nothing}
309
+ @click=${options.onDropdownClick ?? nothing}
310
+ >
311
+ <span
312
+ class="dropdown-label"
313
+ slot="dropdown-label"
314
+ data-title=${options.displayName}
315
+ >
316
+ ${options.displayName}
317
+ </span>
318
+ </ia-dropdown>
319
+ `;
320
+ }
321
+
322
+ /** Generates a single dropdown option object for the given sort field */
323
+ private getDropdownOption(sortField: SortField): optionInterface {
324
+ return {
325
+ id: sortField,
326
+ label: html`
327
+ <span class="dropdown-option-label">
328
+ ${SORT_OPTIONS[sortField].displayName}
329
+ </span>
330
+ `,
331
+ };
332
+ }
333
+
334
+ /** Handler for when a new sort dropdown option is selected */
335
+ private sortOptionSelected(e: CustomEvent<{ option: optionInterface }>) {
336
+ this.dropdownBackdropVisible = false;
337
+
338
+ const sortField = e.detail.option.id as SortField;
339
+ this.setSelectedSort(sortField);
340
+
341
+ this.alphaSelectorVisible = null;
342
+ if (sortField !== 'title' && this.selectedTitleFilter) {
343
+ this.selectedTitleFilter = null;
344
+ this.emitTitleLetterChangedEvent();
345
+ }
346
+ if (sortField !== 'creator' && this.selectedCreatorFilter) {
347
+ this.selectedCreatorFilter = null;
348
+ this.emitCreatorLetterChangedEvent();
349
+ }
350
+ }
351
+
352
+ /** Template for rendering the three display mode options */
353
+ /** Added data-testid for Playwright testing * */
354
+ private get displayOptionTemplate() {
355
+ return html`
356
+ <ul>
357
+ <li>
358
+ <button
359
+ id="grid-button"
360
+ @click=${() => {
361
+ this.displayMode = 'grid';
362
+ }}
363
+ class=${this.displayMode === 'grid' ? 'active' : ''}
364
+ title="Tile view"
365
+ data-testid="grid-button"
366
+ >
367
+ ${tileIcon}
368
+ </button>
369
+ </li>
370
+ <li>
371
+ <button
372
+ id="list-detail-button"
373
+ @click=${() => {
374
+ this.displayMode = 'list-detail';
375
+ }}
376
+ class=${this.displayMode === 'list-detail' ? 'active' : ''}
377
+ title="List view"
378
+ data-testid="list-detail-button"
379
+ >
380
+ ${listIcon}
381
+ </button>
382
+ </li>
383
+ <li>
384
+ <button
385
+ id="list-compact-button"
386
+ @click=${() => {
387
+ this.displayMode = 'list-compact';
388
+ }}
389
+ class=${this.displayMode === 'list-compact' ? 'active' : ''}
390
+ title="Compact list view"
391
+ data-testid="list-compact-button"
392
+ >
393
+ ${compactIcon}
394
+ </button>
395
+ </li>
396
+ </ul>
397
+ `;
398
+ }
399
+
400
+ /**
401
+ * Template for rendering the transparent backdrop to capture clicks outside the
402
+ * dropdown menu while it is open.
403
+ */
404
+ private get dropdownBackdrop() {
405
+ return html`
406
+ <div
407
+ id="sort-selector-backdrop"
408
+ @keyup=${this.closeDropdown}
409
+ @click=${this.closeDropdown}
410
+ ></div>
411
+ `;
412
+ }
413
+
414
+ /** Closes the sorting dropdown component's menus */
415
+ private closeDropdown() {
416
+ this.dropdownBackdropVisible = false;
417
+
418
+ if (!this.sortOptionsDropdown) return;
419
+ this.sortOptionsDropdown.open = false;
420
+ this.sortOptionsDropdown.classList.remove('open');
421
+ }
422
+
423
+ setSortDirection(sortDirection: SortDirection) {
424
+ this.sortDirection = sortDirection;
425
+ this.emitSortChangedEvent();
426
+ }
427
+
428
+ /** Toggles the current sort direction between 'asc' and 'desc' */
429
+ private toggleSortDirection() {
430
+ this.setSortDirection(
431
+ this.finalizedSortDirection === 'desc' ? 'asc' : 'desc',
432
+ );
433
+ }
434
+
435
+ private handleSortDirectionClicked(): void {
436
+ if (
437
+ !this.sortDirection &&
438
+ this.defaultSortField &&
439
+ this.defaultSortDirection
440
+ ) {
441
+ // When the sort direction is merely defaulted (not set by the user), clicking
442
+ // the toggled button should "promote" the default sort to an explicitly-set one
443
+ // and then toggle it as usual.
444
+ this.selectedSort = this.defaultSortField;
445
+ this.sortDirection = this.defaultSortDirection;
446
+ }
447
+
448
+ this.toggleSortDirection();
449
+ }
450
+
451
+ setSelectedSort(sort: SortField) {
452
+ this.selectedSort = sort;
453
+ // Apply this field's default sort direction
454
+ const sortOption = SORT_OPTIONS[sort];
455
+ this.sortDirection = sortOption.defaultSortDirection;
456
+ this.emitSortChangedEvent();
457
+ }
458
+
459
+ /** The current sort field, or the default one if no explicit sort is set */
460
+ private get finalizedSortField(): SortField {
461
+ const resolvedField =
462
+ this.selectedSort === SortField.default
463
+ ? this.defaultSortField
464
+ : this.selectedSort;
465
+ if (this.sortFieldAvailability[resolvedField]) return resolvedField;
466
+
467
+ // Fall back to the first available sort option shown in the sort bar, if
468
+ // the requested one isn't available
469
+ return this.firstAvailableOption?.field ?? resolvedField;
470
+ }
471
+
472
+ /** The current sort direction, or the default one if no explicit direction is set */
473
+ private get finalizedSortDirection(): SortDirection | null {
474
+ return this.sortDirection === null
475
+ ? this.defaultSortDirection
476
+ : this.sortDirection;
477
+ }
478
+
479
+ /** The first option shown in the sort dropdown, or undefined if none are available */
480
+ private get firstAvailableOption(): SortOption | undefined {
481
+ return Object.values(SORT_OPTIONS).find(
482
+ opt => opt.shownInSortBar && this.sortFieldAvailability[opt.field],
483
+ );
484
+ }
485
+
486
+ /** Whether the sort direction button should be enabled for the current sort */
487
+ private get canChangeSortDirection(): boolean {
488
+ return SORT_OPTIONS[this.finalizedSortField].canSetDirection;
489
+ }
490
+
491
+ private get titleSelectorBar() {
492
+ return html` <alpha-bar
493
+ .selectedLetter=${this.selectedTitleFilter}
494
+ .letterCounts=${this.prefixFilterCountMap?.title}
495
+ ariaLandmarkLabel="Filter by title letter"
496
+ @letterChanged=${this.titleLetterChanged}
497
+ ></alpha-bar>`;
498
+ }
499
+
500
+ private get creatorSelectorBar() {
501
+ return html` <alpha-bar
502
+ .selectedLetter=${this.selectedCreatorFilter}
503
+ .letterCounts=${this.prefixFilterCountMap?.creator}
504
+ ariaLandmarkLabel="Filter by creator letter"
505
+ @letterChanged=${this.creatorLetterChanged}
506
+ ></alpha-bar>`;
507
+ }
508
+
509
+ private titleLetterChanged(
510
+ e: CustomEvent<{ selectedLetter: string | undefined }>,
511
+ ) {
512
+ this.selectedTitleFilter = e.detail.selectedLetter ?? null;
513
+ this.emitTitleLetterChangedEvent();
514
+ }
515
+
516
+ private creatorLetterChanged(
517
+ e: CustomEvent<{ selectedLetter: string | undefined }>,
518
+ ) {
519
+ this.selectedCreatorFilter = e.detail.selectedLetter ?? null;
520
+ this.emitCreatorLetterChangedEvent();
521
+ }
522
+
523
+ private emitTitleLetterChangedEvent() {
524
+ const event = new CustomEvent<{ selectedLetter: string | null }>(
525
+ 'titleLetterChanged',
526
+ {
527
+ detail: { selectedLetter: this.selectedTitleFilter },
528
+ },
529
+ );
530
+ this.dispatchEvent(event);
531
+ }
532
+
533
+ private emitCreatorLetterChangedEvent() {
534
+ const event = new CustomEvent<{ selectedLetter: string | null }>(
535
+ 'creatorLetterChanged',
536
+ {
537
+ detail: { selectedLetter: this.selectedCreatorFilter },
538
+ },
539
+ );
540
+ this.dispatchEvent(event);
541
+ }
542
+
543
+ private displayModeChanged() {
544
+ const event = new CustomEvent<{
545
+ displayMode?: CollectionDisplayMode;
546
+ }>('displayModeChanged', {
547
+ detail: { displayMode: this.displayMode },
548
+ });
549
+ this.dispatchEvent(event);
550
+ }
551
+
552
+ private emitSortChangedEvent() {
553
+ const event = new CustomEvent<{
554
+ selectedSort: SortField;
555
+ sortDirection: SortDirection | null;
556
+ }>('sortChanged', {
557
+ detail: {
558
+ selectedSort: this.selectedSort,
559
+ sortDirection: this.sortDirection,
560
+ },
561
+ });
562
+ this.dispatchEvent(event);
563
+ }
564
+
565
+ static get styles() {
566
+ const disabledIconColor = css`#bbbbbb`;
567
+
568
+ return [
569
+ srOnlyStyle,
570
+ css`
571
+ #container {
572
+ position: relative;
573
+ }
574
+
575
+ #sort-bar {
576
+ display: flex;
577
+ justify-content: flex-start;
578
+ align-items: center;
579
+ padding-bottom: 1px;
580
+ border-bottom: 1px solid #2c2c2c;
581
+ font-size: 1.4rem;
582
+ }
583
+
584
+ #sort-options {
585
+ display: flex;
586
+ align-items: center;
587
+ flex-grow: 1;
588
+ }
589
+
590
+ ul {
591
+ list-style: none;
592
+ display: flex;
593
+ align-items: center;
594
+ margin: 0;
595
+ padding: 0;
596
+ }
597
+
598
+ li {
599
+ padding: 0;
600
+ }
601
+
602
+ .sort-by-text {
603
+ margin-right: 5px;
604
+ font-weight: bold;
605
+ white-space: nowrap;
606
+ }
607
+
608
+ .sort-direction-container {
609
+ display: flex;
610
+ align-self: stretch;
611
+ flex: 0;
612
+ margin: 0 3px;
613
+ }
614
+
615
+ .sort-direction-selector {
616
+ display: flex;
617
+ justify-content: center;
618
+ width: 30px;
619
+ margin: 0 5px 0 0;
620
+ padding: 7px 8px;
621
+ max-height: fit-content;
622
+ border-radius: 5px;
623
+ background: white;
624
+ border: 1px solid rgb(25, 72, 128);
625
+ appearance: none;
626
+ cursor: pointer;
627
+ }
628
+
629
+ .sort-direction-selector:disabled {
630
+ cursor: not-allowed;
631
+ border-color: ${disabledIconColor};
632
+ }
633
+
634
+ .sort-direction-icon {
635
+ display: flex;
636
+ align-items: center;
637
+ background: none;
638
+ color: inherit;
639
+ border: none;
640
+ padding: 0;
641
+ outline: inherit;
642
+ width: 12px;
643
+ height: 12px;
644
+ }
645
+
646
+ .sort-direction-icon > svg {
647
+ flex: 1;
648
+ }
649
+
650
+ #sort-selector-container {
651
+ flex: 1;
652
+ display: flex;
653
+ justify-content: flex-start;
654
+ align-items: center;
655
+ }
656
+
657
+ #sort-dropdown-container {
658
+ display: flex;
659
+ justify-content: flex-start;
660
+ align-items: center;
661
+ }
662
+
663
+ #sort-selector-backdrop {
664
+ position: fixed;
665
+ top: 0;
666
+ left: 0;
667
+ width: 100vw;
668
+ height: 100vh;
669
+ z-index: 1;
670
+ background-color: transparent;
671
+ }
672
+
673
+ #display-style-selector {
674
+ flex: 0;
675
+ }
676
+
677
+ #display-style-selector button {
678
+ background: none;
679
+ color: inherit;
680
+ border: none;
681
+ appearance: none;
682
+ cursor: pointer;
683
+ -webkit-appearance: none;
684
+ fill: ${disabledIconColor};
685
+ }
686
+
687
+ #display-style-selector button.active {
688
+ fill: var(--ia-theme-primary-text-color, #2c2c2c);
689
+ }
690
+
691
+ #display-style-selector button svg {
692
+ width: 24px;
693
+ height: 24px;
694
+ }
695
+
696
+ ia-dropdown {
697
+ --dropdownTextColor: white;
698
+ --dropdownOffsetTop: 0;
699
+ --dropdownBorderTopWidth: 0;
700
+ --dropdownBorderTopLeftRadius: 0;
701
+ --dropdownBorderTopRightRadius: 0;
702
+ --dropdownWhiteSpace: nowrap;
703
+ --dropdownListZIndex: 2;
704
+ --dropdownCaretColor: var(--ia-theme-primary-text-color, #2c2c2c);
705
+ --dropdownSelectedTextColor: white;
706
+ --dropdownSelectedBgColor: rgba(255, 255, 255, 0.3);
707
+ --dropdownHoverBgColor: rgba(255, 255, 255, 0.3);
708
+ --caretHeight: 9px;
709
+ --caretWidth: 12px;
710
+ --caretPadding: 0 5px 0 0;
711
+ }
712
+ ia-dropdown.selected .dropdown-label {
713
+ font-weight: bold;
714
+ }
715
+ ia-dropdown.open {
716
+ z-index: 2;
717
+ }
718
+
719
+ .dropdown-label {
720
+ display: inline-block;
721
+ height: 100%;
722
+ padding-left: 5px;
723
+ font-size: 1.4rem;
724
+ font-family: var(--ia-theme-base-font-family);
725
+ line-height: 2;
726
+ color: var(--ia-theme-primary-text-color, #2c2c2c);
727
+ white-space: nowrap;
728
+ user-select: none;
729
+ }
730
+ `,
731
+ ];
732
+ }
733
+ }