spee.ch/react/containers/PublishTitleInput.jsx

44 lines
1.1 KiB
React
Raw Normal View History

2018-01-04 23:14:03 +01:00
import React from 'react';
import {updateMetadata} from '../actions/index';
import {connect} from 'react-redux';
2018-01-13 00:02:42 +01:00
import PropTypes from 'prop-types';
2018-01-04 23:14:03 +01:00
class TitleInput extends React.Component {
constructor (props) {
super(props);
this.handleInput = this.handleInput.bind(this);
}
handleInput (e) {
e.preventDefault();
const name = e.target.name;
const value = e.target.value;
this.props.onMetadataChange(name, value);
2018-01-04 23:14:03 +01:00
}
render () {
return (
<input type="text" id="publish-title" className="input-text text--large input-text--full-width" name="title" placeholder="Give your post a title..." onChange={this.handleInput} value={this.props.title}/>
);
}
}
const mapStateToProps = state => {
return {
title: state.metadata.title,
};
};
const mapDispatchToProps = dispatch => {
return {
onMetadataChange: (name, value) => {
dispatch(updateMetadata(name, value));
},
};
}
2018-01-13 00:02:42 +01:00
TitleInput.propTypes = {
title : PropTypes.string.isRequired,
onMetadataChange: PropTypes.func.isRequired,
};
export default connect(mapStateToProps, mapDispatchToProps)(TitleInput);