Source: frontend/iconViews/DrinkIcon.js

  1. //Brennan Wilkes
  2. //imports
  3. import React from "react";
  4. import "../bootstrap-import.js";
  5. import axios from "axios";
  6. import "./iconView.css";
  7. //capitalization one liner using regex
  8. const capitalize = s => String(s).toLowerCase().replace(/(?:^|\s|["'([{])+\S/g, l => l.toUpperCase());
  9. /**
  10. An icon preview view for a drink recipe
  11. @class
  12. @memberof frontend
  13. @extends React.Component
  14. */
  15. class DrinkIcon extends React.Component{
  16. /**
  17. Binds methods
  18. @param {any[]} Must contain a click callback and full drink details. Details should be gathered at parent level
  19. */
  20. constructor(props){
  21. super(props);
  22. this.state = this.props.drinkInfo;
  23. }
  24. /**
  25. Renders a icon view of the drink, using the drink image and name
  26. */
  27. render(){
  28. return <>
  29. <div className="iconWrapper" onClick={event=>{
  30. this.props.clickCallback(this.state.id);
  31. }}>
  32. <img className="iconItem" src={this.state.imgURL} />
  33. <div><h3 className="h6 bg-secondary text-light" >{capitalize(this.state.name)}</h3></div>
  34. </div>
  35. </>
  36. }
  37. }
  38. export default DrinkIcon;