This repository was archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
(CEM-2514) MenuItemCard Component #383
Open
mfnisbetLU
wants to merge
15
commits into
cheapreats:master
Choose a base branch
from
mfnisbetLU:CEM-2514
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1a75865
Initial Commit
mfnisbetLU 08383b9
(CEM-2514) Menu Item Card Initial Commit
mfnisbetLU 64ee9f9
(CEM-2514) Soldout state + component position fixes
mfnisbetLU db04009
Changed default, added multiple stories for state testing
mfnisbetLU 74a4b8c
Fixed children arguments, added rounding edge case, increased item te…
mfnisbetLU 5f5ffc2
Merge branch 'master' into CEM-2514
mfnisbetLU 6968e20
Delete LimitedTimeBanner.stories.tsx
mfnisbetLU 92fb926
Delete LimitedTimeBanner.tsx
mfnisbetLU 2d4a1ac
Delete LoyaltyPoints.stories.tsx
mfnisbetLU 8cc63c9
Delete SaleTag.stories.tsx
mfnisbetLU 0ac735a
Delete LoyaltyPoints.tsx
mfnisbetLU 276f6d8
Delete SaleTag.tsx
mfnisbetLU b9d59e3
Revised draft of Menu Item Card using variable names from related com…
mfnisbetLU 79f213e
CEM-2514 Revised draft
mfnisbetLU 0b9a668
Merge branch 'CEM-2514' of https://github.com/mfnisbetLU/react-ui-lib…
mfnisbetLU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React from 'react'; | ||
| import { Meta, Story } from '@storybook/react'; | ||
| import { MenuItemCard, MenuItemCardProps, LoyaltyPoints, LimitedTimeBanner, SaleTag} from '../../index'; | ||
| import { createStoryTitle } from '../../Constants'; | ||
|
|
||
| export default { | ||
| title: createStoryTitle('MenuItemCard'), | ||
| component: MenuItemCard, | ||
| subcomponents: {LoyaltyPoints, LimitedTimeBanner, SaleTag}, | ||
| argTypes: { onClick: { action: 'Link to next step' } }, | ||
| } as Meta; | ||
|
|
||
| const Template: Story<MenuItemCardProps> = (args) => <MenuItemCard {...args}> <LoyaltyPoints {...args}/> | ||
| <LimitedTimeBanner {...args}/> <SaleTag {...args} /> </MenuItemCard>; | ||
|
|
||
| export const MenuItemCardBasic = Template.bind({}); | ||
| MenuItemCardBasic.args = { | ||
| itemImage: 'https://keyassets-p2.timeincuk.net/wp/prod/wp-content/uploads/sites/63/2007/09/Ricotta-cheese-pancakes-with-blackberry-butter.jpg', | ||
| itemName: 'Blackberry Pancakes', | ||
| itemPrice: 15.99, | ||
| itemPriceLimit: 1000, | ||
| saleAmount: 5, | ||
| loyaltyamount: 20, | ||
| loyaltypointlimit: 100, | ||
| minsRemaining: 120, | ||
| sale: false, | ||
| soldOut: false, | ||
| widthFitContent: false, | ||
| heightFitContent: false, | ||
| animated: true, | ||
| flat: false, | ||
| }; | ||
|
|
||
| export const MenuItemCardStates = Template.bind({}); | ||
| MenuItemCardStates.args = { | ||
| itemImage: 'https://keyassets-p2.timeincuk.net/wp/prod/wp-content/uploads/sites/63/2007/09/Ricotta-cheese-pancakes-with-blackberry-butter.jpg', | ||
| itemName: 'Blackberry Pancakes', | ||
| itemPrice: 15.99, | ||
| itemPriceLimit: 1000, | ||
| saleAmount: 5, | ||
| loyaltyamount: 0, | ||
| loyaltypointlimit: 100, | ||
| minsRemaining: 0, | ||
| sale: true, | ||
| soldOut: true, | ||
| widthFitContent: false, | ||
| heightFitContent: true, | ||
| animated: false, | ||
| flat: false, | ||
| }; | ||
|
|
||
| export const MenuItemCardLongText = Template.bind({}); | ||
| MenuItemCardLongText.args = { | ||
| itemImage: 'https://keyassets-p2.timeincuk.net/wp/prod/wp-content/uploads/sites/63/2007/09/Ricotta-cheese-pancakes-with-blackberry-butter.jpg', | ||
| itemName: 'Super crazy long combo special order with extra sides and drinks blackberry pancakes', | ||
| itemPrice: 2560, | ||
| itemPriceLimit: 1000, | ||
| saleAmount: 200, | ||
| loyaltyamount: 150, | ||
| loyaltypointlimit: 100, | ||
| minsRemaining: 24000, | ||
| sale: false, | ||
| soldOut: false, | ||
| widthFitContent: false, | ||
| heightFitContent: true, | ||
| animated: true, | ||
| flat: false, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
| import { Main, MainInterface, Responsive, ResponsiveInterface } from '@Utils/BaseStyles'; | ||
| import { transition } from '@Utils/Mixins'; | ||
| // eslint-disable-next-line import/no-cycle | ||
| import { LoyaltyPoints, LimitedTimeBanner, SaleTag } from '../../index'; | ||
|
|
||
| export interface MenuItemCardProps | ||
| extends MainInterface, ResponsiveInterface, React.HTMLAttributes<HTMLDivElement> { | ||
| LoyaltyPoints?: React.ReactElement; | ||
| LimitedTimeBanner?: React.ReactElement; | ||
| SaleTag?: React.ReactElement; | ||
| itemImage: string, // Image for the Menu Item Card, hosted on any server and converted to 350px x 200px | ||
| itemName: string, // Item name, heightFitContent adjusts the item card size to fit any text (keeping min size of 350px) | ||
| itemPrice: number, // Price of the item, will be adjusted by saleAmount and will reduce + round if above 1000 | ||
| itemPriceLimit: number, // Limit before item price is divided by 1000, should be greater than 1000 | ||
| animated?: boolean; | ||
| flat?: boolean; | ||
| widthFitContent?: boolean; | ||
| heightFitContent?: boolean; | ||
| sale?: boolean; | ||
| soldOut?: boolean; | ||
| loyaltyamount: number, | ||
| loyaltypointlimit: number, | ||
| saleAmount: number, | ||
| minsRemaining: number, | ||
| } | ||
|
|
||
| export const ItemCard: React.FC<MenuItemCardProps> = ({ | ||
| children, | ||
| ...props | ||
| }): React.ReactElement => <MenuItemCardBox {...props}>{children}</MenuItemCardBox>; | ||
|
|
||
| export const MenuItemCard: React.FC<MenuItemCardProps> = ({ | ||
| animated, | ||
| flat, | ||
| widthFitContent, | ||
| heightFitContent, | ||
| sale, | ||
| soldOut, | ||
| itemImage, | ||
| itemName, | ||
| itemPrice, | ||
| itemPriceLimit, | ||
| saleAmount, | ||
| loyaltyamount, | ||
| loyaltypointlimit, | ||
| minsRemaining, | ||
| ...props | ||
|
|
||
| }): React.ReactElement => ( | ||
| <ItemCard {...props} itemImage={itemImage} itemName={itemName} itemPrice={itemPrice} animated={animated} | ||
| flat={flat} widthFitContent={widthFitContent} sale={sale} soldOut={soldOut} saleAmount = {saleAmount} itemPriceLimit = {itemPriceLimit} | ||
| loyaltyamount = {loyaltyamount} minsRemaining = {minsRemaining} loyaltypointlimit = {loyaltypointlimit} heightFitContent = {heightFitContent}> | ||
|
|
||
| <img src={itemImage} alt={itemName} style={{ width: 350, height: 200 }}/> | ||
| <ItemHeader>{itemName}</ItemHeader> | ||
| { soldOut && <SoldOutBox>Sold Out</SoldOutBox>} | ||
|
|
||
| { !!minsRemaining && | ||
| <LimitedTimeBannerPosition> <LimitedTimeBanner minsRemaining={minsRemaining}/></LimitedTimeBannerPosition> } | ||
|
|
||
| { !!loyaltyamount && | ||
| <LoyaltyPointsPosition> <LoyaltyPoints loyaltyamount={loyaltyamount} loyaltypointlimit = {loyaltypointlimit} /></LoyaltyPointsPosition> } | ||
|
|
||
| { !!saleAmount && | ||
| <SaleTagPosition><SaleTag saleAmount={saleAmount}/></SaleTagPosition> } | ||
|
Comment on lines
+58
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you abstract this all out into a getMenuItemStatus function. What happens if someone passes in two conflicting states. We will need to override. |
||
|
|
||
| { sale | ||
| ? <> | ||
| <SalePropsSlash>${itemPrice}</SalePropsSlash> | ||
| <OnSale>${itemPrice - saleAmount}</OnSale> | ||
| </> | ||
| : [ itemPrice >= itemPriceLimit | ||
| ? <> <SaleProps1k>${getItemValue(itemPrice, itemPriceLimit)}K</SaleProps1k> </> | ||
| : <SaleProps>${itemPrice}</SaleProps> | ||
| ] | ||
| } | ||
| </ItemCard> | ||
| ); | ||
| /** | ||
| * Checks if the Item Price is greater than or equal to the item price limit | ||
| * Returns item price to the nearest tenth rounded | ||
| * Also reduces the amount by 1000, the K is added in the component | ||
| */ | ||
| function getItemValue(itemPrice: number, itemPriceLimit: number){ | ||
| if(itemPrice >= itemPriceLimit) | ||
| return ((Math.round(itemPrice * .1) / .1) / 1000) | ||
| return itemPriceLimit }; | ||
|
|
||
| const MenuItemCardBox = styled.div<MenuItemCardProps & MainInterface & ResponsiveInterface>` | ||
| position: relative; | ||
| width: 350px; | ||
| height: 350px; | ||
| min-height: 350px; | ||
| z-index: 1; | ||
| cursor: pointer; | ||
| box-shadow: ${({ flat, theme }): string => theme.depth[flat ? 0 : 1]}; | ||
|
|
||
| ${({ theme, ...props }): string => ` | ||
| border-radius: ${theme.dimensions.radius}; | ||
| font-family: ${theme.colors.background}}; | ||
| background-color: white; | ||
| ${Main({ | ||
| ...props, | ||
| })} `} | ||
|
|
||
| ${({ animated, flat, theme }): string => | ||
| animated ? ` ${transition(['box-shadow'])} &:hover { | ||
| box-shadow: ${theme.depth[flat ? 1 : 2]}; | ||
| }` : ''} | ||
|
|
||
| ${Responsive} | ||
|
|
||
| ${({ soldOut }) => | ||
| soldOut && ` | ||
| opacity: 0.5; | ||
| cursor: not-allowed; `} | ||
|
|
||
| ${({ widthFitContent }): string => `${widthFitContent ? 'width:fit-content;' : ''} `} | ||
| ${({ heightFitContent }): string => `${heightFitContent ? 'height:fit-content;' : ''} `} | ||
| `; | ||
| const SoldOutBox = styled.div` | ||
| ${({theme}):string => ` | ||
| font-family: ${theme.font.family}; | ||
| color: ${theme.colors.background}}; | ||
| `} | ||
| position: absolute; | ||
| z-index: 2; | ||
| top: 0px; | ||
| background-color: rgba(48,48,48,48.0); | ||
| font-size: 25px; | ||
| text-align: center; | ||
| width: 350px; | ||
| height: 40px; | ||
| padding-top: 15px; | ||
| `; | ||
| const ItemHeader = styled.header` | ||
| font-weight: bold; | ||
| padding-left: 10px; | ||
| padding-bottom: 10px; | ||
| padding-right: 120px; | ||
| font-size: 35px; | ||
| ` | ||
| const SaleProps = styled.header` | ||
| font-weight: bold; | ||
| position: absolute; | ||
| font-size: 30px; | ||
| text-align: right; | ||
| right: 10px; | ||
| top: 300px; | ||
| ` | ||
| const SalePropsSlash = styled(SaleProps)` | ||
| text-decoration: line-through; | ||
| font-size: 25px; | ||
| opacity: .6; | ||
| top: 230px; | ||
| ` | ||
| const SaleProps1k = styled(SaleProps)` | ||
| font-size: 35px; | ||
| ${({theme}):string => ` | ||
| color: ${theme.colors.ItemCardSaleGreen}; | ||
| `} | ||
| ` | ||
| const OnSale = styled.header` | ||
| position: absolute; | ||
| font-size: 35px; | ||
| text-align: right; | ||
| font-weight: bold; | ||
| ${({theme}):string => ` | ||
| color: ${theme.colors.primary}; | ||
| `} | ||
| padding-right: 10px; | ||
| right: 10px; | ||
| top: 300px; | ||
| ` | ||
| const LoyaltyPointsPosition = styled.div` | ||
| position: absolute; | ||
| top: 30px; | ||
| ` | ||
| const SaleTagPosition = styled.div` | ||
| position: absolute; | ||
| right: 10px; | ||
| top: 53px; | ||
| ` | ||
| const LimitedTimeBannerPosition = styled.div` | ||
| position: absolute; | ||
| top: 160px; | ||
| ` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Rounds amount to the nearest positive integer above 0 | ||
| * @param {number} amount - Number to round | ||
| * @returns {number} - Rounded amount above 0 | ||
| */ | ||
| export const positiveRounding = (amount:number): number => (amount >= 1 ? Math.round(amount) : 1); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in gitignore??