import React, { createElement } from 'react'; import { classNames, type PropsOf, type As } from '../../utils'; import styles from './Anchor.module.css'; import { Anchor, type AnchorProps } from './Anchor'; export type LinkProps = PropsOf | AnchorProps; function isCustomElement( props: LinkProps, ): props is PropsOf { return 'as' in props; } export function Link(props: LinkProps) { if (isCustomElement(props)) { const { as: Component, className, ...rest } = props; return createElement(Component, { ...rest, className: classNames(styles.anchor, className), }); } return createElement(Anchor, props); }