import Link from 'next/link';
import { get, isEmpty, omit, pick } from 'lodash';
export const Button: FC<ButtonProps> = props => {
const { children, ...rest } = props;
if (!isEmpty(get(rest, 'to'))) {
const linkProps = pick(rest, linkFields);
const anchorProps = omit(rest, linkFields);
return (
<Link {...linkProps} href={linkProps.to}>
<a {...anchorProps}>{children}</a>
</Link>
);
}
return <button {...(rest as BtnProps)}>{children}</button>;
};
const linkFields = [
'to',
'href',
'as',
'replace',
'scroll',
'shallow',
'passHref',
'prefetch',
'locale',
];