import React from 'react' import useTheme from '../use-theme' import useWarning from '../utils/use-warning' import LinkIcon from './icon' import { addColorAlpha } from '../utils/color' import useScaleable, { withScaleable } from '../use-scaleable' export interface Props { href?: string color?: boolean pure?: boolean icon?: boolean underline?: boolean block?: boolean className?: string } const defaultProps = { href: '', color: false, pure: false, icon: false, underline: false, block: false, className: '', } type NativeAttrs = Omit, keyof Props> export type LinkProps = Props & NativeAttrs const LinkComponent = React.forwardRef< HTMLAnchorElement, React.PropsWithChildren >( ( { href, color, underline, pure, children, className, block, icon, ...props }: React.PropsWithChildren & typeof defaultProps, ref: React.Ref, ) => { const theme = useTheme() const { SCALES } = useScaleable() const linkColor = color || block ? theme.palette.link : 'inherit' const hoverColor = color || block ? theme.palette.successLight : 'inherit' const decoration = underline ? 'underline' : 'none' if (pure) { useWarning('Props "pure" is deprecated, now the default Link is pure.') } return ( {children} {icon && } ) }, ) LinkComponent.defaultProps = defaultProps LinkComponent.displayName = 'GeistLink' const Link = withScaleable(LinkComponent) export default Link