Skip to content

Instantly share code, notes, and snippets.

@fourjuaneight
Created January 18, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourjuaneight/66677eaf61141fa4162d2ea80534e883 to your computer and use it in GitHub Desktop.
Save fourjuaneight/66677eaf61141fa4162d2ea80534e883 to your computer and use it in GitHub Desktop.
// src/components/product.js
const Product = ({ product, single, url }) => {
const sizes = {
individual: {
maxImg: '40rem',
maxWrap: '42rem',
},
list: {
maxImg: '20rem',
maxWrap: '22rem',
},
};
return (
<Box
align="center"
pad="small"
width={{ max: single ? sizes.individual.maxWrap : sizes.list.maxWrap }}
>
<ImgWrap
height={{
min: sizes.list.maxImg,
max: single ? sizes.individual.maxImg : sizes.list.maxImg,
}}
overflow="hidden"
round="small"
width={{
min: '18rem',
max: single ? sizes.individual.maxImg : sizes.list.maxImg,
}}
>
<Img isLazy src={product.metadata.image.imgix_url} />
</ImgWrap>
{single ? (
<Heading level="3" textAlign="center">
{product.title}
</Heading>
) : (
<Anchor color="dark-1" href={`products/${product.slug}/`}>
<Heading level="3" textAlign="center">
{product.title}
</Heading>
</Anchor>
)}
<Box align="center" direction="row" justify="around">
<Text>{`$${product.metadata.price}`}</Text>
<Button
className="snipcart-add-item"
color="brand"
data-item-description="Test description."
data-item-id={product.metadata.id}
data-item-image={product.metadata.image.imgix_url}
data-item-name={product.title}
data-item-price={product.metadata.price}
data-item-url={single ? url : `${url}products/${product.slug}/`}
label="Add to Cart"
margin="small"
size="large"
style={size}
type="button"
/>
</Box>
</Box>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment