feat(web/context): disabled buttons

This commit is contained in:
Luke
2022-11-06 11:01:39 +01:00
parent 33b70b6f1c
commit 306b7b3670
6 changed files with 15 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ interface ContextMenuItem {
arrow?: boolean; arrow?: boolean;
description?: string; description?: string;
metadata?: string | { [key: string]: any } | string[]; metadata?: string | { [key: string]: any } | string[];
disabled?: boolean;
event?: string; event?: string;
serverEvent?: string; serverEvent?: string;
args?: any; args?: any;

View File

@@ -10,6 +10,7 @@ local openContextMenu = nil
---@field arrow? boolean ---@field arrow? boolean
---@field description? string ---@field description? string
---@field metadata? string | { [string]: any } | string[] ---@field metadata? string | { [string]: any } | string[]
---@field disabled? boolean
---@field event? string ---@field event? string
---@field serverEvent? string ---@field serverEvent? string
---@field args? any ---@field args? any

View File

@@ -15,6 +15,7 @@ export const debugContext = () => {
icon: 'inbox', icon: 'inbox',
image: 'https://i.imgur.com/YAe7k17.jpeg', image: 'https://i.imgur.com/YAe7k17.jpeg',
metadata: [{ label: 'Value 1', value: 300 }], metadata: [{ label: 'Value 1', value: 300 }],
disabled: true,
}, },
{ {
title: 'Menu button', title: 'Menu button',

View File

@@ -7,7 +7,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { fetchNui } from '../../../utils/fetchNui'; import { fetchNui } from '../../../utils/fetchNui';
const openMenu = (id: string | undefined) => { const openMenu = (id: string | undefined) => {
fetchNui<ContextMenuProps>('openContext', {id: id, back: true}); fetchNui<ContextMenuProps>('openContext', { id: id, back: true });
}; };
const ContextMenu: React.FC = () => { const ContextMenu: React.FC = () => {

View File

@@ -34,7 +34,7 @@ const Item: React.FC<{
<Popover placement="right-start" trigger="hover" eventListeners={{ scroll: true }} isLazy> <Popover placement="right-start" trigger="hover" eventListeners={{ scroll: true }} isLazy>
<PopoverTrigger> <PopoverTrigger>
<Box <Box
bg="gray.800" bg={button.disabled ? 'gray.600' : 'gray.800'}
borderRadius="md" borderRadius="md"
h="fit-content" h="fit-content"
w="100%" w="100%"
@@ -43,12 +43,16 @@ const Item: React.FC<{
fontFamily="Poppins" fontFamily="Poppins"
fontSize="md" fontSize="md"
transition="300ms" transition="300ms"
_hover={{ bg: 'gray.700' }} _hover={{ bg: !button.disabled && 'gray.700' }}
cursor={(button.disabled && 'not-allowed') || undefined}
> >
<Flex <Flex
w="100%" w="100%"
alignItems="center" alignItems="center"
onClick={() => (button.menu ? openMenu(button.menu) : clickContext(buttonKey))} color={button.disabled ? '#718096' : undefined}
onClick={() =>
!button.disabled ? (button.menu ? openMenu(button.menu) : clickContext(buttonKey)) : null
}
> >
{button?.icon && ( {button?.icon && (
<FontAwesomeIcon <FontAwesomeIcon
@@ -64,12 +68,12 @@ const Item: React.FC<{
)} )}
<Box> <Box>
<Box paddingBottom={button.description ? 1 : 0}> <Box paddingBottom={button.description ? 1 : 0}>
<Text w="100%" fontWeight="medium"> <Text w="100%" fontWeight="medium" color={button.disabled ? '#718096' : undefined}>
{button.title ? button.title : buttonKey} {button.title ? button.title : buttonKey}
</Text> </Text>
</Box> </Box>
{button.description && ( {button.description && (
<Box paddingBottom={1}> <Box paddingBottom={1} color={button.disabled ? '#718096' : undefined}>
<Text>{button.description}</Text> <Text>{button.description}</Text>
</Box> </Box>
)} )}
@@ -84,7 +88,7 @@ const Item: React.FC<{
)} )}
</Flex> </Flex>
<Portal> <Portal>
{(button.metadata || button.image) && ( {!button.disabled && (button.metadata || button.image) && (
<PopoverContent <PopoverContent
fontFamily="Poppins" fontFamily="Poppins"
bg="gray.800" bg="gray.800"

View File

@@ -9,6 +9,7 @@ export interface Option {
icon?: IconProp; icon?: IconProp;
iconColor?: string; iconColor?: string;
metadata?: string[] | { [key: string]: any } | { label: string; value: any }[]; metadata?: string[] | { [key: string]: any } | { label: string; value: any }[];
disabled?: boolean;
event?: string; event?: string;
serverEvent?: string; serverEvent?: string;
args?: any; args?: any;