import { useForwardedRef } from '@anton.bobrov/react-hooks'; import React, { PropsWithChildren, forwardRef, memo } from 'react'; import { TButtonAnchor } from './types'; import { RenderAnchor } from './RenderAnchor'; const DefaultRenderAnchor = memo(RenderAnchor); /** * ButtonAnchor component for rendering a clickable button or a link. * * @link See examples https://antonbobrov.github.io/react-kit/?path=/docs/elements-buttonanchor--docs */ export const ButtonAnchor = forwardRef< HTMLButtonElement | HTMLAnchorElement, PropsWithChildren >( ( { tag, className, style, children, renderAnchor: Anchor = DefaultRenderAnchor, ...props }, forwardedRef, ) => { const ref = useForwardedRef(forwardedRef); if (tag === 'a') { const defaultRel = (props as any).target === '_blank' ? 'noopener noreferrer' : undefined; return ( {children} ); } return ( ); }, ); ButtonAnchor.displayName = 'ButtonAnchor';