import * as React from 'react'; import { useState, Fragment, Suspense } from 'react'; import styled from 'styled-components'; // @ts-ignore import Image from '@Components/Image'; import { dim } from '@dim'; import * as tokens from '@tokens'; import { Label, Body } from '@Typography'; import ProductRating from '../ProductRating'; import { ProductCellInterface, ColorInterface } from '../interface'; const ColorSwatches = styled.ul` margin: ${dim(2)} 0 0; padding: 0; `; const ColorSwatchesItem = styled.li` display: inline-block; & + & { margin-left: ${dim(2)}; } `; const ColorSwatch = styled.div` border-radius: 100%; height: ${dim(2)}; width: ${dim(2)}; background-color: ${({ bg }: { bg: string }) => bg}; border: 1px solid ${tokens.colorGrey40}; &:hover { cursor: pointer; } `; const WasPrice = styled.span` margin-left: ${dim()}; color: ${tokens.colorGrey40}; text-decoration: line-through; `; const ProductCell = styled.article` max-width: 100%; text-align: center; margin-top: ${dim(4)}; margin-bottom: ${dim(2)}; `; const ManequinWrapper = styled.div` width: 100%; padding-top: 100%; /* 1:1 Aspect Ratio */ position: relative; img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } `; const ProductName = styled(Label)` margin: ${dim(2)} 0 0; `; const Price = styled(Body)` margin: ${dim(2)} 0 0; `; const ProductStatus = styled(Label)` color: ${tokens.colorGrey40}; margin-top: 0; margin-bottom: ${dim(4)}; `; export default ({ code, name, status = '', colors = [], showSwatches = true, showRating = true, rating = null, ActiveColorLink, ProductLink }: ProductCellInterface) => { const [activeColorIndex, setActiveColorIndex] = useState(0); const [firstColor] = colors; const activeColor: ColorInterface = colors[activeColorIndex] || firstColor; const getManequin: string = typeof activeColor.imageURI === 'string' ? activeColor.imageURI : activeColor.imageURI[0]; const Anchor: React.FC = ({ anchorRenderer, ...anchorProps }) => { if (!anchorRenderer) return ; // @ts-ignore const RenderAnchor: React.FC = (renderProps: any) => anchorRenderer({ code, activeColor, activeColorIndex, ...anchorProps, ...renderProps }); // @ts-ignore return || ; }; return ( {status} }> {name} {showRating && rating && } {name} {activeColor.price.formatted} {activeColor.wasPrice && {activeColor.wasPrice.formatted}} {showSwatches && colors && ( {colors.map((color: ColorInterface, i: number) => ( setActiveColorIndex(i)} bg={color.swatch} > ))} )} ); };