-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Button.js
45 lines (42 loc) · 997 Bytes
/
Button.js
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
import React from 'react';
import PropTypes from 'prop-types';
import './Button.css';
/**
* The only true button.
*/
export default function Button({ color, size, onClick, disabled, children }) {
const styles = {
color,
fontSize: Button.sizes[size],
};
return (
<button className="button" style={styles} onClick={onClick} disabled={disabled}>
{children}
</button>
);
}
Button.propTypes = {
/** Button label */
children: PropTypes.node.isRequired,
/** The color for the button */
color: PropTypes.string,
/** The size of the button */
size: PropTypes.oneOf(['small', 'normal', 'large']),
/** Disable button */
disabled: PropTypes.bool,
/** Gets called when the user clicks on the button */
onClick: PropTypes.func,
};
Button.defaultProps = {
color: '#333',
size: 'normal',
onClick: (event) => {
// eslint-disable-next-line no-console
console.log('You have clicked me!', event.target);
},
};
Button.sizes = {
small: '10px',
normal: '14px',
large: '18px',
};