'use client' import React, { ElementType } from 'react' import Link from 'next/link' import classes from './index.module.scss' export type Props = { label?: string appearance?: 'default' | 'primary' | 'secondary' el?: 'button' | 'link' | 'a' onClick?: () => void href?: string newTab?: boolean className?: string type?: 'submit' | 'button' disabled?: boolean invert?: boolean } export const Button: React.FC = ({ el: elFromProps = 'link', label, newTab, href, appearance, className: classNameFromProps, onClick, type = 'button', disabled, invert, }) => { let el = elFromProps const newTabProps = newTab ? { target: '_blank', rel: 'noopener noreferrer' } : {} const className = [ classes.button, classNameFromProps, classes[`appearance--${appearance}`], invert && classes[`${appearance}--invert`], ] .filter(Boolean) .join(' ') const content = (
{label}
) if (onClick || type === 'submit') el = 'button' if (el === 'link') { return ( {content} ) } const Element: ElementType = el return ( {content} ) }