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

49 lines
1.4 KiB
React
Raw Normal View History

2017-09-07 17:59:14 -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:59:14 -04:00
import {changeStrokeColor} from '../reducers/stroke-color';
import StrokeColorIndicatorComponent from '../components/stroke-color-indicator.jsx';
import {applyStrokeColorToSelection} from '../helper/style-path';
2017-10-05 18:12:22 -04:00
class StrokeColorIndicator extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleChangeStrokeColor'
]);
}
handleChangeStrokeColor (newColor) {
applyStrokeColorToSelection(newColor, this.props.onUpdateSvg);
this.props.onChangeStrokeColor(newColor);
}
render () {
return (
<StrokeColorIndicatorComponent
strokeColor={this.props.strokeColor}
onChangeStrokeColor={this.handleChangeStrokeColor}
/>
);
}
}
2017-09-07 17:59:14 -04:00
const mapStateToProps = state => ({
strokeColor: state.scratchPaint.color.strokeColor
});
const mapDispatchToProps = dispatch => ({
onChangeStrokeColor: strokeColor => {
2017-09-07 17:59:14 -04:00
dispatch(changeStrokeColor(strokeColor));
}
});
2017-10-05 18:12:22 -04:00
StrokeColorIndicator.propTypes = {
onChangeStrokeColor: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired,
strokeColor: PropTypes.string
};
2017-09-07 17:59:14 -04:00
export default connect(
mapStateToProps,
mapDispatchToProps
2017-10-05 18:12:22 -04:00
)(StrokeColorIndicator);