simple checkbox component implemented and exported as a common module

This commit is contained in:
NikolaBorislavovHristov 2018-06-04 16:36:11 +03:00
parent 67f3668166
commit 7077b89f6a
4 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styles from './styles';
class Checkbox extends Component {
shouldComponentUpdate(nextProps, nextState) {
return nextProps.checked !== this.props.checked;
}
onPress = () => {
if (typeof this.props.onPress === 'function') {
this.props.onPress();
}
}
render() {
return (
<div style={styles.root} onClick={this.onPress} />
);
}
}
Checkbox.propTypes = {
enabled: PropTypes.bool.isRequired,
checked: PropTypes.bool.isRequired,
onPress: PropTypes.func
};
Checkbox.defaultProps = {
enabled: true
};
export default Checkbox;

View file

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

View file

@ -0,0 +1,7 @@
export default {
root: {
width: 300,
height: 300,
backgroundColor: 'red'
},
};

5
src/common/index.js Normal file
View file

@ -0,0 +1,5 @@
import Checkbox from './checkbox';
export {
Checkbox
};