2021-08-16 00:43:04 -04:00
|
|
|
import React from 'react';
|
2021-08-23 13:34:28 -04:00
|
|
|
import { ContextMenuView, ContextMenuButton } from 'react-native-ios-context-menu';
|
2021-02-10 00:18:40 -05:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2021-08-23 15:39:52 -04:00
|
|
|
const ToolTipMenu = props => {
|
|
|
|
const menuItems = props.actions.map(action => {
|
|
|
|
const item = {
|
|
|
|
actionKey: action.id,
|
|
|
|
actionTitle: action.text,
|
|
|
|
actionOnPress: action.onPress,
|
|
|
|
icon: action.icon,
|
|
|
|
menuOptions: action.menuOptions,
|
|
|
|
menuTitle: action.menuTitle,
|
|
|
|
};
|
2021-08-23 15:54:22 -04:00
|
|
|
item.menuState = action.menuStateOn ? 'on' : 'off';
|
|
|
|
|
2021-08-23 15:39:52 -04:00
|
|
|
if (action.disabled) {
|
|
|
|
item.menuAttributes = ['disabled'];
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2021-08-16 00:43:04 -04:00
|
|
|
const menuTitle = props.title ?? '';
|
|
|
|
const submenu = props.submenu;
|
2021-08-23 15:39:52 -04:00
|
|
|
const isButton = !!props.isButton;
|
2021-08-23 13:34:28 -04:00
|
|
|
const isMenuPrimaryAction = props.isMenuPrimaryAction ? props.isMenuPrimaryAction : false;
|
2021-08-23 15:39:52 -04:00
|
|
|
return isButton ? (
|
|
|
|
<ContextMenuButton
|
|
|
|
onPressMenuItem={({ nativeEvent }) => {
|
|
|
|
props.onPress(nativeEvent.actionKey);
|
|
|
|
}}
|
|
|
|
isMenuPrimaryAction={isMenuPrimaryAction}
|
|
|
|
menuConfig={{
|
|
|
|
menuTitle,
|
|
|
|
menuItems: menuItems.concat(submenu),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
</ContextMenuButton>
|
|
|
|
) : (
|
2021-08-16 00:43:04 -04:00
|
|
|
<ContextMenuView
|
|
|
|
onPressMenuItem={({ nativeEvent }) => {
|
|
|
|
props.onPress(nativeEvent.actionKey);
|
|
|
|
}}
|
|
|
|
menuConfig={{
|
|
|
|
menuTitle,
|
|
|
|
menuItems: menuItems.concat(submenu),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
</ContextMenuView>
|
2021-02-12 23:48:19 -05:00
|
|
|
);
|
2021-02-10 00:18:40 -05:00
|
|
|
};
|
|
|
|
|
2021-08-16 00:43:04 -04:00
|
|
|
export default ToolTipMenu;
|
2021-02-10 00:18:40 -05:00
|
|
|
ToolTipMenu.propTypes = {
|
|
|
|
actions: PropTypes.arrayOf(PropTypes.shape).isRequired,
|
2021-08-16 00:43:04 -04:00
|
|
|
title: PropTypes.string,
|
|
|
|
submenu: PropTypes.object,
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
onPress: PropTypes.func.isRequired,
|
2021-08-23 15:39:52 -04:00
|
|
|
isMenuPrimaryAction: PropTypes.bool,
|
|
|
|
isButton: PropTypes.bool,
|
2021-02-10 00:18:40 -05:00
|
|
|
};
|