Show different mouse cursor when zoomed in.
This commit is contained in:
@@ -1,20 +1,43 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from 'lit';
|
import {
|
||||||
import { customElement } from 'lit/decorators.js';
|
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';
|
import { Zoom } from '../utils/zoom/zoom.js';
|
||||||
|
|
||||||
@customElement('frigate-card-zoomer')
|
@customElement('frigate-card-zoomer')
|
||||||
export class FrigateCardZoomer extends LitElement {
|
export class FrigateCardZoomer extends LitElement {
|
||||||
protected _zoom = new Zoom(this);
|
protected _zoom = new Zoom(this);
|
||||||
|
|
||||||
|
@state()
|
||||||
|
protected _zoomed = false;
|
||||||
|
|
||||||
|
protected _zoomHandler = () => (this._zoomed = true);
|
||||||
|
protected _unzoomHandler = () => (this._zoomed = false);
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
this.addEventListener('frigate-card:zoom:zoomed', this._zoomHandler);
|
||||||
|
this.addEventListener('frigate-card:zoom:unzoomed', this._unzoomHandler);
|
||||||
this._zoom.activate();
|
this._zoom.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback(): void {
|
disconnectedCallback(): void {
|
||||||
this._zoom.deactivate();
|
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 {
|
protected render(): TemplateResult | void {
|
||||||
return html` <slot></slot> `;
|
return html` <slot></slot> `;
|
||||||
}
|
}
|
||||||
@@ -25,6 +48,10 @@ export class FrigateCardZoomer extends LitElement {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: block;
|
display: block;
|
||||||
|
cursor: auto;
|
||||||
|
}
|
||||||
|
:host([zoomed]) {
|
||||||
|
cursor: move;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ export class Zoom {
|
|||||||
maxScale: 10,
|
maxScale: 10,
|
||||||
minScale: 1,
|
minScale: 1,
|
||||||
noBind: true,
|
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 = (
|
const registerListeners = (
|
||||||
|
|||||||
Reference in New Issue
Block a user