-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7c0ad8
commit 3b5a72b
Showing
14 changed files
with
419 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import React, { FC, useMemo } from "react"; | ||
import { SelectedOptions } from "types/cart"; | ||
import { Product } from "types/product"; | ||
import { calcFinalPrice } from "utils/product"; | ||
import { DisplayPrice } from "./price"; | ||
|
||
export const FinalPrice: FC<{ children: Product }> = ({ children }) => { | ||
const finalPrice = useMemo(() => calcFinalPrice(children), [children]); | ||
export const FinalPrice: FC<{ | ||
children: Product; | ||
options?: SelectedOptions; | ||
}> = ({ children, options }) => { | ||
const finalPrice = useMemo( | ||
() => calcFinalPrice(children, options), | ||
[children, options] | ||
); | ||
return <DisplayPrice>{finalPrice}</DisplayPrice>; | ||
}; |
This file contains 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,25 @@ | ||
import React, { FC, useMemo } from "react"; | ||
import { Option, Product } from "types/product"; | ||
import { calcFinalPrice } from "utils/product"; | ||
import { DisplayPrice } from "./price"; | ||
|
||
export const DisplayPriceChange: FC<{ children: Product; option: Option }> = ({ | ||
children, | ||
option, | ||
}) => { | ||
const changes = useMemo( | ||
() => | ||
option.priceChange | ||
? option.priceChange.type === "fixed" | ||
? option.priceChange.amount | ||
: children.price * option.priceChange.percent | ||
: 0, | ||
[children, option] | ||
); | ||
return ( | ||
<> | ||
{changes > 0 && "+"} | ||
<DisplayPrice>{changes}</DisplayPrice> | ||
</> | ||
); | ||
}; |
This file contains 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,42 @@ | ||
import React, { FC, useMemo } from "react"; | ||
import { SelectedOptions } from "types/cart"; | ||
import { Product } from "types/product"; | ||
|
||
export const DisplaySelectedOptions: FC<{ | ||
children: Product; | ||
options: SelectedOptions; | ||
}> = ({ children, options }) => { | ||
const description = useMemo(() => { | ||
let variants: string[] = []; | ||
if (children.variants) { | ||
const selectedVariants = Object.keys(options); | ||
children.variants | ||
.filter((v) => selectedVariants.includes(v.key)) | ||
.forEach((variant) => { | ||
if (variant.type === "single") { | ||
const selectedOption = variant.options.find( | ||
(o) => o.key === options[variant.key] | ||
); | ||
if (selectedOption) { | ||
variants.push( | ||
`${variant.label || variant.key}: ${ | ||
selectedOption.label || selectedOption.key | ||
}` | ||
); | ||
} | ||
} else { | ||
const selectedOptions = variant.options.filter((o) => | ||
options[variant.key].includes(o.key) | ||
); | ||
variants.push( | ||
`${variant.label || variant.key}: ${selectedOptions | ||
.map((o) => o.label || o.key) | ||
.join(", ")}` | ||
); | ||
} | ||
}); | ||
} | ||
return variants.join(". "); | ||
}, [children]); | ||
return <>{description}</>; | ||
}; |
This file contains 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 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,40 @@ | ||
import { DisplayPriceChange } from "components/display/price-change"; | ||
import React, { FC } from "react"; | ||
import { MultipleOptionVariant, Product } from "types/product"; | ||
import { Box, Checkbox, Text } from "zmp-ui"; | ||
|
||
export const MultipleOptionPicker: FC<{ | ||
product: Product; | ||
variant: MultipleOptionVariant; | ||
value: string[]; | ||
onChange: (value: string[]) => void; | ||
}> = ({ product, variant, value, onChange }) => { | ||
return ( | ||
<Box my={8} className="space-y-2"> | ||
<Text.Title size="small">{variant.label}</Text.Title> | ||
<Checkbox.Group | ||
className="flex flex-col space-y-2" | ||
name={variant.key} | ||
options={variant.options.map((option) => ({ | ||
className: "last-of-type:mr-2", | ||
value: option.key, | ||
label: ( | ||
<div className="w-full"> | ||
<span className="flex-1">{option.label}</span> | ||
<span className="absolute right-0"> | ||
<DisplayPriceChange option={option}> | ||
{product} | ||
</DisplayPriceChange> | ||
</span> | ||
</div> | ||
) as any, | ||
}))} | ||
value={value} | ||
defaultValue={value} | ||
onChange={(selectedOptions: string[]) => { | ||
onChange(selectedOptions); | ||
}} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file contains 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 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,27 @@ | ||
import React, { FC } from "react"; | ||
import { Variant } from "types/product"; | ||
import { Box, Radio, Text } from "zmp-ui"; | ||
|
||
export const SingleOptionPicker: FC<{ | ||
variant: Variant; | ||
value: string; | ||
onChange: (value: string) => void; | ||
}> = ({ variant, value, onChange }) => { | ||
return ( | ||
<Box my={8} className="space-y-2"> | ||
<Text.Title size="small">{variant.label}</Text.Title> | ||
<Radio.Group | ||
className="flex-1 grid grid-cols-3 justify-between" | ||
name={variant.key} | ||
options={variant.options.map((option) => ({ | ||
value: option.key, | ||
label: option.label, | ||
}))} | ||
value={value} | ||
onChange={(selectedOption: string) => { | ||
onChange(selectedOption); | ||
}} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.