@internetarchive/collection-browser 2.1.2 → 2.1.3-alpha.1

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/src/app-root.ts CHANGED
@@ -395,11 +395,11 @@ export class AppRoot extends LitElement {
395
395
  <div class="checkbox-control">
396
396
  <input
397
397
  type="checkbox"
398
- id="enable-loanstab-topbar-view"
399
- @click=${this.loansTabTopBarViewCheckboxChanged}
398
+ id="enable-replaced-sort-options"
399
+ @click=${this.replaceSortOptionsChanged}
400
400
  />
401
- <label for="enable-loanstab-topbar-view">
402
- Show loans-tab top-bar view
401
+ <label for="enable-replaced-sort-options">
402
+ Show replaced sort options
403
403
  </label>
404
404
  </div>
405
405
  </fieldset>
@@ -744,7 +744,7 @@ export class AppRoot extends LitElement {
744
744
  div.style.setProperty('height', '3rem');
745
745
  div.style.setProperty('width', '3rem');
746
746
  div.style.backgroundColor = '#00000';
747
- div.setAttribute('slot', 'sortbar-left-slot');
747
+ div.setAttribute('slot', 'sort-options-left');
748
748
 
749
749
  if (target.checked) {
750
750
  this.collectionBrowser.appendChild(div);
@@ -802,9 +802,9 @@ export class AppRoot extends LitElement {
802
802
  }
803
803
 
804
804
  /**
805
- * Handler for when the dev panel's "Show loanstab topbar view" checkbox is changed.
805
+ * Handler for when the dev panel's "Replace sort options" checkbox is changed.
806
806
  */
807
- private loansTabTopBarViewCheckboxChanged(e: Event) {
807
+ private replaceSortOptionsChanged(e: Event) {
808
808
  const target = e.target as HTMLInputElement;
809
809
 
810
810
  const p = document.createElement('p');
@@ -812,13 +812,13 @@ export class AppRoot extends LitElement {
812
812
  p.textContent = 'New stuff as a child.';
813
813
  p.style.setProperty('height', '20px');
814
814
  p.style.backgroundColor = '#00000';
815
- p.setAttribute('slot', 'loans-tab-filter-bar-options-slot');
815
+ p.setAttribute('slot', 'sort-options');
816
816
 
817
817
  if (target.checked) {
818
- this.collectionBrowser.isLoansTab = true;
818
+ this.collectionBrowser.enableSortOptionsSlot = true;
819
819
  this.collectionBrowser.appendChild(p);
820
820
  } else {
821
- this.collectionBrowser.isLoansTab = false;
821
+ this.collectionBrowser.enableSortOptionsSlot = false;
822
822
  this.collectionBrowser.removeChild(
823
823
  this.collectionBrowser.lastElementChild as Element
824
824
  );
@@ -171,7 +171,8 @@ export class CollectionBrowser
171
171
  */
172
172
  @property({ type: Boolean }) isManageView = false;
173
173
 
174
- @property({ type: Boolean }) isLoansTab = false;
174
+ /** Whether to replace the default sort options with a slot for customization (default: false) */
175
+ @property({ type: Boolean }) enableSortOptionsSlot = false;
175
176
 
176
177
  /**
177
178
  * The results per page so we can paginate.
@@ -626,18 +627,19 @@ export class CollectionBrowser
626
627
  .selectedCreatorFilter=${this.selectedCreatorFilter}
627
628
  .prefixFilterCountMap=${this.dataSource.prefixFilterCountMap}
628
629
  .resizeObserver=${this.resizeObserver}
630
+ .enableSortOptionsSlot=${this.enableSortOptionsSlot}
629
631
  @sortChanged=${this.userChangedSort}
630
632
  @displayModeChanged=${this.displayModeChanged}
631
633
  @titleLetterChanged=${this.titleLetterSelected}
632
634
  @creatorLetterChanged=${this.creatorLetterSelected}
633
- .showLoansTopBar=${this.isLoansTab}
634
635
  >
635
- <div slot="sortbar-left-slot">
636
- <slot name="sortbar-left-slot"></slot>
637
- </div>
638
636
  <slot
639
- name="loans-tab-filter-bar-options-slot"
640
- slot="loans-tab-filter-bar-options-slot"
637
+ name="sort-options-left"
638
+ slot="sort-options-left"
639
+ ></slot>
640
+ <slot
641
+ name="sort-options"
642
+ slot="sort-options"
641
643
  ></slot>
642
644
  </sort-filter-bar>
643
645
  `;
@@ -7,6 +7,7 @@ import {
7
7
  TemplateResult,
8
8
  } from 'lit';
9
9
  import { customElement, property, query, state } from 'lit/decorators.js';
10
+ import { msg } from '@lit/localize';
10
11
  import type {
11
12
  SharedResizeObserverInterface,
12
13
  SharedResizeObserverResizeHandlerInterface,
@@ -68,8 +69,8 @@ export class SortFilterBar
68
69
  /** Whether to show the Date Favorited sort option instead of Date Published/Archived/Reviewed (default `false`) */
69
70
  @property({ type: Boolean }) showDateFavorited: boolean = false;
70
71
 
71
- /** Whether to show the Loans filter for ProfilePage (default `false`) */
72
- @property({ type: Boolean }) showLoansTopBar: boolean = false;
72
+ /** Whether to replace the default sort options with a slot for customization (default `false`) */
73
+ @property({ type: Boolean }) enableSortOptionsSlot: boolean = false;
73
74
 
74
75
  /** Maps of result counts for letters on the alphabet bar, for each letter filter type */
75
76
  @property({ type: Object }) prefixFilterCountMap?: Record<
@@ -143,19 +144,21 @@ export class SortFilterBar
143
144
  return html`
144
145
  <div id="container">
145
146
  <section id="sort-bar" aria-label="Sorting options">
146
- ${!this.showLoansTopBar
147
- ? html`
148
- <slot name="sortbar-left-slot"></slot>
149
- <div class="sort-direction-container">
150
- ${this.sortDirectionSelectorTemplate}
151
- </div>
152
- <span class="sort-by-text">Sort by:</span>
153
- <div id="sort-selector-container">
154
- ${this.mobileSortSelectorTemplate}
155
- ${this.desktopSortSelectorTemplate}
156
- </div>
157
- `
158
- : html`<slot name="loans-tab-filter-bar-options-slot"></slot>`}
147
+ <slot name="sort-options-left"></slot>
148
+ <div id="sort-options">
149
+ ${!this.enableSortOptionsSlot
150
+ ? html`
151
+ <div class="sort-direction-container">
152
+ ${this.sortDirectionSelectorTemplate}
153
+ </div>
154
+ <span class="sort-by-text">${msg('Sort by:')}</span>
155
+ <div id="sort-selector-container">
156
+ ${this.mobileSortSelectorTemplate}
157
+ ${this.desktopSortSelectorTemplate}
158
+ </div>
159
+ `
160
+ : html`<slot name="sort-options"></slot>`}
161
+ </div>
159
162
 
160
163
  <div id="display-style-selector">${this.displayOptionTemplate}</div>
161
164
  </section>
@@ -939,12 +942,18 @@ export class SortFilterBar
939
942
 
940
943
  #sort-bar {
941
944
  display: flex;
942
- justify-content: space-between;
945
+ justify-content: flex-start;
943
946
  align-items: center;
944
947
  border-bottom: 1px solid #2c2c2c;
945
948
  font-size: 1.4rem;
946
949
  }
947
950
 
951
+ #sort-options {
952
+ display: flex;
953
+ align-items: center;
954
+ flex-grow: 1;
955
+ }
956
+
948
957
  ul {
949
958
  list-style: none;
950
959
  display: flex;
@@ -1833,8 +1833,8 @@ describe('Collection Browser', () => {
1833
1833
  const sortBar = el.shadowRoot?.querySelector(
1834
1834
  'sort-filter-bar'
1835
1835
  ) as SortFilterBar;
1836
- expect(sortBar?.showLoansTopBar, 'show loans in sort bar').to.be.true;
1837
- expect(el.isLoansTab, 'collection browser is loans tab').to.be.true;
1836
+ expect(sortBar?.enableSortOptionsSlot, 'show loans in sort bar').to.be.true;
1837
+ expect(el.enableSortOptionsSlot, 'collection browser is loans tab').to.be.true;
1838
1838
 
1839
1839
  const loansTabSlot = sortBar.querySelector(
1840
1840
  'slot[name="loans-tab-filter-bar-options-slot"]'