2024-06-27 11:28:06 -04:00
|
|
|
import {EditorContainerUiElement, EditorUiElement} from "../core";
|
|
|
|
import {EditorDropdownButton} from "./dropdown-button";
|
|
|
|
import moreHorizontal from "@icons/editor/more-horizontal.svg"
|
2024-08-03 13:14:01 -04:00
|
|
|
import {el} from "../../../utils/dom";
|
2024-06-27 11:28:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
export class EditorOverflowContainer extends EditorContainerUiElement {
|
|
|
|
|
|
|
|
protected size: number;
|
|
|
|
protected overflowButton: EditorDropdownButton;
|
|
|
|
protected content: EditorUiElement[];
|
|
|
|
|
|
|
|
constructor(size: number, children: EditorUiElement[]) {
|
|
|
|
super(children);
|
|
|
|
this.size = size;
|
|
|
|
this.content = children;
|
|
|
|
this.overflowButton = new EditorDropdownButton({
|
2024-08-02 06:16:54 -04:00
|
|
|
button: {
|
|
|
|
label: 'More',
|
|
|
|
icon: moreHorizontal,
|
|
|
|
},
|
|
|
|
}, []);
|
2024-06-27 11:28:06 -04:00
|
|
|
this.addChildren(this.overflowButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected buildDOM(): HTMLElement {
|
2024-07-04 11:16:16 -04:00
|
|
|
const slicePosition = this.content.length > this.size ? this.size - 1 : this.size;
|
|
|
|
const visibleChildren = this.content.slice(0, slicePosition);
|
|
|
|
const invisibleChildren = this.content.slice(slicePosition);
|
2024-06-27 11:28:06 -04:00
|
|
|
|
|
|
|
const visibleElements = visibleChildren.map(child => child.getDOMElement());
|
|
|
|
if (invisibleChildren.length > 0) {
|
|
|
|
this.removeChildren(...invisibleChildren);
|
|
|
|
this.overflowButton.insertItems(...invisibleChildren);
|
|
|
|
visibleElements.push(this.overflowButton.getDOMElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
return el('div', {
|
|
|
|
class: 'editor-overflow-container',
|
|
|
|
}, visibleElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|