Menu
⚠️
This page is under construction.
Menu component renders the menu container, and Item
renders the menu item.
Example
- Import the components
import { useState } from "react";
import { GameMenu, Item, useGame } from "narraleaf-react";
- Slot the components
function DefaultMenu({items}: { items: number[] }) {
return (
<GameMenu
className="absolute flex flex-col items-center justify-center min-w-full w-full h-full"
>
{items.map((index) => (
<Item
key={index}
className="bg-white text-black p-2 mt-2 w-1/2"
/>
))}
</GameMenu>
);
}
- Configure the game
function App() {
const game = useGame();
useEffect(() => {
game.configure({
menu: DefaultMenu,
});
}, []);
return /* ... */
}
Components
GameMenu
GameMenu component renders the menu container. Its children are the Item
components.
children?: React.ReactNode
- The children of the menu container....props: React.HTMLAttributes<HTMLDivElement>
- The props of the menu container.
Item
Item component renders the menu item. It is a child of the GameMenu
component.
className?: string
- The class name of the menu item.style?: React.CSSProperties
- The style of the menu item.bindKey?: string
- The keyboard binding for this item, see Key_Values (opens in a new tab) for more information. When this key is pressed, the item will be selected and the action will be executed.