Update link component

This commit is contained in:
Hazem Krimi
2021-06-16 00:41:57 +01:00
parent 3d5c8d2e61
commit 73b090ab62
+13 -2
View File
@@ -2,7 +2,8 @@ import { Link as RouterLink } from 'react-router-dom';
import { Wrapper } from './styles'; import { Wrapper } from './styles';
type LinkProps = { type LinkProps = {
href: string; href?: string;
url?: boolean;
children?: React.ReactNode | JSX.Element | string; children?: React.ReactNode | JSX.Element | string;
color?: color?:
| 'client' | 'client'
@@ -19,21 +20,31 @@ type LinkProps = {
className?: string; className?: string;
iconLeft?: React.SVGProps<SVGSVGElement>; iconLeft?: React.SVGProps<SVGSVGElement>;
onClick?: () => void; onClick?: () => void;
target?: '_self' | '_blank';
}; };
const Link = ({ const Link = ({
href, href,
url = false,
children, children,
iconLeft, iconLeft,
selected = false, selected = false,
target = '_self',
...props ...props
}: LinkProps) => { }: LinkProps) => {
return ( return (
<Wrapper {...props} selected={selected}> <Wrapper {...props} selected={selected}>
<RouterLink to={href}> {href && !url ? (
<RouterLink to={href} target={target}>
{iconLeft && <span className='icon left'>{iconLeft}</span>} {iconLeft && <span className='icon left'>{iconLeft}</span>}
{children} {children}
</RouterLink> </RouterLink>
) : (
<a href={href} target={target}>
{iconLeft && <span className='icon left'>{iconLeft}</span>}
{children}
</a>
)}
</Wrapper> </Wrapper>
); );
}; };