mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-15 03:44:31 +08:00
add dataset option
This commit is contained in:
parent
4521dc7301
commit
c3484630e2
1 changed files with 6 additions and 0 deletions
|
|
@ -91,12 +91,18 @@ export function createElementWithUtils<T extends HTMLElement>(
|
|||
tagName: string,
|
||||
options?: {
|
||||
classList?: string[];
|
||||
dataset?: Record<string, string>;
|
||||
},
|
||||
): ElementWithUtils<T> {
|
||||
const element = document.createElement(tagName) as T;
|
||||
if (options?.classList !== undefined) {
|
||||
element.classList.add(...options.classList);
|
||||
}
|
||||
if (options?.dataset !== undefined) {
|
||||
for (const key of Object.keys(options.dataset)) {
|
||||
element.dataset[key] = options.dataset[key];
|
||||
}
|
||||
}
|
||||
return new ElementWithUtils(element);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue