feat(core): add fullscreen button component (#459)

This commit is contained in:
rahim
2026-02-06 14:39:09 +11:00
committed by GitHub
parent 7b8bc11f9f
commit 3c4152fb58
10 changed files with 397 additions and 7 deletions
@@ -0,0 +1,9 @@
import { FullscreenButtonElement } from '../../ui/fullscreen-button/fullscreen-button-element';
customElements.define(FullscreenButtonElement.tagName, FullscreenButtonElement);
declare global {
interface HTMLElementTagNameMap {
[FullscreenButtonElement.tagName]: FullscreenButtonElement;
}
}
+2 -3
View File
@@ -13,11 +13,10 @@ export * from './player/player-mixin';
export * from './store/container-mixin';
export * from './store/provider-mixin';
export * from './store/types';
// UI Components
export { FullscreenButtonElement } from './ui/fullscreen-button/fullscreen-button-element';
// Primitives
export * from './ui/media-element';
// UI Components
export { MuteButtonElement } from './ui/mute-button/mute-button-element';
export { PlayButtonElement } from './ui/play-button/play-button-element';
export { TimeElement } from './ui/time/time-element';
@@ -0,0 +1,71 @@
import type { PropertyValues } from '@lit/reactive-element';
import { FullscreenButtonCore } from '@videojs/core';
import {
applyElementProps,
applyStateDataAttrs,
createButton,
logMissingFeature,
selectFullscreen,
} from '@videojs/core/dom';
import { playerContext } from '../../player/context';
import { PlayerController } from '../../player/player-controller';
import { MediaElement } from '../media-element';
export class FullscreenButtonElement extends MediaElement {
static readonly tagName = 'media-fullscreen-button';
static override properties = {
label: { type: String },
disabled: { type: Boolean },
};
label = '';
disabled = false;
readonly #core = new FullscreenButtonCore();
readonly #state = new PlayerController(this, playerContext, selectFullscreen);
#disconnect: AbortController | null = null;
override connectedCallback(): void {
super.connectedCallback();
this.#disconnect = new AbortController();
const buttonProps = createButton({
onActivate: () => this.#core.toggle(this.#state.value!),
isDisabled: () => this.disabled || !this.#state.value,
});
applyElementProps(this, buttonProps, this.#disconnect.signal);
if (!this.#state.value) {
logMissingFeature(FullscreenButtonElement.tagName, 'fullscreen');
}
}
override disconnectedCallback(): void {
super.disconnectedCallback();
this.#disconnect?.abort();
this.#disconnect = null;
}
protected override willUpdate(changed: PropertyValues): void {
super.willUpdate(changed);
this.#core.setProps(this);
}
protected override update(changed: PropertyValues): void {
super.update(changed);
const state = this.#state.value;
if (!state) {
return;
}
applyElementProps(this, this.#core.getAttrs(state));
applyStateDataAttrs(this, this.#core.getState(state));
}
}