Skip to content

Commit 3e8829d

Browse files
authored
WEBDEV-8134 Add minimal layout type to item & collection tiles (#547)
* Expose 'minimal' layout type for collection tiles * Handle 'minimal' layout type correctly in item tiles too * Apply minimal class to item-tile as needed * Add demo app toggle for minimal tiles * Improve naming of layout type property & options * Fix obsolete name in app-root
1 parent e5cf239 commit 3e8829d

File tree

5 files changed

+75
-14
lines changed

5 files changed

+75
-14
lines changed

src/app-root.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manag
1616
import type { CollectionBrowser } from '../src/collection-browser';
1717

1818
import '../src/collection-browser';
19+
import { InfiniteScroller } from '@internetarchive/infinite-scroller';
20+
import { TileDispatcher } from './tiles/tile-dispatcher';
1921

2022
@customElement('app-root')
2123
export class AppRoot extends LitElement {
@@ -396,6 +398,14 @@ export class AppRoot extends LitElement {
396398
/>
397399
<label for="show-outline-check">Show cell outlines</label>
398400
</div>
401+
<div class="checkbox-control">
402+
<input
403+
type="checkbox"
404+
id="minimal-tiles-check"
405+
@click=${this.minimalTilesChanged}
406+
/>
407+
<label for="minimal-tiles-check">Minimal tile layouts</label>
408+
</div>
399409
</fieldset>
400410
401411
<fieldset class="user-profile-controls">
@@ -587,6 +597,22 @@ export class AppRoot extends LitElement {
587597
}
588598
}
589599

600+
private minimalTilesChanged(e: Event) {
601+
const target = e.target as HTMLInputElement;
602+
const scroller = this.collectionBrowser?.shadowRoot!.querySelector(
603+
'infinite-scroller',
604+
) as InfiniteScroller;
605+
const tileDispatchers = [
606+
...scroller.shadowRoot!.querySelectorAll('tile-dispatcher'),
607+
] as TileDispatcher[];
608+
609+
if (target.checked) {
610+
tileDispatchers?.forEach(tile => (tile.layoutType = 'minimal'));
611+
} else {
612+
tileDispatchers?.forEach(tile => (tile.layoutType = 'default'));
613+
}
614+
}
615+
590616
private toggleDevTools() {
591617
const pageUrl = new URL(window.location.href);
592618
const { searchParams } = pageUrl;

src/tiles/grid/collection-tile.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { css, CSSResultGroup, html, nothing, TemplateResult } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
3+
import { classMap } from 'lit/directives/class-map.js';
34
import { msg } from '@lit/localize';
45
import { collectionIcon } from '../../assets/img/icons/mediatype/collection';
56
import { formatUnitSize } from '../../utils/format-unit-size';
67
import { baseTileStyles } from './styles/tile-grid-shared-styles';
78
import { BaseTileComponent } from '../base-tile-component';
9+
import { LayoutType } from '../models';
810
import '../image-block';
911

1012
@customElement('collection-tile')
@@ -27,9 +29,16 @@ export class CollectionTile extends BaseTileComponent {
2729

2830
@property({ type: Boolean }) showInfoButton = false;
2931

32+
@property({ type: String }) layoutType: LayoutType = 'default';
33+
3034
render() {
35+
const containerClasses = classMap({
36+
container: true,
37+
minimal: this.layoutType === 'minimal',
38+
});
39+
3140
return html`
32-
<div class="container">
41+
<div class=${containerClasses}>
3342
${this.infoButtonTemplate}
3443
<div class="tile-details">
3544
<div class="item-info">
@@ -157,6 +166,18 @@ export class CollectionTile extends BaseTileComponent {
157166
flex-direction: column;
158167
margin-left: 10px;
159168
}
169+
170+
.minimal #item-stats {
171+
display: none;
172+
}
173+
174+
.minimal .truncated {
175+
-webkit-line-clamp: initial;
176+
}
177+
178+
.minimal .item-info {
179+
padding-bottom: 5px;
180+
}
160181
`,
161182
];
162183
}

src/tiles/grid/item-tile.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { DateFormat } from '../../utils/format-date';
1010
import { isFirstMillisecondOfUTCYear } from '../../utils/local-date-from-utc';
1111
import { BaseTileComponent } from '../base-tile-component';
1212
import { baseTileStyles } from './styles/tile-grid-shared-styles';
13-
import { SimpleLayoutType } from '../models';
13+
import { LayoutType } from '../models';
1414

1515
import '../image-block';
1616
import '../review-block';
@@ -42,15 +42,16 @@ export class ItemTile extends BaseTileComponent {
4242

4343
@property({ type: Boolean }) showTvClips = false;
4444

45-
@property({ type: String }) simpleLayoutType: SimpleLayoutType = 'none';
45+
@property({ type: String }) layoutType: LayoutType = 'default';
4646

4747
render() {
4848
const itemTitle = this.model?.title;
4949
const containerClasses = classMap({
5050
container: true,
51-
simple: this.simpleLayoutType !== 'none',
52-
'stats-only': this.simpleLayoutType === 'stats-only',
53-
'snippets-only': this.simpleLayoutType === 'snippets-only',
51+
simple: this.layoutType !== 'default',
52+
'stats-only': this.layoutType === 'stats-only',
53+
'snippets-only': this.layoutType === 'snippets-only',
54+
minimal: this.layoutType === 'minimal',
5455
});
5556

5657
return html`
@@ -175,8 +176,10 @@ export class ItemTile extends BaseTileComponent {
175176
}
176177

177178
private get textSnippetsTemplate(): TemplateResult | typeof nothing {
178-
if (!this.hasSnippets || this.simpleLayoutType === 'stats-only')
179+
if (!this.hasSnippets) return nothing;
180+
if (['stats-only', 'minimal'].includes(this.layoutType)) {
179181
return nothing;
182+
}
180183

181184
return html`
182185
<text-snippet-block viewsize="grid" .snippets=${this.model?.snippets}>
@@ -221,7 +224,9 @@ export class ItemTile extends BaseTileComponent {
221224
* Template for the stats row along the bottom of the tile.
222225
*/
223226
private get tileStatsTemplate(): TemplateResult | typeof nothing {
224-
if (this.simpleLayoutType === 'snippets-only') return nothing;
227+
if (['snippets-only', 'minimal'].includes(this.layoutType)) {
228+
return nothing;
229+
}
225230

226231
const effectiveSort = this.sortParam ?? this.defaultSortParam;
227232
const [viewCount, viewLabel] =
@@ -301,7 +306,8 @@ export class ItemTile extends BaseTileComponent {
301306
-webkit-line-clamp: 1;
302307
}
303308
304-
.simple.snippets-only .item-info {
309+
.simple.snippets-only .item-info,
310+
.simple.minimal .item-info {
305311
padding-bottom: 5px;
306312
}
307313

src/tiles/models.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
export type SimpleLayoutType = 'none' | 'stats-only' | 'snippets-only';
1+
/**
2+
* What type of simplified tile layout to use.
3+
* - `default`: Do not apply any layout simplifications.
4+
* - `stats-only`: Only show the tile stats row, but not text snippets.
5+
* - `snippets-only`: Only show the text snippets row (if snippets exist), but not tile stats.
6+
* - `minimal`: Show neither tile stats nor the text snippets.
7+
*/
8+
export type LayoutType = 'default' | 'stats-only' | 'snippets-only' | 'minimal';

src/tiles/tile-dispatcher.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import './list/tile-list-compact';
1818
import './list/tile-list-compact-header';
1919
import type { TileHoverPane } from './hover/tile-hover-pane';
2020
import { BaseTileComponent } from './base-tile-component';
21-
import { SimpleLayoutType } from './models';
21+
import { LayoutType } from './models';
2222
import {
2323
HoverPaneController,
2424
HoverPaneControllerInterface,
@@ -62,8 +62,8 @@ export class TileDispatcher
6262

6363
@property({ type: Boolean }) showTvClips = false;
6464

65-
/** What type of simple layout to use in grid mode, if any */
66-
@property({ type: String }) simpleLayoutType: SimpleLayoutType = 'none';
65+
/** What type of simplified layout to use in grid mode, if any */
66+
@property({ type: String }) layoutType: LayoutType = 'default';
6767

6868
/** Whether this tile should include a hover pane at all (for applicable tile modes) */
6969
@property({ type: Boolean }) enableHoverPane = false;
@@ -325,6 +325,7 @@ export class TileDispatcher
325325
.creatorFilter=${creatorFilter}
326326
.suppressBlurring=${this.suppressBlurring}
327327
.isManageView=${this.isManageView}
328+
.layoutType=${this.layoutType}
328329
?showInfoButton=${!this.isHoverEnabled}
329330
@infoButtonPressed=${this.tileInfoButtonPressed}
330331
>
@@ -370,7 +371,7 @@ export class TileDispatcher
370371
.loggedIn=${this.loggedIn}
371372
.suppressBlurring=${this.suppressBlurring}
372373
.isManageView=${this.isManageView}
373-
.simpleLayoutType=${this.simpleLayoutType}
374+
.layoutType=${this.layoutType}
374375
?showTvClips=${this.showTvClips}
375376
?showInfoButton=${!this.isHoverEnabled}
376377
?useLocalTime=${this.useLocalTime}

0 commit comments

Comments
 (0)