Skip to content

Commit

Permalink
ref: tsx-ify BytmMenu class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Feb 9, 2024
1 parent e6f4012 commit d1a25c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
24 changes: 18 additions & 6 deletions src/menu/new/BytmMenu.ts → src/menu/new/BytmMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as ReactDOM from "react-dom";
import * as React from "react";
import { clearInner, NanoEmitter, warn } from "../../utils";
import menuTemplateHtml from "./menuTemplate.html";

export interface BytmMenuConfig {
/** ID that gets added to all child element IDs and class names */
id: string;
/** Called to render the body of the menu */
renderBody: (bodyContainer: HTMLElement) => HTMLElement;
renderBody: () => React.ReactNode;
/** Called to render the header of the menu - leave undefined for a blank header */
renderHeader?: (headerContainer: HTMLElement) => HTMLElement;
renderHeader?: () => React.ReactNode;
/** Called to render the footer of the menu - leave undefined for no footer */
renderFooter?: (footerContainer: HTMLElement) => HTMLElement;
renderFooter?: () => React.ReactNode;
}

interface BytmMenuEventsMap {
Expand All @@ -23,7 +24,6 @@ interface BytmMenuEventsMap {
clear: () => void;
}

// TODO: expose on interface
/** Creates and manages a modal menu element */
export class BytmMenu extends NanoEmitter<BytmMenuEventsMap> {
public readonly config;
Expand All @@ -43,12 +43,13 @@ export class BytmMenu extends NanoEmitter<BytmMenuEventsMap> {
const bgElem = document.createElement("div");
bgElem.id = `bytm-${this.id}-menu-bg`;
bgElem.classList.add("bytm-menu-bg");
bgElem.innerHTML = menuTemplateHtml;
bgElem.style.visibility = "hidden";
bgElem.style.display = "none";

document.body.appendChild(bgElem);

ReactDOM.render(<MenuContent></MenuContent>, bgElem);

this.events.emit("render");
}

Expand Down Expand Up @@ -110,3 +111,14 @@ export class BytmMenu extends NanoEmitter<BytmMenuEventsMap> {
this.events.emit("close");
}
}

function MenuContent() {
// TODO:
return (
<div className="bytm-menu-content">
<div className="bytm-menu-header" id="bytm-menu-header"></div>
<div className="bytm-menu-body" id="bytm-menu-body"></div>
<div className="bytm-menu-footer" id="bytm-menu-footer"></div>
</div>
);
}
14 changes: 0 additions & 14 deletions src/menu/new/menuTemplate.html

This file was deleted.

0 comments on commit d1a25c9

Please sign in to comment.