Skip to content

Commit 719b942

Browse files
author
kai
committed
Accept multiple elements
1 parent 48ab766 commit 719b942

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/BaseComponent.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,24 @@ export abstract class BaseComponent<T extends Element> {
5656
/**
5757
* Insert component after the last child
5858
*/
59-
public append(component?: BaseComponent<any> | null) {
60-
if (!component) return this;
61-
this.element.appendChild(component.element);
59+
public append(...components: BaseComponent<any>[]) {
60+
components.map((component) => this.element.appendChild(component.element))
6261
return this;
6362
}
6463

6564
/**
6665
* Insert component before the first child
6766
*/
68-
public prepend(component?: BaseComponent<any> | null) {
69-
if (!component) return this;
70-
this.element.prepend(component.element);
67+
public prepend(...components: BaseComponent<any>[]) {
68+
components.map((component) => this.element.appendChild(component.element))
7169
return this;
7270
}
7371

7472
/**
7573
* Add classes
7674
*/
7775
public class(...classes: string[]) {
78-
this.element.classList.add(...classes.flatMap(c => c.split(" ")));
76+
this.element.classList.add(...classes.flatMap(c => c.split(" ")));
7977
return this;
8078
}
8179

0 commit comments

Comments
 (0)