Skip to content

Commit c1b0653

Browse files
author
Tiko
committed
added link properties to buttons
1 parent 11ef8f8 commit c1b0653

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

src/components/ArrowButton.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,42 @@ import React from 'react';
33
import styled from 'styled-components';
44
import { Link } from 'gatsby';
55
import theme from '../styles/theme';
6-
7-
// eslint-disable-next-line no-unused-vars
8-
interface OwnProps {
9-
href: string;
10-
useGatsbyLink?: boolean;
11-
className?: string;
12-
children: React.ReactNode;
13-
}
6+
import { ButtonProps } from './Button.types';
147

158
// TODO: find a way to use both ...props and typescript
16-
const ButtonBase: React.FC<any> = ({
9+
const ButtonBase: React.FC<ButtonProps> = ({
1710
href,
1811
useGatsbyLink = false,
1912
className = '',
13+
rel,
14+
type,
15+
target,
16+
onClick,
2017
children,
21-
...props
2218
}) => {
2319
if (useGatsbyLink) {
2420
return (
25-
<Link to={href} className={`button ${className}`} {...props}>
21+
<Link
22+
to={href}
23+
className={`button ${className}`}
24+
rel={rel}
25+
type={type}
26+
target={target}
27+
onClick={onClick}
28+
>
2629
{children}
2730
</Link>
2831
);
2932
}
3033
return (
31-
<a href={href} className={`button ${className}`} {...props}>
34+
<a
35+
href={href}
36+
className={`button ${className}`}
37+
rel={rel}
38+
type={type}
39+
target={target}
40+
onClick={onClick}
41+
>
3242
{children}
3343
</a>
3444
);

src/components/Button.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,42 @@ import React from 'react';
22
import styled from 'styled-components';
33
import { Link } from 'gatsby';
44
import theme from '../styles/theme';
5-
6-
// eslint-disable-next-line no-unused-vars
7-
interface OwnProps {
8-
href: string;
9-
useGatsbyLink?: boolean;
10-
className?: string;
11-
children: React.ReactNode;
12-
}
5+
import { ButtonProps } from './Button.types';
136

147
// TODO: find a way to use both ...props and typescript
15-
const ButtonBase: React.FC<any> = ({
8+
const ButtonBase: React.FC<ButtonProps> = ({
169
href,
1710
useGatsbyLink = false,
1811
className = '',
12+
rel,
13+
type,
14+
target,
15+
onClick,
1916
children,
20-
...props
2117
}) => {
2218
if (useGatsbyLink) {
2319
return (
24-
<Link to={href} className={`button ${className}`} {...props}>
20+
<Link
21+
to={href}
22+
className={`button ${className}`}
23+
rel={rel}
24+
type={type}
25+
target={target}
26+
onClick={onClick}
27+
>
2528
{children}
2629
</Link>
2730
);
2831
}
2932
return (
30-
<a href={href} className={`button ${className}`} {...props}>
33+
<a
34+
href={href}
35+
className={`button ${className}`}
36+
rel={rel}
37+
type={type}
38+
target={target}
39+
onClick={onClick}
40+
>
3141
{children}
3242
</a>
3343
);

src/components/Button.types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
export interface ButtonProps {
4+
href?: string;
5+
useGatsbyLink?: boolean;
6+
className?: string;
7+
rel?: string;
8+
type?: string;
9+
target?: string;
10+
onClick?: () => void;
11+
children: React.ReactNode;
12+
}

0 commit comments

Comments
 (0)