Using the Button component

Install Material-UI by typing the following command into the terminal you are using and starting your app after the installation is finished:

npm install @material-ui/core --save

Let's first change all the buttons to use the Material-UI Button component. Import the Button to the AddCar.js file:

// AddCar.js
import Button from '@material-ui/core/Button';

Change the buttons to use the Button component. In the list page, we are using the primary button and in the modal form, the outline buttons:

  render() {
return (
<div>
<SkyLight hideOnOverlayClicked ref="addDialog">
<h3>New car</h3>
<form>
<input type="text" placeholder="Brand" name="brand"
onChange={this.handleChange}/><br/>
<input type="text" placeholder="Model" name="model"
onChange={this.handleChange}/><br/>
<input type="text" placeholder="Color" name="color"
onChange={this.handleChange}/><br/>
<input type="text" placeholder="Year" name="year"
onChange={this.handleChange}/><br/>
<input type="text" placeholder="Price" name="price"
onChange={this.handleChange}/><br/><br/>
<Button variant="outlined" color="primary"
onClick={this.handleSubmit}>Save</Button>
<Button variant="outlined" color="secondary"
onClick={this.cancelSubmit}>Cancel</Button>
</form>
</SkyLight>
<div>
<Button variant="raised" color="primary"
style={{'margin': '10px'}}
onClick={() => this.refs.addDialog.show()}>
New Car</Button>
</div>
</div>
);

Now, the list page button should look like the following:

And the modal form buttons should look like the following:

We use the flat variant buttons in the car table and define the button size as small. See the following source code for the table columns:

// Carlist.js render() method
const columns = [{
Header: 'Brand',
accessor: 'brand',
Cell: this.renderEditable
}, {
Header: 'Model',
accessor: 'model',
Cell: this.renderEditable
}, {
Header: 'Color',
accessor: 'color',
Cell: this.renderEditable
}, {
Header: 'Year',
accessor: 'year',
Cell: this.renderEditable
}, {
Header: 'Price €',
accessor: 'price',
Cell: this.renderEditable
}, {
id: 'savebutton',
sortable: false,
filterable: false,
width: 100,
accessor: '_links.self.href',
Cell: ({value, row}) => (<Button size="small" variant="flat" color="primary"
onClick={()=>{this.updateCar(row, value)}}>Save</Button>)
}, {
id: 'delbutton',
sortable: false,
filterable: false,
width: 100,
accessor: '_links.self.href',
Cell: ({value}) => (<Button size="small" variant="flat" color="secondary"
onClick={()=>{this.confirmDelete(value)}}>Delete</Button>)
}]

Now, the table should look like the following:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.138.202