import { Button, createStyles, Group, HoverCard, Image, Progress, Stack, Text } from '@mantine/core'; import ReactMarkdown from 'react-markdown'; import { ContextMenuProps, Option } from '../../../../typings'; import { fetchNui } from '../../../../utils/fetchNui'; import { isIconUrl } from '../../../../utils/isIconUrl'; import { IconProp } from '@fortawesome/fontawesome-svg-core'; import MarkdownComponents from '../../../../config/MarkdownComponents'; import LibIcon from '../../../../components/LibIcon'; const openMenu = (id: string | undefined) => { fetchNui('openContext', { id: id, back: false }); }; const clickContext = (id: string) => { fetchNui('clickContext', id); }; const useStyles = createStyles((theme, params: { disabled?: boolean; readOnly?: boolean }) => ({ inner: { justifyContent: 'flex-start', }, label: { width: '100%', color: params.disabled ? theme.colors.dark[3] : theme.colors.dark[0], whiteSpace: 'pre-wrap', }, button: { height: 'fit-content', width: '100%', padding: 10, '&:hover': { backgroundColor: params.readOnly ? theme.colors.dark[6] : undefined, cursor: params.readOnly ? 'unset' : 'pointer', }, '&:active': { transform: params.readOnly ? 'unset' : undefined, }, }, iconImage: { maxWidth: '25px', }, description: { color: params.disabled ? theme.colors.dark[3] : theme.colors.dark[2], fontSize: 12, }, dropdown: { padding: 10, color: theme.colors.dark[0], fontSize: 14, maxWidth: 256, width: 'fit-content', border: 'none', }, buttonStack: { gap: 4, flex: '1', }, buttonGroup: { gap: 4, flexWrap: 'nowrap', }, buttonIconContainer: { width: 25, height: 25, justifyContent: 'center', alignItems: 'center', }, buttonTitleText: { overflowWrap: 'break-word', }, buttonArrowContainer: { justifyContent: 'center', alignItems: 'center', width: 25, height: 25, }, })); const ContextButton: React.FC<{ option: [string, Option]; }> = ({ option }) => { const button = option[1]; const buttonKey = option[0]; const { classes } = useStyles({ disabled: button.disabled, readOnly: button.readOnly }); return ( <> {button.image && } {Array.isArray(button.metadata) ? ( button.metadata.map( ( metadata: string | { label: string; value?: any; progress?: number; colorScheme?: string }, index: number ) => ( <> {typeof metadata === 'string' ? `${metadata}` : `${metadata.label}: ${metadata?.value ?? ''}`} {typeof metadata === 'object' && metadata.progress !== undefined && ( )} ) ) ) : ( <> {typeof button.metadata === 'object' && Object.entries(button.metadata).map((metadata: { [key: string]: any }, index) => ( {metadata[0]}: {metadata[1]} ))} )} ); }; export default ContextButton;