Skip to content

Commit

Permalink
Improve element rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
electrikmilk committed Apr 28, 2024
1 parent 8fbd1b7 commit 0eec84c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
19 changes: 19 additions & 0 deletions src/element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function renderElement(tag: string, attributes: object, ...elements: HTMLElement[]) {
const element = document.createElement(tag);
for (const key in attributes) {
// @ts-ignore
element[key] = attributes[key];
}

element.append(...elements);

return element;
}

export function renderText(text: string) {
return document.createTextNode(text);
}

export function renderClass(cssClass: string, ...elements: HTMLElement[]) {
return renderElement('div', {className: cssClass}, ...elements);
}
20 changes: 7 additions & 13 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,13 @@ export function renderShortcut(shortcutActions: Array<ActionData>) {
}

function renderCardContent(element: HTMLElement) {
const content = document.createElement('div');
content.className = 'card-content';

const list = document.createElement('div');
list.className = 'list';

const ul = document.createElement('ul');
ul.innerHTML = element.outerHTML;

list.appendChild(ul);
content.appendChild(list);

return content;
return renderClass('card-content',
renderClass('list',
renderElement('ul', {},
element,
)
)
)
}

function renderAction(identifier: string, action: ActionData): Node {
Expand Down

0 comments on commit 0eec84c

Please sign in to comment.