index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, { Component } from 'react';
  2. import Recipe, { SubRecipe, Ingredient } from '../../types/recipes';
  3. import Card, {
  4. CardMedia,
  5. } from "@material/react-card";
  6. import Icon from 'components/Icon';
  7. import { List as Ingredients } from 'components/Ingredient';
  8. import moment from 'moment';
  9. import sample_img from "components/Card/sample.png";
  10. const API: string = process.env.REACT_APP_API || '';
  11. import './styles.scss';
  12. type RecipeCardProps = {
  13. recipe: Recipe,
  14. }
  15. function CBKRecipeCard(props: RecipeCardProps) {
  16. const { recipe } = props;
  17. const prepTime = moment.duration(recipe.details.preparationTime).humanize();
  18. const cookTime = moment.duration(recipe.details.cookingTime).humanize();
  19. const servings = recipe.details.servings;
  20. return (
  21. <Card outlined className='cbk-recipe-card'>
  22. <div className='cbk-recipe-card__primary'>
  23. <CardMedia square imageUrl={recipe.image ? `${API}/${recipe.image}` : sample_img} className='cbk-recipe-card__primary__image'/>
  24. <div className='cbk-recipe-card__primary__title'>
  25. <h4>{recipe.name}</h4>
  26. <p>{recipe.summary}</p>
  27. <p>
  28. <b>Author:</b> {recipe.author.name} {recipe.details.url && (<a href={recipe.details.url}>(website)</a>)}
  29. </p>
  30. <ul>
  31. <li>
  32. <Icon width={32} height={32} icon='preparation' />
  33. <label>{prepTime}</label>
  34. </li>
  35. <li>
  36. <Icon width={32} height={32} icon='cooking' />
  37. <label>{cookTime}</label>
  38. </li>
  39. <li>
  40. <Icon width={32} height={32} icon='servings' />
  41. <label>{servings}</label>
  42. </li>
  43. </ul>
  44. </div>
  45. </div>
  46. <div className='cbk-recipe-card__content'>
  47. <div className='cbk-recipe-card__content__ingredients'>
  48. <Ingredients ingredients={recipe.ingredients} />
  49. </div>
  50. <div className='cbk-recipe-card__content__instructions'>
  51. <ol>
  52. {
  53. recipe.instructions.map((instruction, i) => (
  54. <li key={i}>{instruction}</li>
  55. ))
  56. }
  57. </ol>
  58. </div>
  59. </div>
  60. </Card>
  61. )
  62. }
  63. export default CBKRecipeCard;