mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(web/context): readOnly buttons
This commit is contained in:
@@ -11,6 +11,7 @@ interface ContextMenuItem {
|
|||||||
progress?: number;
|
progress?: number;
|
||||||
colorScheme?: string;
|
colorScheme?: string;
|
||||||
onSelect?: (args: any) => void;
|
onSelect?: (args: any) => void;
|
||||||
|
readOnly?: boolean;
|
||||||
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
|
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
event?: string;
|
event?: string;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const clickContext = (id: string) => {
|
|||||||
fetchNui('clickContext', id);
|
fetchNui('clickContext', id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const useStyles = createStyles((theme, params: { disabled?: boolean }) => ({
|
const useStyles = createStyles((theme, params: { disabled?: boolean; readOnly?: boolean }) => ({
|
||||||
inner: {
|
inner: {
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
},
|
},
|
||||||
@@ -28,6 +28,13 @@ const useStyles = createStyles((theme, params: { disabled?: boolean }) => ({
|
|||||||
height: 'fit-content',
|
height: 'fit-content',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: 10,
|
padding: 10,
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: params.readOnly ? theme.colors.dark[6] : undefined,
|
||||||
|
cursor: params.readOnly ? 'unset' : 'pointer',
|
||||||
|
},
|
||||||
|
'&:active': {
|
||||||
|
transform: params.readOnly ? 'unset' : undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
iconImage: {
|
iconImage: {
|
||||||
maxWidth: '25px',
|
maxWidth: '25px',
|
||||||
@@ -74,7 +81,7 @@ const ContextButton: React.FC<{
|
|||||||
}> = ({ option }) => {
|
}> = ({ option }) => {
|
||||||
const button = option[1];
|
const button = option[1];
|
||||||
const buttonKey = option[0];
|
const buttonKey = option[0];
|
||||||
const { classes } = useStyles({ disabled: button.disabled });
|
const { classes } = useStyles({ disabled: button.disabled, readOnly: button.readOnly });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -85,10 +92,15 @@ const ContextButton: React.FC<{
|
|||||||
>
|
>
|
||||||
<HoverCard.Target>
|
<HoverCard.Target>
|
||||||
<Button
|
<Button
|
||||||
classNames={{ inner: classes.inner, label: classes.label }}
|
classNames={{ inner: classes.inner, label: classes.label, root: classes.button }}
|
||||||
onClick={() => (!button.disabled ? (button.menu ? openMenu(button.menu) : clickContext(buttonKey)) : null)}
|
onClick={() =>
|
||||||
|
!button.disabled && !button.readOnly
|
||||||
|
? button.menu
|
||||||
|
? openMenu(button.menu)
|
||||||
|
: clickContext(buttonKey)
|
||||||
|
: null
|
||||||
|
}
|
||||||
variant="default"
|
variant="default"
|
||||||
className={classes.button}
|
|
||||||
disabled={button.disabled}
|
disabled={button.disabled}
|
||||||
>
|
>
|
||||||
<Group position="apart" w="100%" noWrap>
|
<Group position="apart" w="100%" noWrap>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface Option {
|
|||||||
iconColor?: string;
|
iconColor?: string;
|
||||||
progress?: number;
|
progress?: number;
|
||||||
colorScheme?: string;
|
colorScheme?: string;
|
||||||
|
readOnly?: boolean;
|
||||||
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
|
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress?: number }[];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
event?: string;
|
event?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user