Skip to content

Commit

Permalink
feat(player): expose hideOnMouseLeave prop on controls component
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Dec 2, 2023
1 parent e0b0ab1 commit 7eeabdd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/vidstack/src/components/ui/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { setAttributeIfEmpty } from '../../utils/dom';
export class Controls extends Component<ControlsProps, {}, ControlsEvents> {
static props: ControlsProps = {
hideDelay: 2000,
hideOnMouseLeave: false,
};

private _media!: MediaContext;

protected override onSetup(): void {
this._media = useMediaContext();
effect(this._watchHideDelay.bind(this));
effect(this._watchProps.bind(this));
}

protected override onAttach(el: HTMLElement): void {
Expand Down Expand Up @@ -61,12 +62,13 @@ export class Controls extends Component<ControlsProps, {}, ControlsEvents> {
setStyle(this.el, 'display', isHidden ? 'none' : null);
}

private _watchHideDelay() {
private _watchProps() {
const { controls } = this._media.player,
{ hideDelay } = this.$props;
{ hideDelay, hideOnMouseLeave } = this.$props;

// Use controls delay prop on player if this is the default value.
controls.defaultDelay = hideDelay() === 2000 ? this._media.$props.controlsDelay() : hideDelay();
controls.hideOnMouseLeave = hideOnMouseLeave();
}

private _isShowing() {
Expand All @@ -81,6 +83,11 @@ export interface ControlsProps {
* activity to hide the controls.
*/
hideDelay: number;
/**
* Whether controls visibility should be toggled when the mouse enters and leaves the player
* container.
*/
hideOnMouseLeave: boolean;
}

export interface ControlsEvents {
Expand Down

0 comments on commit 7eeabdd

Please sign in to comment.