scratch-paint/src/containers/fill-color-indicator.jsx

49 lines
1.3 KiB
React
Raw Normal View History

2017-09-07 17:12:50 -04:00
import {connect} from 'react-redux';
2017-10-05 18:12:22 -04:00
import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
2017-09-07 17:12:50 -04:00
import {changeFillColor} from '../reducers/fill-color';
import FillColorIndicatorComponent from '../components/fill-color-indicator.jsx';
import {applyFillColorToSelection} from '../helper/style-path';
2017-10-05 18:12:22 -04:00
class FillColorIndicator extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleChangeFillColor'
]);
}
handleChangeFillColor (newColor) {
applyFillColorToSelection(newColor, this.props.onUpdateSvg);
this.props.onChangeFillColor(newColor);
}
render () {
return (
<FillColorIndicatorComponent
fillColor={this.props.fillColor}
onChangeFillColor={this.handleChangeFillColor}
/>
);
}
}
2017-09-07 17:12:50 -04:00
const mapStateToProps = state => ({
fillColor: state.scratchPaint.color.fillColor
2017-09-07 17:12:50 -04:00
});
const mapDispatchToProps = dispatch => ({
onChangeFillColor: fillColor => {
2017-09-07 17:12:50 -04:00
dispatch(changeFillColor(fillColor));
}
});
2017-10-05 18:12:22 -04:00
FillColorIndicator.propTypes = {
fillColor: PropTypes.string,
onChangeFillColor: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired
};
2017-09-07 17:12:50 -04:00
export default connect(
mapStateToProps,
mapDispatchToProps
2017-10-05 18:12:22 -04:00
)(FillColorIndicator);