editor.js/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.ts
2024-05-04 17:15:19 +03:00

58 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PopoverItem } from '../popover-item';
import { PopoverItemHtmlParams } from '../popover-item.types';
import { css } from './popover-item-html.const';
import Dom from '../../../../../dom';
/**
* Represents popover item with custom html content
*/
export class PopoverItemHtml extends PopoverItem {
/**
* Item html elements
*/
private nodes: { root: HTMLElement };
/**
* Constructs the instance
*
* @param params instance parameters
*/
constructor(params: PopoverItemHtmlParams) {
super();
this.nodes = {
root: Dom.make('div', css.root),
};
this.nodes.root.appendChild(params.element);
}
/**
* Returns popover item root element
*/
public getElement(): HTMLElement {
return this.nodes.root;
}
/**
* Toggles item hidden state
*
* @param isHidden - true if item should be hidden
*/
public toggleHidden(isHidden: boolean): void {
this.nodes.root?.classList.toggle(css.hidden, isHidden);
}
/**
* Returns list of buttons and inputs inside custom content
*/
public getControls(): HTMLElement[] {
/** Query buttons and inputs inside custom html */
const controls = this.nodes.root.querySelectorAll<HTMLElement>(
`button, ${Dom.allInputsSelector}`
);
return Array.from(controls);
}
}