From 7077b89f6af5e1e49082adf86f9abc11c418f044 Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Mon, 4 Jun 2018 16:36:11 +0300 Subject: [PATCH] simple checkbox component implemented and exported as a common module --- src/common/checkbox/checkbox.js | 32 ++++++++++++++++++++++++++++++++ src/common/checkbox/index.js | 3 +++ src/common/checkbox/styles.js | 7 +++++++ src/common/index.js | 5 +++++ 4 files changed, 47 insertions(+) create mode 100644 src/common/checkbox/checkbox.js create mode 100644 src/common/checkbox/index.js create mode 100644 src/common/checkbox/styles.js create mode 100644 src/common/index.js diff --git a/src/common/checkbox/checkbox.js b/src/common/checkbox/checkbox.js new file mode 100644 index 000000000..2954da79b --- /dev/null +++ b/src/common/checkbox/checkbox.js @@ -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 ( +
+ ); + } +} + +Checkbox.propTypes = { + enabled: PropTypes.bool.isRequired, + checked: PropTypes.bool.isRequired, + onPress: PropTypes.func +}; +Checkbox.defaultProps = { + enabled: true +}; + +export default Checkbox; diff --git a/src/common/checkbox/index.js b/src/common/checkbox/index.js new file mode 100644 index 000000000..cea9e24dc --- /dev/null +++ b/src/common/checkbox/index.js @@ -0,0 +1,3 @@ +import Checkbox from './checkbox'; + +export default Checkbox; diff --git a/src/common/checkbox/styles.js b/src/common/checkbox/styles.js new file mode 100644 index 000000000..953e15580 --- /dev/null +++ b/src/common/checkbox/styles.js @@ -0,0 +1,7 @@ +export default { + root: { + width: 300, + height: 300, + backgroundColor: 'red' + }, +}; diff --git a/src/common/index.js b/src/common/index.js new file mode 100644 index 000000000..d4a1c16b0 --- /dev/null +++ b/src/common/index.js @@ -0,0 +1,5 @@ +import Checkbox from './checkbox'; + +export { + Checkbox +};