@internetarchive/collection-browser 2.18.3-alpha-webdev7768.8 → 2.19.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.
@@ -1,185 +1,185 @@
1
- import { css, html, LitElement, CSSResultGroup, nothing } from 'lit';
2
- import { customElement, property, query } from 'lit/decorators.js';
3
- import type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';
4
- import type { FacetRef, SmartFacet, SmartFacetEvent } from './models';
5
- import { log } from '../../utils/log';
6
-
7
- @customElement('smart-facet-dropdown')
8
- export class SmartFacetDropdown extends LitElement {
9
- @property({ type: Array }) facetInfo?: SmartFacet[];
10
-
11
- @property({ type: String }) labelPrefix?: string;
12
-
13
- @property({ type: Object }) activeFacetRef?: FacetRef;
14
-
15
- @query('ia-dropdown') dropdown?: IaDropdown;
16
-
17
- //
18
- // COMPONENT LIFECYCLE METHODS
19
- //
20
-
21
- render() {
22
- if (!this.facetInfo || !this.activeFacetRef) return nothing;
23
- if (this.facetInfo.length === 0) return nothing;
24
-
25
- const displayText =
26
- this.activeFacetRef.displayText ?? this.activeFacetRef.bucketKey;
27
- if (!displayText) return nothing;
28
-
29
- return html`
30
- <div class="dropdown-container">
31
- <ia-dropdown
32
- class="dropdown"
33
- displayCaret
34
- closeOnSelect
35
- closeOnEscape
36
- closeOnBackdropClick
37
- includeSelectedOption
38
- usePopover
39
- .options=${this.dropdownOptions}
40
- .selectedOption=${this.activeDropdownOption}
41
- .openViaButton=${false}
42
- @optionSelected=${this.optionSelected}
43
- @click=${this.onDropdownClick}
44
- >
45
- <span
46
- class="dropdown-label"
47
- slot="dropdown-label"
48
- @click=${this.defaultOptionSelected}
49
- >${this.labelPrefix ?? nothing} ${displayText}</span
50
- >
51
- </ia-dropdown>
52
- </div>
53
- `;
54
- }
55
-
56
- //
57
- // OTHER METHODS
58
- //
59
-
60
- private get dropdownOptions(): optionInterface[] {
61
- return (
62
- this.facetInfo?.map(smartFacet => {
63
- const firstFacet = smartFacet.facets[0];
64
- return {
65
- id: firstFacet.bucketKey,
66
- label: html`<span>
67
- ${smartFacet.label ??
68
- firstFacet.displayText ??
69
- firstFacet.bucketKey}
70
- </span>`,
71
- };
72
- }) ?? []
73
- );
74
- }
75
-
76
- private get activeDropdownOption(): optionInterface | undefined {
77
- if (!this.activeFacetRef) return undefined;
78
- return this.dropdownOptions.find(
79
- opt => opt.id === this.activeFacetRef?.bucketKey,
80
- );
81
- }
82
-
83
- /**
84
- * Handler for when the default option on the dropdown button is clicked
85
- */
86
- private defaultOptionSelected(): void {
87
- this.handleSelection(this.activeFacetRef?.bucketKey);
88
- }
89
-
90
- /**
91
- * Handler for when an option in the dropdown menu is selected
92
- */
93
- private optionSelected(e: CustomEvent<{ option: optionInterface }>): void {
94
- this.handleSelection(e.detail.option.id);
95
- }
96
-
97
- /**
98
- * Responds to a dropdown selection by emitting a `facetClick` event with
99
- * the appropriate facet details.
100
- */
101
- private handleSelection(bucketKey?: string): void {
102
- if (!bucketKey || !this.facetInfo || !this.activeFacetRef) return;
103
-
104
- let selectedSmartFacet;
105
- for (const smartFacet of this.facetInfo) {
106
- const selectedRef = smartFacet.facets.find(
107
- b => b.bucketKey === bucketKey,
108
- );
109
- if (selectedRef) {
110
- this.activeFacetRef = selectedRef;
111
- selectedSmartFacet = smartFacet;
112
- }
113
- }
114
-
115
- if (!selectedSmartFacet) return;
116
-
117
- this.dispatchEvent(
118
- new CustomEvent<SmartFacetEvent>('facetClick', {
119
- detail: {
120
- smartFacet: selectedSmartFacet,
121
- details: [
122
- {
123
- facetType: this.activeFacetRef.facetType,
124
- bucket: {
125
- key: this.activeFacetRef.bucketKey,
126
- count: 0,
127
- state: 'selected',
128
- },
129
- negative: false,
130
- },
131
- ],
132
- },
133
- }),
134
- );
135
- }
136
-
137
- private onDropdownClick(): void {
138
- log('smart dropdown: onDropdownClick', this);
139
- this.dispatchEvent(
140
- new CustomEvent<SmartFacetDropdown>('dropdownClick', { detail: this }),
141
- );
142
- }
143
-
144
- close(): void {
145
- if (this.dropdown) {
146
- this.dropdown.open = false;
147
- }
148
- }
149
-
150
- //
151
- // STYLES
152
- //
153
-
154
- static get styles(): CSSResultGroup {
155
- return css`
156
- .dropdown-container {
157
- padding: 5px 5px;
158
- border-radius: 5px;
159
- background: white;
160
- color: #2c2c2c;
161
- border: 1px solid #194880;
162
- font-size: 1.4rem;
163
- font-family: inherit;
164
- }
165
-
166
- .dropdown-label {
167
- font-size: 1.4rem;
168
- font-family: inherit;
169
- }
170
-
171
- .dropdown {
172
- --dropdownBorderColor: #194880;
173
- --dropdownBorderWidth: 1px;
174
- --dropdownBgColor: white;
175
- --dropdownHoverBgColor: #f8f8f8;
176
- --dropdownTextColor: #2c2c2c;
177
- --dropdownHoverTextColor: #2c2c2c;
178
- --dropdownCaretColor: #2c2c2c;
179
- --dropdownWhiteSpace: nowrap;
180
- --caretWidth: 14px;
181
- --caretHeight: 14px;
182
- }
183
- `;
184
- }
185
- }
1
+ import { css, html, LitElement, CSSResultGroup, nothing } from 'lit';
2
+ import { customElement, property, query } from 'lit/decorators.js';
3
+ import type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';
4
+ import type { FacetRef, SmartFacet, SmartFacetEvent } from './models';
5
+ import { log } from '../../utils/log';
6
+
7
+ @customElement('smart-facet-dropdown')
8
+ export class SmartFacetDropdown extends LitElement {
9
+ @property({ type: Array }) facetInfo?: SmartFacet[];
10
+
11
+ @property({ type: String }) labelPrefix?: string;
12
+
13
+ @property({ type: Object }) activeFacetRef?: FacetRef;
14
+
15
+ @query('ia-dropdown') dropdown?: IaDropdown;
16
+
17
+ //
18
+ // COMPONENT LIFECYCLE METHODS
19
+ //
20
+
21
+ render() {
22
+ if (!this.facetInfo || !this.activeFacetRef) return nothing;
23
+ if (this.facetInfo.length === 0) return nothing;
24
+
25
+ const displayText =
26
+ this.activeFacetRef.displayText ?? this.activeFacetRef.bucketKey;
27
+ if (!displayText) return nothing;
28
+
29
+ return html`
30
+ <div class="dropdown-container">
31
+ <ia-dropdown
32
+ class="dropdown"
33
+ displayCaret
34
+ closeOnSelect
35
+ closeOnEscape
36
+ closeOnBackdropClick
37
+ includeSelectedOption
38
+ usePopover
39
+ .options=${this.dropdownOptions}
40
+ .selectedOption=${this.activeDropdownOption}
41
+ .openViaButton=${false}
42
+ @optionSelected=${this.optionSelected}
43
+ @click=${this.onDropdownClick}
44
+ >
45
+ <span
46
+ class="dropdown-label"
47
+ slot="dropdown-label"
48
+ @click=${this.defaultOptionSelected}
49
+ >${this.labelPrefix ?? nothing} ${displayText}</span
50
+ >
51
+ </ia-dropdown>
52
+ </div>
53
+ `;
54
+ }
55
+
56
+ //
57
+ // OTHER METHODS
58
+ //
59
+
60
+ private get dropdownOptions(): optionInterface[] {
61
+ return (
62
+ this.facetInfo?.map(smartFacet => {
63
+ const firstFacet = smartFacet.facets[0];
64
+ return {
65
+ id: firstFacet.bucketKey,
66
+ label: html`<span>
67
+ ${smartFacet.label ??
68
+ firstFacet.displayText ??
69
+ firstFacet.bucketKey}
70
+ </span>`,
71
+ };
72
+ }) ?? []
73
+ );
74
+ }
75
+
76
+ private get activeDropdownOption(): optionInterface | undefined {
77
+ if (!this.activeFacetRef) return undefined;
78
+ return this.dropdownOptions.find(
79
+ opt => opt.id === this.activeFacetRef?.bucketKey,
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Handler for when the default option on the dropdown button is clicked
85
+ */
86
+ private defaultOptionSelected(): void {
87
+ this.handleSelection(this.activeFacetRef?.bucketKey);
88
+ }
89
+
90
+ /**
91
+ * Handler for when an option in the dropdown menu is selected
92
+ */
93
+ private optionSelected(e: CustomEvent<{ option: optionInterface }>): void {
94
+ this.handleSelection(e.detail.option.id);
95
+ }
96
+
97
+ /**
98
+ * Responds to a dropdown selection by emitting a `facetClick` event with
99
+ * the appropriate facet details.
100
+ */
101
+ private handleSelection(bucketKey?: string): void {
102
+ if (!bucketKey || !this.facetInfo || !this.activeFacetRef) return;
103
+
104
+ let selectedSmartFacet;
105
+ for (const smartFacet of this.facetInfo) {
106
+ const selectedRef = smartFacet.facets.find(
107
+ b => b.bucketKey === bucketKey,
108
+ );
109
+ if (selectedRef) {
110
+ this.activeFacetRef = selectedRef;
111
+ selectedSmartFacet = smartFacet;
112
+ }
113
+ }
114
+
115
+ if (!selectedSmartFacet) return;
116
+
117
+ this.dispatchEvent(
118
+ new CustomEvent<SmartFacetEvent>('facetClick', {
119
+ detail: {
120
+ smartFacet: selectedSmartFacet,
121
+ details: [
122
+ {
123
+ facetType: this.activeFacetRef.facetType,
124
+ bucket: {
125
+ key: this.activeFacetRef.bucketKey,
126
+ count: 0,
127
+ state: 'selected',
128
+ },
129
+ negative: false,
130
+ },
131
+ ],
132
+ },
133
+ }),
134
+ );
135
+ }
136
+
137
+ private onDropdownClick(): void {
138
+ log('smart dropdown: onDropdownClick', this);
139
+ this.dispatchEvent(
140
+ new CustomEvent<SmartFacetDropdown>('dropdownClick', { detail: this }),
141
+ );
142
+ }
143
+
144
+ close(): void {
145
+ if (this.dropdown) {
146
+ this.dropdown.open = false;
147
+ }
148
+ }
149
+
150
+ //
151
+ // STYLES
152
+ //
153
+
154
+ static get styles(): CSSResultGroup {
155
+ return css`
156
+ .dropdown-container {
157
+ padding: 5px 5px;
158
+ border-radius: 5px;
159
+ background: white;
160
+ color: #2c2c2c;
161
+ border: 1px solid #194880;
162
+ font-size: 1.4rem;
163
+ font-family: inherit;
164
+ }
165
+
166
+ .dropdown-label {
167
+ font-size: 1.4rem;
168
+ font-family: inherit;
169
+ }
170
+
171
+ .dropdown {
172
+ --dropdownBorderColor: #194880;
173
+ --dropdownBorderWidth: 1px;
174
+ --dropdownBgColor: white;
175
+ --dropdownHoverBgColor: #f8f8f8;
176
+ --dropdownTextColor: #2c2c2c;
177
+ --dropdownHoverTextColor: #2c2c2c;
178
+ --dropdownCaretColor: #2c2c2c;
179
+ --dropdownWhiteSpace: nowrap;
180
+ --caretWidth: 14px;
181
+ --caretHeight: 14px;
182
+ }
183
+ `;
184
+ }
185
+ }
@@ -1,129 +1,129 @@
1
- import { css } from 'lit';
2
- import { srOnlyStyle } from '../../../styles/sr-only';
3
-
4
- /**
5
- * Base tile styles
6
- */
7
-
8
- const tileBackgroundColor = css`var(--tileBackgroundColor, #ffffff)`;
9
- const tileCornerRadius = css`var(--tileCornerRadius, 4px)`;
10
-
11
- export const baseTileStyles = css`
12
- /* Include .sr-only styles for all tiles */
13
- ${srOnlyStyle}
14
-
15
- .container {
16
- background-color: ${tileBackgroundColor};
17
- border: 1px #2c2c2c;
18
- border-radius: ${tileCornerRadius};
19
- box-shadow: var(--tileBoxShadow, 1px 1px 2px 0);
20
- box-sizing: border-box;
21
- height: 100%;
22
- display: flex;
23
- flex-direction: column;
24
- width: 100%;
25
- }
26
-
27
- image-block {
28
- display: block;
29
- position: relative;
30
- text-align: center;
31
- }
32
-
33
- .tile-details {
34
- display: flex;
35
- flex-direction: column;
36
- height: 100%;
37
- row-gap: 10px;
38
- font-family: 'Helvetica Neue', ui-sans-serif, system-ui, sans-serif;
39
- }
40
-
41
- .item-info {
42
- display: flex;
43
- flex-direction: column;
44
- row-gap: 5px;
45
- flex-grow: 1;
46
- }
47
-
48
- #title {
49
- padding: 0 5px;
50
- }
51
-
52
- .created-by,
53
- .date-sorted-by,
54
- .volume-issue,
55
- .archivist-since {
56
- display: flex;
57
- justify-content: left;
58
- align-items: flex-start;
59
- padding: 0 5px;
60
- }
61
-
62
- .truncated {
63
- flex: 1;
64
- color: #2c2c2c;
65
- min-width: 0; /* Important for long words! */
66
- text-align: left;
67
- line-height: 15px;
68
- text-overflow: ellipsis;
69
- overflow: hidden;
70
- word-wrap: break-word;
71
- -webkit-line-clamp: 3;
72
- -webkit-box-orient: vertical;
73
- }
74
-
75
- h4.truncated {
76
- display: -webkit-box;
77
- margin: 0px;
78
- line-height: 15px;
79
- font-size: 14px;
80
- font-weight: 500;
81
- padding-bottom: 1px;
82
- }
83
-
84
- span {
85
- display: -webkit-box;
86
- font-size: 1.4rem;
87
- line-height: 15px;
88
- overflow: hidden;
89
- word-wrap: break-word;
90
- -webkit-line-clamp: 1;
91
- -webkit-box-orient: vertical;
92
- padding-bottom: 1px;
93
- }
94
-
95
- .container:hover > .tile-details > .item-info > #title > .truncated {
96
- text-decoration: underline;
97
- }
98
-
99
- /** this is a workaround for Safari 15 where the hover effects are not working */
100
- #title:hover > .truncated {
101
- text-decoration: underline;
102
- }
103
-
104
- .info-button {
105
- position: absolute;
106
- right: 10px;
107
- top: 10px;
108
- margin: 0;
109
- padding: 0;
110
- border: none;
111
- border-radius: 50%;
112
- display: flex;
113
- justify-content: center;
114
- align-items: center;
115
- background: rgba(220, 220, 220, 0.5);
116
- color: white;
117
- font-size: 2rem;
118
- font-weight: bold;
119
- line-height: 1;
120
- text-shadow: black 1px 1px 3px;
121
- overflow: visible;
122
- aspect-ratio: 1 / 1;
123
- z-index: 1;
124
- }
125
-
126
- .hidden {
127
- display: none;
128
- }
129
- `;
1
+ import { css } from 'lit';
2
+ import { srOnlyStyle } from '../../../styles/sr-only';
3
+
4
+ /**
5
+ * Base tile styles
6
+ */
7
+
8
+ const tileBackgroundColor = css`var(--tileBackgroundColor, #ffffff)`;
9
+ const tileCornerRadius = css`var(--tileCornerRadius, 4px)`;
10
+
11
+ export const baseTileStyles = css`
12
+ /* Include .sr-only styles for all tiles */
13
+ ${srOnlyStyle}
14
+
15
+ .container {
16
+ background-color: ${tileBackgroundColor};
17
+ border: 1px #2c2c2c;
18
+ border-radius: ${tileCornerRadius};
19
+ box-shadow: var(--tileBoxShadow, 1px 1px 2px 0);
20
+ box-sizing: border-box;
21
+ height: 100%;
22
+ display: flex;
23
+ flex-direction: column;
24
+ width: 100%;
25
+ }
26
+
27
+ image-block {
28
+ display: block;
29
+ position: relative;
30
+ text-align: center;
31
+ }
32
+
33
+ .tile-details {
34
+ display: flex;
35
+ flex-direction: column;
36
+ height: 100%;
37
+ row-gap: 10px;
38
+ font-family: 'Helvetica Neue', ui-sans-serif, system-ui, sans-serif;
39
+ }
40
+
41
+ .item-info {
42
+ display: flex;
43
+ flex-direction: column;
44
+ row-gap: 5px;
45
+ flex-grow: 1;
46
+ }
47
+
48
+ #title {
49
+ padding: 0 5px;
50
+ }
51
+
52
+ .created-by,
53
+ .date-sorted-by,
54
+ .volume-issue,
55
+ .archivist-since {
56
+ display: flex;
57
+ justify-content: left;
58
+ align-items: flex-start;
59
+ padding: 0 5px;
60
+ }
61
+
62
+ .truncated {
63
+ flex: 1;
64
+ color: #2c2c2c;
65
+ min-width: 0; /* Important for long words! */
66
+ text-align: left;
67
+ line-height: 15px;
68
+ text-overflow: ellipsis;
69
+ overflow: hidden;
70
+ word-wrap: break-word;
71
+ -webkit-line-clamp: 3;
72
+ -webkit-box-orient: vertical;
73
+ }
74
+
75
+ h4.truncated {
76
+ display: -webkit-box;
77
+ margin: 0px;
78
+ line-height: 15px;
79
+ font-size: 14px;
80
+ font-weight: 500;
81
+ padding-bottom: 1px;
82
+ }
83
+
84
+ span {
85
+ display: -webkit-box;
86
+ font-size: 1.4rem;
87
+ line-height: 15px;
88
+ overflow: hidden;
89
+ word-wrap: break-word;
90
+ -webkit-line-clamp: 1;
91
+ -webkit-box-orient: vertical;
92
+ padding-bottom: 1px;
93
+ }
94
+
95
+ .container:hover > .tile-details > .item-info > #title > .truncated {
96
+ text-decoration: underline;
97
+ }
98
+
99
+ /** this is a workaround for Safari 15 where the hover effects are not working */
100
+ #title:hover > .truncated {
101
+ text-decoration: underline;
102
+ }
103
+
104
+ .info-button {
105
+ position: absolute;
106
+ right: 10px;
107
+ top: 10px;
108
+ margin: 0;
109
+ padding: 0;
110
+ border: none;
111
+ border-radius: 50%;
112
+ display: flex;
113
+ justify-content: center;
114
+ align-items: center;
115
+ background: rgba(220, 220, 220, 0.5);
116
+ color: white;
117
+ font-size: 2rem;
118
+ font-weight: bold;
119
+ line-height: 1;
120
+ text-shadow: black 1px 1px 3px;
121
+ overflow: visible;
122
+ aspect-ratio: 1 / 1;
123
+ z-index: 1;
124
+ }
125
+
126
+ .hidden {
127
+ display: none;
128
+ }
129
+ `;