import type { FC } from '../../lib/teact/teact'; import React from '../../lib/teact/teact'; import { IS_TEST } from '../../config'; import buildClassName from '../../util/buildClassName'; import useLastCallback from '../../hooks/useLastCallback'; import useLang from '../../hooks/useLang'; import useAppLayout from '../../hooks/useAppLayout'; import './MenuItem.scss'; export type MenuItemProps = { icon?: string; isCharIcon?: boolean; customIcon?: React.ReactNode; className?: string; children: React.ReactNode; onClick?: (e: React.SyntheticEvent, arg?: number) => void; clickArg?: number; onContextMenu?: (e: React.UIEvent) => void; href?: string; download?: string; disabled?: boolean; destructive?: boolean; ariaLabel?: string; withWrap?: boolean; }; const MenuItem: FC = (props) => { const { icon, isCharIcon, customIcon, className, children, onClick, href, download, disabled, destructive, ariaLabel, withWrap, onContextMenu, clickArg, } = props; const lang = useLang(); const { isTouchScreen } = useAppLayout(); const handleClick = useLastCallback((e: React.MouseEvent) => { if (disabled || !onClick) { e.stopPropagation(); e.preventDefault(); return; } onClick(e, clickArg); }); const handleKeyDown = useLastCallback((e: React.KeyboardEvent) => { if (e.keyCode !== 13 && e.keyCode !== 32) { return; } if (disabled || !onClick) { e.stopPropagation(); e.preventDefault(); return; } onClick(e, clickArg); }); const fullClassName = buildClassName( 'MenuItem', className, disabled && 'disabled', destructive && 'destructive', !isTouchScreen && 'compact', withWrap && 'wrap', ); const content = ( <> {!customIcon && icon && ( )} {customIcon} {children} ); if (href) { return ( {content} ); } return (
{content}
); }; export default MenuItem;