scratch-paint/src/containers/stroke-width-indicator.jsx
2017-11-07 14:02:39 -05:00

52 lines
1.6 KiB
JavaScript

import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
import {changeStrokeWidth} from '../reducers/stroke-width';
import StrokeWidthIndicatorComponent from '../components/stroke-width-indicator.jsx';
import {applyStrokeWidthToSelection} from '../helper/style-path';
import Modes from '../lib/modes';
class StrokeWidthIndicator extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleChangeStrokeWidth'
]);
}
handleChangeStrokeWidth (newWidth) {
applyStrokeWidthToSelection(newWidth, this.props.onUpdateSvg);
this.props.onChangeStrokeWidth(newWidth);
}
render () {
return (
<StrokeWidthIndicatorComponent
disabled={this.props.disabled}
strokeWidth={this.props.strokeWidth}
onChangeStrokeWidth={this.handleChangeStrokeWidth}
/>
);
}
}
const mapStateToProps = state => ({
disabled: state.scratchPaint.mode === Modes.BRUSH,
strokeWidth: state.scratchPaint.color.strokeWidth
});
const mapDispatchToProps = dispatch => ({
onChangeStrokeWidth: strokeWidth => {
dispatch(changeStrokeWidth(strokeWidth));
}
});
StrokeWidthIndicator.propTypes = {
disabled: PropTypes.bool.isRequired,
onChangeStrokeWidth: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired,
strokeWidth: PropTypes.number
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(StrokeWidthIndicator);