mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 20:57:51 +00:00
22 lines
663 B
TypeScript
22 lines
663 B
TypeScript
import CoreCharge from 'components/core-charge';
|
|
import { ProductVariant } from 'lib/shopify/types';
|
|
|
|
type CoreChargeBadgeProps = {
|
|
selectedOptions: {
|
|
name: string;
|
|
value: string;
|
|
}[];
|
|
variants: ProductVariant[];
|
|
};
|
|
|
|
const CoreChargeBadge = ({ variants, selectedOptions }: CoreChargeBadgeProps) => {
|
|
const selectedOptionsMap = new Map(selectedOptions.map((option) => [option.name, option.value]));
|
|
const variant = variants.find((variant: ProductVariant) =>
|
|
variant.selectedOptions.every((option) => option.value === selectedOptionsMap.get(option.name))
|
|
);
|
|
|
|
return <CoreCharge variant={variant} sm />;
|
|
};
|
|
|
|
export default CoreChargeBadge;
|