mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
feat(nui): Context menu Lua callbacks
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useNuiEvent } from "../../../hooks/useNuiEvent";
|
||||
import { Box, Text, Flex, ScaleFade } from "@chakra-ui/react";
|
||||
import { debugData } from "../../../utils/debugData";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ContextMenuProps } from "../../../interfaces";
|
||||
import Item from "./Item";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
@@ -52,6 +52,24 @@ const ContextMenu: React.FC = () => {
|
||||
options: { "": { description: "", metadata: [] } },
|
||||
});
|
||||
|
||||
// Hides the context menu on ESC
|
||||
useEffect(() => {
|
||||
if (!visible) return;
|
||||
|
||||
const keyHandler = (e: KeyboardEvent) => {
|
||||
if (["Escape"].includes(e.code)) {
|
||||
setVisible(false);
|
||||
fetchNui("closeContext");
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", keyHandler);
|
||||
|
||||
return () => window.removeEventListener("keydown", keyHandler);
|
||||
}, [visible]);
|
||||
|
||||
useNuiEvent("hideContext", () => setVisible(false));
|
||||
|
||||
useNuiEvent<ContextMenuProps>("showContext", async (data) => {
|
||||
if (visible) {
|
||||
setVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user