feat(web/context): readOnly buttons

This commit is contained in:
Luke
2023-09-22 13:49:15 +02:00
parent c9246bb392
commit aaa37047f1
3 changed files with 19 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ interface ContextMenuItem {
progress?: number;
colorScheme?: string;
onSelect?: (args: any) => void;
readOnly?: boolean;
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
disabled?: boolean;
event?: string;

View File

@@ -15,7 +15,7 @@ const clickContext = (id: string) => {
fetchNui('clickContext', id);
};
const useStyles = createStyles((theme, params: { disabled?: boolean }) => ({
const useStyles = createStyles((theme, params: { disabled?: boolean; readOnly?: boolean }) => ({
inner: {
justifyContent: 'flex-start',
},
@@ -28,6 +28,13 @@ const useStyles = createStyles((theme, params: { disabled?: boolean }) => ({
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',
@@ -74,7 +81,7 @@ const ContextButton: React.FC<{
}> = ({ option }) => {
const button = option[1];
const buttonKey = option[0];
const { classes } = useStyles({ disabled: button.disabled });
const { classes } = useStyles({ disabled: button.disabled, readOnly: button.readOnly });
return (
<>
@@ -85,10 +92,15 @@ const ContextButton: React.FC<{
>
<HoverCard.Target>
<Button
classNames={{ inner: classes.inner, label: classes.label }}
onClick={() => (!button.disabled ? (button.menu ? openMenu(button.menu) : clickContext(buttonKey)) : null)}
classNames={{ inner: classes.inner, label: classes.label, root: classes.button }}
onClick={() =>
!button.disabled && !button.readOnly
? button.menu
? openMenu(button.menu)
: clickContext(buttonKey)
: null
}
variant="default"
className={classes.button}
disabled={button.disabled}
>
<Group position="apart" w="100%" noWrap>

View File

@@ -10,6 +10,7 @@ export interface Option {
iconColor?: string;
progress?: number;
colorScheme?: string;
readOnly?: boolean;
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
disabled?: boolean;
event?: string;