Skip to content

Commit

Permalink
#8129 - move delayed popup show/hide to library
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed May 23, 2024
1 parent 7a8b280 commit 0d8bfef
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
47 changes: 47 additions & 0 deletions src/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,53 @@ export abstract class BaseAction extends Base implements IAction {
this.popupModel.hide();
}
}

@property({ defaultValue: false }) isPressed: boolean;
@property({ defaultValue: false }) isHovered: boolean;

public get classNames(): string {
return new CssClassBuilder()
.append("svc-toolbox__tool")
.append(this.css)
.append("svc-toolbox__tool--hovered", this.isHovered)
.append("svc-toolbox__tool--pressed", this.isPressed)
.toString();
}

private showPopupTimeout: NodeJS.Timeout;
private hidePopupTimeout: NodeJS.Timeout;
private clearPopupTimeouts() {
if (this.showPopupTimeout) clearTimeout(this.showPopupTimeout);
if (this.hidePopupTimeout) clearTimeout(this.hidePopupTimeout);
}
public showPopupDelayed(delay: number) {

this.clearPopupTimeouts();
this.showPopupTimeout = setTimeout(() => {
this.clearPopupTimeouts();

this.showPopup();

}, delay);
}

public hidePopupDelayed(delay: number) {
if (this.popupModel?.isVisible) {

this.clearPopupTimeouts();
this.hidePopupTimeout = setTimeout(() => {
this.clearPopupTimeouts();

this.hidePopup();
this.isHovered = false;

}, delay);
} else {
this.clearPopupTimeouts();
this.isHovered = false;
}
}

protected abstract getEnabled(): boolean;
protected abstract setEnabled(val: boolean): void;
protected abstract getVisible(): boolean;
Expand Down
19 changes: 19 additions & 0 deletions src/actions/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ export class ActionContainer<T extends BaseAction = Action> extends Base impleme
this.sortItems();
}
}
@property({ defaultValue: 300 }) subItemsShowDelay: number;
@property({ defaultValue: 300 }) subItemsHideDelay: number;
protected popupAfterShowCallback(itemValue: T): void {

}

public mouseOverHandler(itemValue: T): void {
itemValue.isHovered = true;
this.actions.forEach(action => {
if (action === itemValue && !!itemValue.popupModel) {
itemValue.showPopupDelayed(this.subItemsShowDelay);
this.popupAfterShowCallback(itemValue);

} else if (!!action.popupModel && action.popupModel.isVisible) {
action.hidePopupDelayed(this.subItemsHideDelay);
}
});
}

public initResponsivityManager(container: HTMLDivElement, delayedUpdateFunction?: (callback: () => void) => void): void {
return;
}
Expand Down
17 changes: 7 additions & 10 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,16 @@ export class ListModel<T extends BaseAction = Action> extends ActionContainer<T>
}
};

public onItemHover = (itemValue: T): void => {
this.actions.forEach(action => {
if (action === itemValue && !!itemValue.popupModel) {
itemValue.showPopup();
this.addScrollEventListener(() => {
itemValue.hidePopup();
});
} else if (!!action.popupModel && action.popupModel.isVisible) {
action.hidePopup();
}
protected popupAfterShowCallback(itemValue: T) {
this.addScrollEventListener(() => {
itemValue.hidePopup();
});
}

public onItemHover = (itemValue: T): void => {
this.mouseOverHandler(itemValue);
}

public isItemDisabled: (itemValue: T) => boolean = (itemValue: T) => {
return itemValue.enabled !== undefined && !itemValue.enabled;
};
Expand Down

0 comments on commit 0d8bfef

Please sign in to comment.