Files
payloadcms/examples/form-builder/next-app/components/Button/index.tsx
Paul d053778bf2 chore: update form builder example (#6376)
Updates the form builder example
2024-05-15 21:22:54 -03:00

64 lines
1.3 KiB
TypeScript

import Link from 'next/link'
import React from 'react'
import classes from './index.module.scss'
export type Props = {
appearance?: 'default' | 'primary' | 'secondary'
className?: string
el?: 'a' | 'button' | 'link'
form?: string
href?: string
label: string
newTab?: boolean
onClick?: () => void
}
const elements = {
a: 'a',
button: 'button',
link: Link,
}
export const Button: React.FC<Props> = ({
appearance,
className: classNameFromProps,
el = 'button',
form,
href,
label,
newTab,
}) => {
const newTabProps = newTab ? { rel: 'noopener noreferrer', target: '_blank' } : {}
const Element = elements[el]
const className = [classNameFromProps, classes[`appearance--${appearance}`], classes.button]
.filter(Boolean)
.join(' ')
const elementProps = {
...newTabProps,
className,
form,
href,
}
const content = (
<div className={classes.content}>
<span className={classes.label}>{label}</span>
</div>
)
return (
<Element {...elementProps}>
<React.Fragment>
{el === 'link' && (
<Link {...newTabProps} className={elementProps.className} href={href}>
{content}
</Link>
)}
{el !== 'link' && <React.Fragment>{content}</React.Fragment>}
</React.Fragment>
</Element>
)
}