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

59 lines
1.6 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';
2017-10-11 09:05:34 -04:00
import {openFillColor, closeFillColor} from '../reducers/modals';
2017-09-07 17:12:50 -04:00
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
2017-10-11 09:05:34 -04:00
{...this.props}
2017-10-05 18:12:22 -04:00
onChangeFillColor={this.handleChangeFillColor}
/>
);
}
}
2017-09-07 17:12:50 -04:00
const mapStateToProps = state => ({
2017-10-11 09:05:34 -04:00
fillColor: state.scratchPaint.color.fillColor,
fillColorModalVisible: state.scratchPaint.modals.fillColor
2017-09-07 17:12:50 -04:00
});
2017-10-11 09:05:34 -04:00
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-11 09:05:34 -04:00
},
onOpenFillColor: () => {
dispatch(openFillColor());
},
onCloseFillColor: () => {
dispatch(closeFillColor());
2017-09-07 17:12:50 -04:00
}
});
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);