Created
September 3, 2018 09:07
-
-
Save drex44/1d1e3e83ba6a21301fa4f0624d86921c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import { | |
withStyles, | |
List, | |
ListItem, | |
ListItemSecondaryAction, | |
ListItemText, | |
IconButton, | |
Grid, | |
TextField, | |
Button, | |
FormControl | |
} from "@material-ui/core"; | |
import DeleteIcon from "@material-ui/icons/Delete"; | |
const styles = theme => ({ | |
root: { | |
flexGrow: 1, | |
maxWidth: 752 | |
}, | |
demo: { | |
backgroundColor: theme.palette.background.paper | |
}, | |
title: { | |
margin: `${theme.spacing.unit * 4}px 0 ${theme.spacing.unit * 2}px` | |
} | |
}); | |
class ToDO extends Component { | |
state = {}; | |
generate = () => { | |
return this.props.items.map(item => ( | |
<ListItem key={item.id}> | |
<ListItemText primary={item.description} /> | |
<ListItemSecondaryAction> | |
<IconButton | |
aria-label="Delete" | |
onClick={this.handleDelete} | |
value={item.id} | |
> | |
<DeleteIcon /> | |
</IconButton> | |
</ListItemSecondaryAction> | |
</ListItem> | |
)); | |
}; | |
handleSubmit = event => { | |
// console.log(this.state.item); | |
this.setState({ item: "" }); | |
if (this.state.item !== "") { | |
// add the task to store | |
} | |
event.preventDefault(); | |
}; | |
handleDelete = event => { | |
//delete the task from the store | |
}; | |
handleChange = event => { | |
this.setState({ | |
[event.target.name]: event.target.value | |
}); | |
}; | |
render() { | |
const { classes } = this.props; | |
return ( | |
<div> | |
<div> | |
<form noValidate autoComplete="off" onSubmit={this.handleSubmit}> | |
<FormControl> | |
<TextField | |
label="New Task" | |
id="margin-dense" | |
value={this.state.item} | |
className={classes.textField} | |
margin="dense" | |
name="item" | |
onChange={this.handleChange} | |
/> | |
</FormControl> | |
<FormControl> | |
<Button>Add</Button> | |
</FormControl> | |
</form> | |
</div> | |
<div> | |
<Grid item container justify="space-evenly" alignItems="center"> | |
<div className={classes.demo}> | |
<List dense={false}>{this.generate()}</List> | |
</div> | |
</Grid> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default withStyles(styles)(ToDO); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment