BlueWallet/components/HeaderMenuButton.tsx

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-09-27 08:39:31 -04:00
import React from 'react';
2024-10-23 15:54:51 -04:00
import { Pressable, Platform } from 'react-native';
2024-09-27 08:39:31 -04:00
import ToolTipMenu from './TooltipMenu';
import { useTheme } from './themes';
import { Icon } from '@rneui/themed';
import { Action } from './types';
interface HeaderMenuButtonProps {
onPressMenuItem: (id: string) => void;
2024-10-23 15:54:51 -04:00
actions?: Action[] | Action[][];
2024-09-27 08:39:31 -04:00
disabled?: boolean;
}
const HeaderMenuButton: React.FC<HeaderMenuButtonProps> = ({ onPressMenuItem, actions, disabled }) => {
const { colors } = useTheme();
const styleProps = Platform.OS === 'android' ? { iconStyle: { transform: [{ rotate: '90deg' }] } } : {};
2024-10-23 15:54:51 -04:00
if (!actions || actions.length === 0) {
return (
<Pressable
testID="HeaderMenuButton"
disabled={disabled}
android_ripple={{ color: colors.lightButton }}
2024-10-27 22:05:14 -04:00
style={({ pressed }) => [{ opacity: pressed ? 0.5 : 1 }]}
2024-10-23 15:54:51 -04:00
>
<Icon size={22} name="more-horiz" type="material" color={colors.foregroundColor} {...styleProps} />
</Pressable>
);
}
const menuActions = Array.isArray(actions[0]) ? (actions as Action[][]) : (actions as Action[]);
2024-09-27 08:39:31 -04:00
return (
<ToolTipMenu
testID="HeaderMenuButton"
disabled={disabled}
isButton
isMenuPrimaryAction
onPressMenuItem={onPressMenuItem}
2024-10-23 15:54:51 -04:00
actions={menuActions}
2024-09-27 08:39:31 -04:00
>
<Icon size={22} name="more-horiz" type="material" color={colors.foregroundColor} {...styleProps} />
</ToolTipMenu>
);
};
export default HeaderMenuButton;