mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
🎨 styles: card product skeleton
:%s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import commerce from '@lib/api/commerce';
|
import commerce from '@lib/api/commerce';
|
||||||
import { GetStaticPropsContext } from 'next';
|
import { GetStaticPropsContext } from 'next';
|
||||||
import { Layout } from 'src/components/common';
|
import { Layout, ListProductCardSkeleton } from 'src/components/common';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
products: any
|
products: any
|
||||||
@@ -8,10 +8,11 @@ interface Props {
|
|||||||
export default function Home({ products }: Props) {
|
export default function Home({ products }: Props) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
{/* <ListProductCardSkeleton /> */}
|
||||||
TOTAL: {products?.length}
|
{/* <ListProductCardSkeleton count={1} /> */}
|
||||||
</p>
|
<ListProductCardSkeleton count={10} />
|
||||||
{JSON.stringify(products[0])}
|
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ab qui magnam debitis ex laborum laboriosam suscipit! Totam excepturi eum libero.
|
||||||
|
<ListProductCardSkeleton count={10} isWrap/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -22,28 +23,9 @@ export async function getServerSideProps({
|
|||||||
locale,
|
locale,
|
||||||
locales,
|
locales,
|
||||||
}: GetStaticPropsContext) {
|
}: GetStaticPropsContext) {
|
||||||
const config = { locale, locales }
|
|
||||||
const productsPromise = commerce.getAllProducts({
|
|
||||||
// const productsPromise = commerce.getAllFacets({
|
|
||||||
variables: {
|
|
||||||
first: 70,
|
|
||||||
// filter: {
|
|
||||||
// name: {
|
|
||||||
// contains: 'ca'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
config,
|
|
||||||
preview,
|
|
||||||
// Saleor provider only
|
|
||||||
...({ featured: true } as any),
|
|
||||||
})
|
|
||||||
|
|
||||||
const { products } = await productsPromise
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { products },
|
props: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,12 @@
|
|||||||
|
.listProductCardSkeleton {
|
||||||
|
display: flex;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&.wrap {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
overflow: unset;
|
||||||
|
> div {
|
||||||
|
margin-bottom: 1.6rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,21 @@
|
|||||||
|
import classNames from 'classnames'
|
||||||
|
import { ProductCardSkeleton } from '..'
|
||||||
|
import s from './ListProductCardSkeleton.module.scss'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
count?: number
|
||||||
|
isWrap?: boolean
|
||||||
|
}
|
||||||
|
const ListProductCardSkeleton = ({ count = 5, isWrap }: Props) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classNames(s.listProductCardSkeleton, { [s.wrap]: isWrap })}>
|
||||||
|
{
|
||||||
|
Array.from(Array(count).keys()).map(item => <ProductCardSkeleton key={item} />)
|
||||||
|
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ListProductCardSkeleton
|
@@ -0,0 +1,15 @@
|
|||||||
|
.productCardSkeleton {
|
||||||
|
max-width: 22.4rem;
|
||||||
|
min-width: 20rem;
|
||||||
|
margin: 0 0.8rem;
|
||||||
|
> div {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
.content {
|
||||||
|
margin-top: 1.6rem;
|
||||||
|
> div {
|
||||||
|
margin: 0;
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
import SkeletonImage from "../SkeletonCommon/SkeletonImage/SkeletonImage"
|
||||||
|
import SkeletonParagraph from "../SkeletonCommon/SkeletonParagraph/SkeletonParagraph"
|
||||||
|
import s from './ProductCardSkeleton.module.scss'
|
||||||
|
|
||||||
|
const ProductCardSkeleton = ({ }) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={s.productCardSkeleton}>
|
||||||
|
<SkeletonImage />
|
||||||
|
<div className={s.content}>
|
||||||
|
<SkeletonParagraph rows={3} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProductCardSkeleton
|
@@ -1,7 +1,16 @@
|
|||||||
.wrapper {
|
.wrapper {
|
||||||
margin: 4rem auto;
|
margin: 4rem auto;
|
||||||
.list {
|
.list {
|
||||||
@apply flex flex-wrap justify-around;
|
@apply grid grid-cols-2;
|
||||||
|
@screen md {
|
||||||
|
@apply grid-cols-3;
|
||||||
|
}
|
||||||
|
@screen lg {
|
||||||
|
@apply grid-cols-4;
|
||||||
|
}
|
||||||
|
@screen xl {
|
||||||
|
@apply grid-cols-6;
|
||||||
|
}
|
||||||
.empty {
|
.empty {
|
||||||
button {
|
button {
|
||||||
margin-top: 1.6rem;
|
margin-top: 1.6rem;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
@import '../../../../styles/utilities';
|
@import '../../../../styles/utilities';
|
||||||
|
|
||||||
.skeletonImage {
|
.skeletonImage {
|
||||||
@apply relative;
|
@apply relative overflow-hidden;
|
||||||
background: #DDDBDD;
|
background: #DDDBDD;
|
||||||
|
|
||||||
&.small {
|
&.small {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
@import '../../../../styles/utilities';
|
@import '../../../../styles/utilities';
|
||||||
|
|
||||||
.skeletonParagraph {
|
.skeletonParagraph {
|
||||||
|
@apply overflow-hidden;
|
||||||
margin: 0 1.6rem;
|
margin: 0 1.6rem;
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
|
@@ -51,5 +51,6 @@ export { default as LayoutCheckout} from './LayoutCheckout/LayoutCheckout'
|
|||||||
export { default as InputPasswordFiledInForm} from './InputPasswordFiledInForm/InputPasswordFiledInForm'
|
export { default as InputPasswordFiledInForm} from './InputPasswordFiledInForm/InputPasswordFiledInForm'
|
||||||
export { default as InputFiledInForm} from './InputFiledInForm/InputFiledInForm'
|
export { default as InputFiledInForm} from './InputFiledInForm/InputFiledInForm'
|
||||||
export { default as MessageCommon} from './MessageCommon/MessageCommon'
|
export { default as MessageCommon} from './MessageCommon/MessageCommon'
|
||||||
|
export { default as ProductCardSkeleton} from './ProductCardSkeleton/ProductCardSkeleton'
|
||||||
|
export { default as ListProductCardSkeleton} from './ListProductCardSkeleton/ListProductCardSkeleton'
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ import { ProductCard } from '@commerce/types/product'
|
|||||||
import { Collection, Facet, FacetValue, QuerySearchArgs } from '@framework/schema'
|
import { Collection, Facet, FacetValue, QuerySearchArgs } from '@framework/schema'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { HeadingCommon, ProductList } from 'src/components/common'
|
import { HeadingCommon, ListProductCardSkeleton, ProductList } from 'src/components/common'
|
||||||
import BreadcrumbCommon from 'src/components/common/BreadcrumbCommon/BreadcrumbCommon'
|
import BreadcrumbCommon from 'src/components/common/BreadcrumbCommon/BreadcrumbCommon'
|
||||||
import SkeletonImage from 'src/components/common/SkeletonCommon/SkeletonImage/SkeletonImage'
|
import SkeletonImage from 'src/components/common/SkeletonCommon/SkeletonImage/SkeletonImage'
|
||||||
import { useSearchProducts } from 'src/components/hooks/product'
|
import { useSearchProducts } from 'src/components/hooks/product'
|
||||||
@@ -108,7 +108,7 @@ const ProductListFilter = ({ facets, collections, products, total }: ProductList
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
(!initialQueryFlag && loading && !productSearchResult) && <SkeletonImage />
|
(!initialQueryFlag && loading && !productSearchResult) && <ListProductCardSkeleton count={DEFAULT_PAGE_SIZE} isWrap/>
|
||||||
}
|
}
|
||||||
<ProductList data={initialQueryFlag ? products : (productSearchResult || [])} total={totalItems !== undefined ? totalItems : total} onPageChange={onPageChange} defaultCurrentPage={currentPage} />
|
<ProductList data={initialQueryFlag ? products : (productSearchResult || [])} total={totalItems !== undefined ? totalItems : total} onPageChange={onPageChange} defaultCurrentPage={currentPage} />
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user