diff --git a/src/components/Accordion/Accordion.stories.tsx b/src/components/Accordion/Accordion.stories.tsx new file mode 100644 index 0000000..3bb5bbd --- /dev/null +++ b/src/components/Accordion/Accordion.stories.tsx @@ -0,0 +1,52 @@ +import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { Accordion } from './Accordion'; + +export default { + title: 'Accordion', + component: Accordion, + args: { + recipeDetails: [ + { + type: 'ingredients', + data: [ + { unit: 'g', name: 'angel hair pasta', amount: 8 }, + { amount: 0.5, name: 'black pepper', unit: 'tsps' }, + { amount: 0.5, unit: 'Tbsps', name: 'chili powder' }, + { unit: 'tsps', name: 'corn starch', amount: 2 }, + { name: 'spring onions', unit: '', amount: 3 }, + { amount: 2, unit: '', name: 'juice' }, + { amount: 3, name: 'fat free greek yogurt', unit: 'Tbsps' }, + { amount: 0.5, unit: 'Tbsps', name: 'paprika' }, + { unit: 'g', amount: 1, name: 'shrimp' }, + { amount: 0.5, unit: 'tsps', name: 'salt' }, + { name: 'sesame oil', amount: 2.5, unit: 'Tbsps' }, + { amount: 1.5, unit: 'tsps', name: 'sriracha' }, + { unit: '', amount: 3, name: 'sweet chili sauce' }, + ], + }, + { + type: 'equipment', + data: ['pot', 'whisk', 'bowl', 'frying pan'], + }, + { + type: 'summary', + data: 'Need a pescatarian main course? Bang Bang Shrimp Pasta could be a tremendous recipe to try. One serving contains 422 calories, 32g of protein, and 11g of fat. For $2.86 per serving, this recipe covers 20% of your daily requirements of vitamins and minerals. 10686 people have made this recipe and would make it again. From preparation to the plate, this recipe takes approximately 20 minutes. A mixture of juice, paprika, corn starch, and a handful of other ingredients are all it takes to make this recipe so yummy. To use up the black pepper you could follow this main course with the Dr. Pepper Cake with Flour Cooked Frosting as a dessert. All things considered, we decided this recipe deserves a spoonacular score of 87%. This score is tremendous. Try Bang Bang Shrimp Pasta, Bang Bang Shrimp Pasta, and Bang Bang Shrimp Pasta for similar recipes.', + }, + { + type: 'instructions', + data: [ + 'In a large stockpot over medium-high heat, bring 10-12 cups of water to boil.', + 'Add pasta and cook until al dente (softened but still slightly firm).', + 'Drain pasta and set aside. In a large Ziploc bag add corn starch, paprika, chili powder, salt and black pepper.', + 'Add shrimp to bag, seal and shake bag a few times to evenly cover shrimp with seasoning mixture. In a small bowl, whisk together Greek yogurt, sweet chili sauce, 1 Tbsp sesame oil, lime juice, sriracha sauce and red pepper flakes.', + 'Pour sauce over pasta and toss to evenly coat pasta. Set aside. In a large skillet over medium-high heat, add remaining 1 Tbsp sesame oil. Once oil has heated, saut shrimp for 3-5 minutes. Flip halfway through to evenly cook on both sides.', + 'Serve shrimp over pasta and top with green onions.', + ], + }, + ], + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ; + +export const Default = Template.bind({}); diff --git a/src/components/Accordion/Accordion.styled.tsx b/src/components/Accordion/Accordion.styled.tsx new file mode 100644 index 0000000..4231d3f --- /dev/null +++ b/src/components/Accordion/Accordion.styled.tsx @@ -0,0 +1,104 @@ +import styled from '@emotion/styled'; +import { css, Theme } from '@emotion/react'; +import { pxToRem, media } from 'utils'; + +const collapseContent = (props: { theme: Theme }) => + css` + font-size: ${pxToRem(18)}; + color: ${props.theme.color.gray200}; + padding: 0.5rem 0; + line-height: 1.3; + `; + +export const StyledCollapseHeading = styled.div` + display: flex; + justify-content: space-between; + border-bottom: 1px solid ${({ theme }) => theme.color.white}; + align-content: center; + + svg { + color: $white; + width: 2em; + height: 2em; + transition: 0.3s; + margin: auto 0; + } +`; + +export const StyledHeading = styled.h3` + display: inline-block; + font-size: 1.625rem; + user-select: none; +`; + +export const StyledIngredient = styled.li` + display: flex; + justify-content: space-between; + align-items: center; + + span:first-child { + width: 50%; + } +`; + +export const StyledAccordionText = styled.p` + margin-top: 0; +`; + +export const StyledRecipeInfoItem = styled.li` + margin-bottom: 60px !important; + + summary { + list-style: none; + cursor: pointer; + padding: ${pxToRem(3)}; + } + + summary::-webkit-details-marker { + display: none; + } + + details[open] { + svg { + transform: rotate(-180deg); + } + } +`; + +export const DivCollapseContent = styled.div` + ${collapseContent} +`; + +export const UlCollapseContent = styled.ul` + ${collapseContent} + + li { + padding: 8px 0; + } +`; + +export const OlCollapseContent = styled.ol` + ${collapseContent} + list-style: decimal-leading-zero; + padding-left: 1.8em; + + li { + padding: 8px 0; + } +`; + +export const StyledAccordion = styled.ul` + ${media.desktop} { + width: 45%; + height: 70vh; + overflow: auto; + } + + ${media.mobile} { + margin-top: 20px; + } + + display: block; + color: ${({ theme }) => theme.color.white}; + margin: 0; +`; diff --git a/src/components/Accordion/Accordion.tsx b/src/components/Accordion/Accordion.tsx new file mode 100644 index 0000000..faa5ea7 --- /dev/null +++ b/src/components/Accordion/Accordion.tsx @@ -0,0 +1,22 @@ +import { AccordionProps } from './Accordion.types'; +import { Collapse } from './Collapse'; +import { StyledAccordion } from './Accordion.styled'; + +export const Accordion = ({ recipeDetails }: AccordionProps) => { + return ( + + {recipeDetails.map(({ type, data }) => { + switch (type) { + case 'ingredients': + return ; + case 'equipment': + return ; + case 'summary': + return ; + case 'instructions': + return ; + } + })} + + ); +}; diff --git a/src/components/Accordion/Accordion.types.ts b/src/components/Accordion/Accordion.types.ts new file mode 100644 index 0000000..a03ea0a --- /dev/null +++ b/src/components/Accordion/Accordion.types.ts @@ -0,0 +1,38 @@ +type RecipeDetailType = 'ingredients' | 'equipment' | 'summary' | 'instructions'; + +interface Ingredient { + unit: string; + name: string; + amount: number; +} + +interface IngredientDetail { + type: 'ingredients'; + data: Ingredient[]; +} + +interface EquipmentDetail { + type: 'equipment'; + data: string[]; +} + +interface SummaryDetail { + type: 'summary'; + data: string; +} +interface InstructionDetail { + type: 'instructions'; + data: string[]; +} + +export interface CollapseHeadingProps { + heading: RecipeDetailType; +} + +export type CollapseContentProps = IngredientDetail | EquipmentDetail | SummaryDetail | InstructionDetail; + +export type RecipeDetail = [IngredientDetail, EquipmentDetail, SummaryDetail, InstructionDetail]; + +export interface AccordionProps { + recipeDetails: RecipeDetail; +} diff --git a/src/components/Accordion/Collapse.tsx b/src/components/Accordion/Collapse.tsx new file mode 100644 index 0000000..0b2568a --- /dev/null +++ b/src/components/Accordion/Collapse.tsx @@ -0,0 +1,56 @@ +import { CollapseContentProps } from './Accordion.types'; +import { CollapseContent } from './CollapseContent'; +import { CollapseHeading } from './CollapseHeading'; +import { StyledRecipeInfoItem, UlCollapseContent, OlCollapseContent, DivCollapseContent } from './Accordion.styled'; + +export const Collapse = ({ type, data }: CollapseContentProps): JSX.Element => { + let collapseContentContainer = null; + + switch (type) { + case 'ingredients': + collapseContentContainer = ( + + + + ); + break; + case 'equipment': + collapseContentContainer = + !data || !data.length ? ( +

No Equipment.

+ ) : ( + + + + ); + break; + case 'summary': + collapseContentContainer = ( + + + + ); + break; + case 'instructions': + collapseContentContainer = + !data || !data.length ? ( +

No Instructions.

+ ) : ( + + + + ); + break; + } + + return ( + +
+ + + + {collapseContentContainer} +
+
+ ); +}; diff --git a/src/components/Accordion/CollapseContent.tsx b/src/components/Accordion/CollapseContent.tsx new file mode 100644 index 0000000..cf67848 --- /dev/null +++ b/src/components/Accordion/CollapseContent.tsx @@ -0,0 +1,44 @@ +import { CollapseContentProps } from './Accordion.types'; +import { StyledIngredient, StyledAccordionText } from './Accordion.styled'; + +export const CollapseContent = ({ type, data }: CollapseContentProps): JSX.Element => { + switch (type) { + case 'ingredients': + return ( + <> + {data.map((ingredient, index) => ( + + {ingredient.name} + {`${ingredient.amount.toFixed(2)} ${ingredient.unit}`} + + ))} + + ); + case 'equipment': + return ( + <> + {data.map((equipment, index) => ( +
  • {equipment}
  • + ))} + + ); + case 'summary': + return ( + <> + {data.split('. ').map((text, index, texts) => ( + {text + (index < texts.length - 1 ? '.' : '')} + ))} + + ); + case 'instructions': + return ( + <> + {data.map((instruction, index) => ( +
  • + {instruction} +
  • + ))} + + ); + } +}; diff --git a/src/components/Accordion/CollapseHeading.tsx b/src/components/Accordion/CollapseHeading.tsx new file mode 100644 index 0000000..848c7aa --- /dev/null +++ b/src/components/Accordion/CollapseHeading.tsx @@ -0,0 +1,12 @@ +import { GoChevronDown } from 'react-icons/go'; +import { CollapseHeadingProps } from './Accordion.types'; +import { StyledCollapseHeading, StyledHeading } from './Accordion.styled'; + +export const CollapseHeading = ({ heading }: CollapseHeadingProps): JSX.Element => { + return ( + + {heading} + + + ); +}; diff --git a/src/components/index.ts b/src/components/index.ts index 9ea4a6c..d927acb 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -17,3 +17,4 @@ export * from './ErrorBoundary/ErrorBoundary'; export * from './Card/Card'; export * from './RandomRecipe/RandomRecipe'; export * from './HotRecipes/HotRecipes'; +export * from './Accordion/Accordion'; diff --git a/src/theme/theme.d.ts b/src/theme/emotion.d.ts similarity index 100% rename from src/theme/theme.d.ts rename to src/theme/emotion.d.ts