Update button behavior to work as link

This commit is contained in:
Hazem Krimi
2021-12-12 14:56:22 +01:00
parent b2453ae6dd
commit 08dc652d25
14 changed files with 1261 additions and 1100 deletions
+13 -1
View File
@@ -1,10 +1,14 @@
import { FC } from 'react';
import styled from 'styled-components';
import Image from 'next/image';
import Link from 'next/link';
interface Props {
icon: string;
width?: number;
height?: number;
href?: string;
target?: HTMLAnchorElement['target'];
onClick?: () => void;
}
@@ -18,15 +22,23 @@ const Btn = styled.button`
const IconButton: FC<Props & { className?: string }> = ({
icon,
href,
target,
onClick,
className,
width = 24,
height = 24
}) => {
return (
return !href ? (
<Btn onClick={onClick} className={className}>
<Image src={icon} width={width} height={height} />
</Btn>
) : (
<Link href={href} passHref>
<Btn as='a' target={target} onClick={onClick} className={className}>
<Image src={icon} width={width} height={height} />
</Btn>
</Link>
);
};