2022-11-29 16:45:00 +00:00
|
|
|
import classNames from 'classnames'
|
2022-12-06 09:20:22 +00:00
|
|
|
import React, { LegacyRef, ReactNode } from 'react'
|
2022-11-29 16:45:00 +00:00
|
|
|
|
|
|
|
interface Props extends React.HTMLProps<HTMLAnchorElement> {
|
|
|
|
children?: string | ReactNode
|
|
|
|
className?: string
|
|
|
|
color?: 'primary' | 'secondary' | 'tertiary' | 'quaternary'
|
|
|
|
externalLink?: boolean
|
|
|
|
textSize?: 'small' | 'medium' | 'large'
|
|
|
|
text?: string | ReactNode
|
2022-12-06 09:20:22 +00:00
|
|
|
uppercase?: boolean
|
2022-11-29 16:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const colorClasses = {
|
|
|
|
primary:
|
|
|
|
'text-primary hover:text-primary-highlight active:text-primary-highlight-10 focus:text-primary-highlight',
|
|
|
|
secondary:
|
|
|
|
'text-secondary hover:text-secondary-highlight active:text-secondary-highlight-10 focus:text-secondary-highlight',
|
|
|
|
tertiary:
|
|
|
|
'text-secondary-dark/60 hover:text-secondary-dark active:text-secondary-dark-10 focus:text-secondary-dark',
|
2022-12-06 09:20:22 +00:00
|
|
|
quaternary: 'hover:text-white active:text-white',
|
2022-11-29 16:45:00 +00:00
|
|
|
}
|
|
|
|
const textSizeClasses = {
|
|
|
|
small: 'text-sm',
|
|
|
|
medium: 'text-base',
|
|
|
|
large: 'text-lg',
|
|
|
|
}
|
|
|
|
|
2022-12-06 09:20:22 +00:00
|
|
|
const TextLink = React.forwardRef(function TextLink(
|
|
|
|
{
|
|
|
|
children,
|
|
|
|
className = '',
|
|
|
|
color = 'primary',
|
|
|
|
disabled,
|
|
|
|
externalLink,
|
|
|
|
href,
|
|
|
|
textSize = 'small',
|
|
|
|
text,
|
|
|
|
uppercase,
|
|
|
|
onClick,
|
|
|
|
...restProps
|
|
|
|
}: Props,
|
|
|
|
ref,
|
|
|
|
) {
|
2022-11-29 16:45:00 +00:00
|
|
|
return (
|
|
|
|
<a
|
2022-12-06 09:20:22 +00:00
|
|
|
className={classNames(
|
|
|
|
uppercase ? `${textSizeClasses[textSize]}-caps` : textSizeClasses[textSize],
|
|
|
|
colorClasses[color],
|
|
|
|
disabled && 'pointer-events-none opacity-50',
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
ref={ref as LegacyRef<HTMLAnchorElement>}
|
2022-11-29 16:45:00 +00:00
|
|
|
target={externalLink ? '_blank' : '_self'}
|
|
|
|
rel='noreferrer'
|
|
|
|
onClick={
|
2022-12-06 09:20:22 +00:00
|
|
|
onClick && !href
|
2022-11-29 16:45:00 +00:00
|
|
|
? (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
if (disabled) return
|
|
|
|
onClick
|
|
|
|
}
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
href={!href ? '#' : href}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{text && !children && text}
|
|
|
|
{children && children}
|
|
|
|
</a>
|
|
|
|
)
|
2022-12-06 09:20:22 +00:00
|
|
|
})
|
2022-11-29 16:45:00 +00:00
|
|
|
|
|
|
|
export default TextLink
|