Change columns to Lit state()

This commit is contained in:
Dermot Duffy
2021-09-26 14:22:15 -07:00
parent 7c0e0133ee
commit bdb211fafb
2 changed files with 11 additions and 11 deletions
+9 -11
View File
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { CSSResultGroup, LitElement, TemplateResult, html, unsafeCSS } from 'lit'; import { CSSResultGroup, LitElement, TemplateResult, html, unsafeCSS } from 'lit';
import { customElement, property } from 'lit/decorators'; import { customElement, property, state } from 'lit/decorators';
import { until } from 'lit/directives/until.js'; import { until } from 'lit/directives/until.js';
import { HomeAssistant } from 'custom-card-helpers'; import { HomeAssistant } from 'custom-card-helpers';
@@ -33,6 +33,8 @@ export class FrigateCardGallery extends LitElement {
protected browseMediaQueryParameters!: BrowseMediaQueryParameters; protected browseMediaQueryParameters!: BrowseMediaQueryParameters;
protected _resizeObserver: ResizeObserver; protected _resizeObserver: ResizeObserver;
@state()
protected _columns = DEFAULT_COLUMNS; protected _columns = DEFAULT_COLUMNS;
protected _getMediaType(): 'clips' | 'snapshots' { protected _getMediaType(): 'clips' | 'snapshots' {
@@ -53,15 +55,10 @@ export class FrigateCardGallery extends LitElement {
super.disconnectedCallback(); super.disconnectedCallback();
} }
protected _resizeHandler(): void { protected _resizeHandler(): void {
let columns = Math.floor(this.clientWidth / MAX_THUMBNAIL_WIDTH); this._columns = Math.max(
DEFAULT_COLUMNS,
if (columns < DEFAULT_COLUMNS) { Math.floor(this.clientWidth / MAX_THUMBNAIL_WIDTH),
columns = DEFAULT_COLUMNS; );
}
if (this._columns != columns) {
this._columns = columns;
this.requestUpdate();
}
} }
protected render(): TemplateResult | void { protected render(): TemplateResult | void {
@@ -90,7 +87,8 @@ export class FrigateCardGallery extends LitElement {
} }
const styles = { const styles = {
width: `calc(${100/this._columns}% - 1.2px)` // Controls the number of columns in the gallery (allows for 1px gutter).
width: `calc(${100 / this._columns}% - 1.2px)`,
}; };
console.info(this.clientWidth); console.info(this.clientWidth);
+2
View File
@@ -2,6 +2,8 @@
@use "@material/image-list"; @use "@material/image-list";
.frigate-card-gallery { .frigate-card-gallery {
// Note: In fullscreen, number of columns is overwritten in Javascript based
// on dimensions.
@include image-list.standard-columns(5, 1px); @include image-list.standard-columns(5, 1px);
@include image-list.shape-radius(5px); @include image-list.shape-radius(5px);
} }