Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Add ProductTiles skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfp13 committed Feb 16, 2022
1 parent 9d3c898 commit f034975
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
36 changes: 16 additions & 20 deletions src/components/sections/ProductTiles/ProductTiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Tiles, { Tile } from 'src/components/ui/Tiles'
import ProductCard from 'src/components/product/ProductCard'
import type { ProductSummary_ProductFragment } from '@generated/graphql'
import SkeletonProductTile from 'src/components/skeletons/SkeletonProductTile'
import SkeletonProductTiles from 'src/components/skeletons/SkeletonProductTiles'

interface TilesProps {
products: ProductSummary_ProductFragment[]
Expand Down Expand Up @@ -30,25 +30,21 @@ const ProductTiles = ({ products }: TilesProps) => {
}

return (
<Tiles>
{haveProducts
? products.map((product, idx) => (
<Tile key={`${product.id}`}>
<ProductCard
data-testid="tile-card"
product={product}
index={idx + 1}
variant="horizontal"
ratio={getRatio(idx)}
/>
</Tile>
))
: Array.from({ length: 3 }, (_, index) => (
<Tile key={String(index)}>
<SkeletonProductTile tileIndex={index + 1} variant="horizontal" />
</Tile>
))}
</Tiles>
<SkeletonProductTiles variant="horizontal" loading={!haveProducts}>
<Tiles>
{products.map((product, idx) => (
<Tile key={`${product.id}`}>
<ProductCard
data-testid="tile-card"
product={product}
index={idx + 1}
variant="horizontal"
ratio={getRatio(idx)}
/>
</Tile>
))}
</Tiles>
</SkeletonProductTiles>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import Shimmer from '../Shimmer'
import SkeletonElement from '../SkeletonElement'
import Shimmer from '../../Shimmer'
import SkeletonElement from '../../SkeletonElement'
import './skeleton-product-tile.scss'

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../../../styles/vendors/include-media.scss";
@import "../../../../styles/vendors/include-media.scss";

[data-store-skeleton-product-tile] {
position: relative;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import Tiles, { Tile } from 'src/components/ui/Tiles'

import SkeletonProductTile from './SkeletonProductTile'

interface Props {
loading?: boolean
children?: JSX.Element
variant?: 'vertical' | 'horizontal'
}

function SkeletonProductTiles({
children,
loading = true,
variant = 'vertical',
}: Props) {
return loading ? (
<Tiles>
{Array.from({ length: 3 }, (_, index) => (
<Tile key={String(index)}>
<SkeletonProductTile tileIndex={index + 1} variant={variant} />
</Tile>
))}
</Tiles>
) : (
children ?? null
)
}

export default SkeletonProductTiles
1 change: 1 addition & 0 deletions src/components/skeletons/SkeletonProductTiles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './SkeletonProductTiles'

0 comments on commit f034975

Please sign in to comment.