-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from NeurodataWithoutBorders/fullscreen
Create a fullscreen toggle element
- Loading branch information
Showing
7 changed files
with
173 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { LitElement, css, html } from "lit"; | ||
|
||
import fullScreenIcon from './assets/fullscreen.svg?raw' | ||
import fullScreenExitIcon from './assets/fullscreen_exit.svg?raw' | ||
|
||
import { unsafeHTML } from "lit/directives/unsafe-html.js"; | ||
|
||
type FullScreenToggleProps = { | ||
target: HTMLElement | (() => HTMLElement); | ||
} | ||
|
||
export class FullScreenToggle extends LitElement { | ||
static get styles() { | ||
return css` | ||
:host { | ||
display: flex; | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
padding: 10px; | ||
color: white; | ||
background-color: gainsboro; | ||
border: 1px solid gray; | ||
border-radius: 10px; | ||
cursor: pointer; | ||
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3); | ||
z-index: 1000; | ||
opacity: 0.5; | ||
transition: opacity 0.5s; | ||
} | ||
:host(:hover) { | ||
opacity: 1; | ||
} | ||
`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
icon: { type: String }, | ||
}; | ||
} | ||
|
||
declare icon: string; | ||
declare target: FullScreenToggleProps['target']; | ||
|
||
constructor({ target }: FullScreenToggleProps) { | ||
|
||
super(); | ||
this.target = target; | ||
this.icon = fullScreenIcon | ||
|
||
const fullscreenchanged = () => this.icon = document.fullscreenElement ? fullScreenExitIcon : fullScreenIcon | ||
|
||
this.addEventListener('click', () => { | ||
const target = (typeof this.target === 'function' ? this.target() : this.target) | ||
|
||
target.addEventListener("fullscreenchange", fullscreenchanged); | ||
|
||
const fullScreenEl = document.fullscreenElement | ||
if (!fullScreenEl) target.requestFullscreen() | ||
else document.exitFullscreen() | ||
|
||
}) | ||
} | ||
|
||
render() { | ||
return html`${unsafeHTML(this.icon)}`; | ||
} | ||
} | ||
|
||
customElements.get("fullscreen-toggle") || customElements.define("fullscreen-toggle", FullScreenToggle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters