2018-12-22 17:20:04 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import TodoTextInput from './TodoTextInput';
|
|
|
|
|
2020-09-10 18:45:02 +03:00
|
|
|
interface Props {
|
|
|
|
addTodo: (text: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Header extends Component<Props> {
|
2018-12-22 17:20:04 +03:00
|
|
|
static propTypes = {
|
2020-08-08 23:26:39 +03:00
|
|
|
addTodo: PropTypes.func.isRequired,
|
2018-12-22 17:20:04 +03:00
|
|
|
};
|
|
|
|
|
2020-09-10 18:45:02 +03:00
|
|
|
handleSave = (text: string) => {
|
2018-12-22 17:20:04 +03:00
|
|
|
if (text.length !== 0) {
|
|
|
|
this.props.addTodo(text);
|
|
|
|
}
|
2019-01-10 21:51:14 +03:00
|
|
|
};
|
2018-12-22 17:20:04 +03:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-01-10 20:23:33 +03:00
|
|
|
<header className="header">
|
2018-12-22 17:20:04 +03:00
|
|
|
<h1>todos</h1>
|
|
|
|
<TodoTextInput
|
|
|
|
newTodo
|
|
|
|
onSave={this.handleSave}
|
2019-01-10 20:23:33 +03:00
|
|
|
placeholder="What needs to be done?"
|
2018-12-22 17:20:04 +03:00
|
|
|
/>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|