2024-01-09 14:41:42 +11:00
|
|
|
import type { IconName, IconPrefix } from '@fortawesome/fontawesome-common-types';
|
2022-09-14 13:50:32 +02:00
|
|
|
|
|
|
|
|
type MenuPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
2022-10-29 12:23:15 +02:00
|
|
|
type ChangeFunction = (selected: number, scrollIndex?: number, args?: any, checked?: boolean) => void;
|
2023-11-15 15:28:21 +01:00
|
|
|
type IconAnimation = 'spin' | 'spinPulse' | 'spinReverse' | 'pulse' | 'beat' | 'fade' | 'beatFade' | 'bounce' | 'shake';
|
2022-09-14 13:50:32 +02:00
|
|
|
|
|
|
|
|
interface MenuOptions {
|
|
|
|
|
label: string;
|
2023-02-19 20:53:48 +08:00
|
|
|
icon?: IconName | [IconPrefix, IconName] | string;
|
2023-11-15 15:28:21 +01:00
|
|
|
iconColor?: string;
|
|
|
|
|
iconAnimation?: IconAnimation;
|
2022-10-29 12:23:15 +02:00
|
|
|
checked?: boolean;
|
2022-10-27 10:09:48 +02:00
|
|
|
values?: Array<string | { label: string; description: string }>;
|
2022-09-14 13:50:32 +02:00
|
|
|
description?: string;
|
|
|
|
|
defaultIndex?: number;
|
2022-10-29 15:52:59 +02:00
|
|
|
args?: Record<any, any>;
|
2022-09-30 09:57:02 +02:00
|
|
|
close?: boolean;
|
2022-09-14 13:50:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface MenuProps {
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
|
|
|
|
options: MenuOptions[];
|
|
|
|
|
position?: MenuPosition;
|
|
|
|
|
disableInput?: boolean;
|
2022-09-25 14:25:26 +02:00
|
|
|
canClose?: boolean;
|
|
|
|
|
onClose?: (keyPressed?: 'Escape' | 'Backspace') => void;
|
2022-09-14 13:50:32 +02:00
|
|
|
onSelected?: ChangeFunction;
|
|
|
|
|
onSideScroll?: ChangeFunction;
|
2024-09-09 23:59:33 +02:00
|
|
|
onCheck?: ChangeFunction;
|
2022-10-08 01:58:53 +02:00
|
|
|
cb?: ChangeFunction;
|
2022-09-14 13:50:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type registerMenu = (data: MenuProps, cb: ChangeFunction) => void;
|
|
|
|
|
export const registerMenu: registerMenu = (data, cb) => exports.ox_lib.registerMenu(data, cb);
|
|
|
|
|
|
|
|
|
|
export const showMenu = (id: string): string => exports.ox_lib.showMenu(id);
|
|
|
|
|
|
|
|
|
|
export const hideMenu = (onExit: boolean): void => exports.ox_lib.hideMenu(onExit);
|
|
|
|
|
|
|
|
|
|
export const getOpenMenu = (): string | null => exports.ox_lib.getOpenMenu();
|
|
|
|
|
|
|
|
|
|
type setMenuOptions = (id: string, options: MenuOptions | MenuOptions[], index?: number) => void;
|
|
|
|
|
export const setMenuOptions: setMenuOptions = (id, options, index) => exports.ox_lib.setMenuOptions(id, options, index);
|