Merge pull request #1144 from dermotduffy/zoom-cursor

Show different mouse cursor when zoomed in
This commit is contained in:
Dermot Duffy
2023-05-06 14:02:45 -07:00
committed by GitHub
2 changed files with 32 additions and 3 deletions
+29 -2
View File
@@ -1,20 +1,43 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from 'lit';
import { customElement } from 'lit/decorators.js';
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
TemplateResult,
} from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { setOrRemoveAttribute } from '../utils/basic.js';
import { Zoom } from '../utils/zoom/zoom.js';
@customElement('frigate-card-zoomer')
export class FrigateCardZoomer extends LitElement {
protected _zoom = new Zoom(this);
@state()
protected _zoomed = false;
protected _zoomHandler = () => (this._zoomed = true);
protected _unzoomHandler = () => (this._zoomed = false);
connectedCallback(): void {
super.connectedCallback();
this.addEventListener('frigate-card:zoom:zoomed', this._zoomHandler);
this.addEventListener('frigate-card:zoom:unzoomed', this._unzoomHandler);
this._zoom.activate();
}
disconnectedCallback(): void {
this._zoom.deactivate();
this.removeEventListener('frigate-card:zoom:zoomed', this._zoomHandler);
this.removeEventListener('frigate-card:zoom:unzoomed', this._unzoomHandler);
}
protected willUpdate(changedProps: PropertyValues): void {
if (changedProps.has('_zoomed')) {
setOrRemoveAttribute(this, this._zoomed, 'zoomed');
}
}
protected render(): TemplateResult | void {
return html` <slot></slot> `;
}
@@ -25,6 +48,10 @@ export class FrigateCardZoomer extends LitElement {
width: 100%;
height: 100%;
display: block;
cursor: auto;
}
:host([zoomed]) {
cursor: move;
}
`;
}
+3 -1
View File
@@ -75,7 +75,9 @@ export class Zoom {
maxScale: 10,
minScale: 1,
noBind: true,
cursor: 'auto',
// Do not force the cursor style (by default it will always show the
// 'move' type cursor whether or not it is zoomed in).
cursor: undefined,
});
const registerListeners = (