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

53 lines
1.6 KiB
React
Raw Normal View History

2017-09-08 11:52:36 -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-08 11:52:36 -04:00
import {changeStrokeWidth} from '../reducers/stroke-width';
import StrokeWidthIndicatorComponent from '../components/stroke-width-indicator.jsx';
import {applyStrokeWidthToSelection} from '../helper/style-path';
2017-11-07 14:02:39 -05:00
import Modes from '../lib/modes';
2017-10-05 18:12:22 -04:00
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}
2017-10-05 18:12:22 -04:00
strokeWidth={this.props.strokeWidth}
onChangeStrokeWidth={this.handleChangeStrokeWidth}
/>
);
}
}
2017-09-08 11:52:36 -04:00
const mapStateToProps = state => ({
disabled: state.scratchPaint.mode === Modes.BRUSH,
2017-09-08 11:52:36 -04:00
strokeWidth: state.scratchPaint.color.strokeWidth
});
const mapDispatchToProps = dispatch => ({
2017-09-11 13:54:48 -04:00
onChangeStrokeWidth: strokeWidth => {
2017-09-08 11:52:36 -04:00
dispatch(changeStrokeWidth(strokeWidth));
}
});
2017-10-05 18:12:22 -04:00
StrokeWidthIndicator.propTypes = {
disabled: PropTypes.bool.isRequired,
2017-10-05 18:12:22 -04:00
onChangeStrokeWidth: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired,
strokeWidth: PropTypes.number
};
2017-09-08 11:52:36 -04:00
export default connect(
mapStateToProps,
mapDispatchToProps
2017-10-05 18:12:22 -04:00
)(StrokeWidthIndicator);