Guest User

Untitled

a guest
May 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. export const ItemCard = ({toggleEditing, item, image, onChange, index}) => (
  2. <div className="col-md-6 col-lg-3">
  3. <div className="card mb-3">
  4. <img className="card-img-top" src={image}/>
  5. <div className="card-body">
  6. {item.isEditing
  7. ?
  8. <div className="mb-4">
  9. <input
  10. type="text"
  11. name="name"
  12. className="form-control mb-2 mr-sm-2"
  13. placeholder="Item"
  14. value={item.name}
  15. onChange={event => onChange(event, index)}
  16. required
  17. />
  18. <input
  19. type="number"
  20. name="price"
  21. className="form-control"
  22. placeholder="Price"
  23. value={item.price}
  24. onChange={event => onChange(event, index)}
  25. required
  26. />
  27. </div>
  28. :
  29. <div>
  30. <h4
  31. className="card-title text-center">
  32. {item.name}
  33. </h4>
  34. <div
  35. className="row justify-content-center mb-4">
  36. <p className="card-text">
  37. <span className="badge badge-secondary py-2 mr-5">Price</span>
  38. <span>${item.price}</span>
  39. </p>
  40. </div>
  41. </div>
  42. }
  43.  
  44. <div className="row justify-content-center">
  45. <div>
  46. <button
  47. type="button"
  48. className="btn btn-primary mr-2"
  49. onClick={toggleEditing}>
  50. {item.isEditing ? "Save" : "Edit"}
  51. </button>
  52. <button
  53. type="button"
  54. className="btn btn-primary">
  55. Delete
  56. </button>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. );
  63.  
  64.  
  65. ItemCard.propTypes = {
  66. image: PropTypes.string.isRequired,
  67. item: PropTypes.shape({
  68. name: PropTypes.string.isRequired,
  69. price: PropTypes.string.isRequired
  70. }),
  71. toggleEditing: PropTypes.func.isRequired,
  72. onChange: PropTypes.func.isRequired,
  73. };
Add Comment
Please, Sign In to add comment