Button component implemented

This commit is contained in:
NikolaBorislavovHristov 2019-01-22 12:05:56 +02:00
parent 127949d126
commit 196267f7f8
3 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,47 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { Focusable } from 'stremio-common';
class Button extends PureComponent {
onClick = (event) => {
if (this.props.stopPropagation) {
event.stopPropagation();
}
if (typeof this.props.onClick === 'function') {
this.props.onClick(event);
}
}
onKeyUp = (event) => {
if (event.which === 13) { // Enter key code
this.onClick(event);
}
}
render() {
const { stopPropagation, forwardedRef, ...props } = this.props;
return (
<Focusable ref={forwardedRef}>
<div
{...props}
onClick={this.onClick}
onKeyUp={this.onKeyUp}
/>
</Focusable>
);
}
}
Button.propTypes = {
stopPropagation: PropTypes.bool.isRequired
};
Button.defaultProps = {
stopPropagation: true
};
const ButtonWithForwardedRef = React.forwardRef((props, ref) => (
<Button {...props} forwardedRef={ref} />
));
export default ButtonWithForwardedRef;

View file

@ -0,0 +1,3 @@
import Button from './Button';
export default Button;

View file

@ -10,6 +10,7 @@ import ShareAddon from './ShareAddon';
import UserPanel from './UserPanel';
import Slider from './Slider';
import { Focusable, FocusableProvider } from './Focusable';
import Button from './Button';
export {
Checkbox,
@ -24,5 +25,6 @@ export {
UserPanel,
Slider,
Focusable,
FocusableProvider
FocusableProvider,
Button
};