import { AnchorHTMLAttributes, JSX } from "react";

/** 阻止a標籤的href產生網頁跳轉 */
export default function A(props: IAnchor): JSX.Element {
	const { useref, children, onClick } = props;

	function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>): void {
		event.preventDefault(); // 阻止默认点击行为
		onClick && onClick(event);
	}

	return (
		<a {...props} ref={useref} onClick={handleClick}>
			{children}
		</a>
	);
}

interface IAnchor extends AnchorHTMLAttributes<HTMLAnchorElement> {
	useref?: React.LegacyRef<HTMLAnchorElement>;
}