feat(web/menu): visibility handling

This commit is contained in:
Luke
2022-07-31 13:34:40 +02:00
committed by Luke
parent e97bd98726
commit 6ef17e83f5
2 changed files with 55 additions and 44 deletions

View File

@@ -36,21 +36,19 @@ end)
RegisterNUICallback('changeSelected', function(data, cb) RegisterNUICallback('changeSelected', function(data, cb)
cb(1) cb(1)
if registeredMenus[openMenu].onChange then if not registeredMenus[openMenu].onChange then return end
local selected = data local selected = data
if type(selected) == 'number' then if type(selected) == 'number' then
registeredMenus[openMenu].onChange(selected) registeredMenus[openMenu].onChange(selected)
else else
registeredMenus[openMenu].onChange(selected[1], selected[2]) registeredMenus[openMenu].onChange(selected[1], selected[2])
end end
end
end) end)
RegisterCommand('testMenu', function() RegisterCommand('testMenu', function()
lib.registerMenu({ lib.registerMenu({
id = 'epic_menu', id = 'epic_menu',
title = 'Nice menu', title = 'Nice menu',
position = 'top-right',
onChange = function(selected, scrollIndex) onChange = function(selected, scrollIndex)
print(selected, scrollIndex) print(selected, scrollIndex)
end, end,
@@ -60,6 +58,17 @@ RegisterCommand('testMenu', function()
} }
}, function(selected, scrollIndex) }, function(selected, scrollIndex)
print(selected, scrollIndex) print(selected, scrollIndex)
lib.registerMenu({
id = 'more_epic_menu',
title = 'Nicer menu',
position = 'top-right',
options = {
{label = 'Extra nice option'},
{label = 'Giga nice option'},
{label = 'Omega nice option'},
}
}, function() end)
lib.showMenu('more_epic_menu')
end) end)
lib.showMenu('epic_menu') lib.showMenu('epic_menu')
end) end)

View File

@@ -122,6 +122,7 @@ const ListMenu: React.FC = () => {
return ( return (
<> <>
{visible && (
<Box <Box
position="absolute" position="absolute"
pointerEvents="none" pointerEvents="none"
@@ -161,6 +162,7 @@ const ListMenu: React.FC = () => {
</FocusTrap> </FocusTrap>
</Box> </Box>
</Box> </Box>
)}
</> </>
); );
}; };