-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathButton.js
More file actions
64 lines (58 loc) · 1.29 KB
/
Button.js
File metadata and controls
64 lines (58 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
import * as css from './Button.module.css';
export const Button = ({
className,
to,
href,
size,
variant,
target,
onClick,
children,
tabIndex
}) => {
const classNames = classnames(css.root, className, {
[css[size]]: size,
[css[variant]]: variant
});
return (
<>
{to ? (
<Link className={classNames} to={to} tabIndex={tabIndex ? tabIndex : 0}>
{children}
</Link>
) : href ? (
<a
className={classNames}
href={href}
target={target}
rel={target === '_blank' ? 'noreferrer' : null}
tabIndex={tabIndex ? tabIndex : 0}>
{children}
</a>
) : (
<button
className={classNames}
onClick={onClick}
tabIndex={tabIndex ? tabIndex : 0}>
{children}
</button>
)}
</>
);
};
export default Button;
Button.defaultProps = {
onClick: () => {}
};
Button.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
to: PropTypes.string,
onClick: PropTypes.func,
color: PropTypes.oneOf(['gray']),
size: PropTypes.oneOf(['large', 'small'])
};