'use client'; import classnames from 'classnames'; import React, { forwardRef } from 'react'; export type MdLinkProps = { children?: string | React.ReactNode; href?: string; icon?: React.ReactNode; asChild?: boolean; asChildContent?: React.ReactNode; onClick?(_e: React.MouseEvent): void; } & React.AnchorHTMLAttributes & React.ButtonHTMLAttributes; export const MdLink = forwardRef( ({ href, children, icon, asChild, asChildContent, onClick, ...otherProps }, ref) => { const classNames = classnames('md-link', otherProps.className); const content = ( <> {children} {icon &&
{icon}
} ); if (asChild && asChildContent) { const childElement = asChildContent as React.ReactElement; const childClassName = childElement.props?.className || ''; return React.cloneElement( childElement, { ...otherProps, className: classnames(classNames, childClassName), }, content, ); } return href ? ( }> {content} ) : ( ); }, ); MdLink.displayName = 'MdLink'; export default MdLink;