ALink.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { FC } from "react";
  2. import { Box, BoxProps } from "rebass/styled-components";
  3. import styled, { css } from "styled-components";
  4. import { ifProp } from "styled-tools";
  5. import Link from "next/link";
  6. interface Props extends BoxProps {
  7. href?: string;
  8. title?: string;
  9. target?: string;
  10. rel?: string;
  11. forButton?: boolean;
  12. isNextLink?: boolean;
  13. }
  14. const StyledBox = styled(Box)<Props>`
  15. cursor: pointer;
  16. color: #2196f3;
  17. border-bottom: 1px dotted transparent;
  18. text-decoration: none;
  19. transition: all 0.2s ease-out;
  20. ${ifProp(
  21. { forButton: false },
  22. css`
  23. :hover {
  24. border-bottom-color: #2196f3;
  25. }
  26. `
  27. )}
  28. `;
  29. export const ALink: FC<Props> = (props) => {
  30. if (props.isNextLink) {
  31. const { href, target, title, rel, ...rest } = props;
  32. return (
  33. <Link href={href} target={target} title={title} rel={rel} passHref>
  34. <StyledBox as="a" {...rest} />
  35. </Link>
  36. );
  37. }
  38. return <StyledBox as="a" {...props} />;
  39. };
  40. ALink.displayName = "ALink";
  41. ALink.defaultProps = {
  42. pb: "1px",
  43. forButton: false
  44. };
  45. export default ALink;