14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useState , useEffect , useContext } from 'react' ;
17
+ import './ItemDetails.css' ;
18
+ import { Button , Grid , InputLabel , MenuItem , Select , Snackbar , Typography } from '@material-ui/core' ;
18
19
import { ItemDetails as Item , StoreData } from '../data/store-data' ;
19
- import { useParams , useHistory } from 'react-router-dom ' ;
20
- import { Button , Typography , InputLabel , Select , MenuItem , Grid , Snackbar } from '@material-ui/core ' ;
20
+ import React , { useContext , useEffect , useState } from 'react' ;
21
+ import { useHistory , useParams } from 'react-router-dom ' ;
21
22
import { CartContext } from './CartContext' ;
22
23
import qs from 'querystring' ;
23
- import './ItemDetails.css' ;
24
24
25
25
function unescapeHtml ( text : string ) {
26
26
const elem = document . createElement ( 'textarea' ) ;
@@ -58,20 +58,28 @@ export default function ItemDetails() {
58
58
59
59
return (
60
60
< div className = "ItemDetails" >
61
- {
62
- item &&
61
+ { item && (
63
62
< >
64
63
< Grid container className = "container" >
65
64
< Grid item xs = { 12 } sm = { 5 } >
66
65
< img className = "item-details-image" src = { item . largeImage } alt = { item . title } />
67
66
</ Grid >
68
67
< Grid item xs = { 12 } sm = { 6 } className = "content" >
69
68
< Typography variant = "h5" > { item . title } </ Typography >
70
- < Typography variant = "body1" color = "textSecondary" > ${ item . price . toFixed ( 2 ) } </ Typography >
69
+ < Typography variant = "body1" color = "textSecondary" >
70
+ ${ item . price . toFixed ( 2 ) }
71
+ </ Typography >
71
72
< div className = "pickers" >
72
73
< div className = "field-set" >
73
- < InputLabel className = "label" id = "sizeLabel" > Size</ InputLabel >
74
- < Select className = "input" labelId = "sizeLabel" value = { size } onChange = { event => setSize ( event . target . value as string ) } >
74
+ < InputLabel className = "label" id = "sizeLabel" >
75
+ Size
76
+ </ InputLabel >
77
+ < Select
78
+ className = "input"
79
+ labelId = "sizeLabel"
80
+ value = { size }
81
+ onChange = { event => setSize ( event . target . value as string ) }
82
+ >
75
83
< MenuItem value = "XS" > XS</ MenuItem >
76
84
< MenuItem value = "S" > S</ MenuItem >
77
85
< MenuItem value = "M" > M</ MenuItem >
@@ -80,8 +88,15 @@ export default function ItemDetails() {
80
88
</ Select >
81
89
</ div >
82
90
< div className = "field-set" >
83
- < InputLabel className = "label" id = "quantityLabel" > Quantity</ InputLabel >
84
- < Select className = "input" labelId = "quantityLabel" value = { quantity } onChange = { event => setQuantity ( Number ( event . target . value ) ) } >
91
+ < InputLabel className = "label" id = "quantityLabel" >
92
+ Quantity
93
+ </ InputLabel >
94
+ < Select
95
+ className = "input"
96
+ labelId = "quantityLabel"
97
+ value = { quantity }
98
+ onChange = { event => setQuantity ( Number ( event . target . value ) ) }
99
+ >
85
100
< MenuItem value = "1" > 1</ MenuItem >
86
101
< MenuItem value = "2" > 2</ MenuItem >
87
102
< MenuItem value = "3" > 3</ MenuItem >
@@ -97,7 +112,9 @@ export default function ItemDetails() {
97
112
</ Typography >
98
113
</ div >
99
114
< div className = "buttons" >
100
- < Button variant = "outlined" onClick = { addToCart } > Add to Cart</ Button >
115
+ < Button variant = "outlined" onClick = { addToCart } >
116
+ Add to Cart
117
+ </ Button >
101
118
</ div >
102
119
</ Grid >
103
120
</ Grid >
@@ -107,7 +124,7 @@ export default function ItemDetails() {
107
124
} }
108
125
open = { snackOpen }
109
126
autoHideDuration = { 5000 }
110
- anchorOrigin = { { vertical : 'bottom' , horizontal : 'center' } }
127
+ anchorOrigin = { { vertical : 'bottom' , horizontal : 'center' } }
111
128
onClose = { handleSnackClose }
112
129
message = { `${ item . title } added to cart.` }
113
130
action = {
@@ -119,7 +136,7 @@ export default function ItemDetails() {
119
136
}
120
137
/>
121
138
</ >
122
- }
139
+ ) }
123
140
</ div >
124
141
) ;
125
142
}
0 commit comments