-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Matt Seccafien <[email protected]> Co-authored-by: Bret Little <[email protected]> Co-authored-by: Anthony Frehner <[email protected]>
- Loading branch information
1 parent
2e97b1e
commit ba54a3b
Showing
25 changed files
with
1,570 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Add a `<Pagination__unstable>` component and `getPaginationVariables__unstable` helper to make rendering large lists from the Storefront API easy. This is an initial unstable release and we expect to finalize the API by the 2023-07 release. See the [`<Pagination>` component documentation](https://shopify.dev/docs/api/hydrogen/2023-04/components/pagination). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
602 changes: 490 additions & 112 deletions
602
packages/hydrogen/docs/generated/generated_docs_data.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'Pagination', | ||
category: 'components', | ||
isVisualComponent: false, | ||
related: [ | ||
{ | ||
name: 'getPaginationVariables', | ||
type: 'utilities', | ||
url: '/docs/api/hydrogen/utilities/getpaginationvariables', | ||
}, | ||
], | ||
description: `> Caution: | ||
> This component is in an unstable pre-release state and may have breaking changes in a future release. | ||
The [Storefront API uses cursors](https://shopify.dev/docs/api/usage/pagination-graphql) to paginate through lists of data and the \`<Pagination />\` component makes it easy to paginate data from the Storefront API. It is important for pagination state to be maintained in the URL, so that the user can navigate to a product and return back to the same scrolled position in a list. It is also important that the list state is shareable via URL. The \`<Pagination>\` component provides a render prop with properties to load more elements into your list.`, | ||
type: 'component', | ||
defaultExample: { | ||
description: 'I am the default example', | ||
codeblock: { | ||
tabs: [ | ||
{ | ||
title: 'JavaScript', | ||
code: './Pagination.example.jsx', | ||
language: 'jsx', | ||
}, | ||
{ | ||
title: 'TypeScript', | ||
code: './Pagination.example.tsx', | ||
language: 'tsx', | ||
}, | ||
], | ||
title: 'Example code', | ||
}, | ||
}, | ||
definitions: [ | ||
{ | ||
title: 'Props', | ||
type: 'PaginationProps', | ||
description: '', | ||
}, | ||
], | ||
}; | ||
|
||
export default data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {json} from '@shopify/remix-oxygen'; | ||
import { | ||
Pagination__unstable as Pagination, | ||
getPaginationVariables__unstable as getPaginationVariables, | ||
} from '@shopify/hydrogen'; | ||
import {useLoaderData, Link} from '@remix-run/react'; | ||
|
||
export async function loader({request, context: {storefront}}) { | ||
const variables = getPaginationVariables(request, {pageBy: 8}); | ||
|
||
const data = await storefront.query(ALL_PRODUCTS_QUERY, { | ||
variables, | ||
}); | ||
|
||
return json({products: data.products}); | ||
} | ||
|
||
export default function List() { | ||
const {products} = useLoaderData(); | ||
|
||
return ( | ||
<Pagination connection={products}> | ||
{({nodes, PreviousLink, NextLink}) => ( | ||
<> | ||
<PreviousLink>Previous</PreviousLink> | ||
<div> | ||
{nodes.map((product) => ( | ||
<Link key={product.id} to={`/products/${product.handle}`}> | ||
{product.title} | ||
</Link> | ||
))} | ||
</div> | ||
<NextLink>Next</NextLink> | ||
</> | ||
)} | ||
</Pagination> | ||
); | ||
} | ||
|
||
const ALL_PRODUCTS_QUERY = `#graphql | ||
query AllProducts( | ||
$country: CountryCode | ||
$language: LanguageCode | ||
$first: Int | ||
$last: Int | ||
$startCursor: String | ||
$endCursor: String | ||
) @inContext(country: $country, language: $language) { | ||
products(first: $first, last: $last, before: $startCursor, after: $endCursor) { | ||
nodes { id | ||
title | ||
handle | ||
} | ||
pageInfo { | ||
hasPreviousPage | ||
hasNextPage | ||
startCursor | ||
endCursor | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {json, type LoaderArgs} from '@shopify/remix-oxygen'; | ||
import { | ||
Pagination__unstable as Pagination, | ||
getPaginationVariables__unstable as getPaginationVariables, | ||
} from '@shopify/hydrogen'; | ||
import {useLoaderData, Link} from '@remix-run/react'; | ||
import {ProductConnection} from '@shopify/hydrogen/storefront-api-types'; | ||
|
||
export async function loader({request, context: {storefront}}: LoaderArgs) { | ||
const variables = getPaginationVariables(request, {pageBy: 8}); | ||
|
||
const data = await storefront.query<{products: ProductConnection}>( | ||
ALL_PRODUCTS_QUERY, | ||
{ | ||
variables, | ||
}, | ||
); | ||
|
||
return json({products: data.products}); | ||
} | ||
|
||
export default function List() { | ||
const {products} = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
<Pagination connection={products}> | ||
{({nodes, NextLink, PreviousLink}) => ( | ||
<> | ||
<PreviousLink>Previous</PreviousLink> | ||
<div> | ||
{nodes.map((product) => ( | ||
<Link key={product.id} to={`/products/${product.handle}`}> | ||
{product.title} | ||
</Link> | ||
))} | ||
</div> | ||
<NextLink>Next</NextLink> | ||
</> | ||
)} | ||
</Pagination> | ||
); | ||
} | ||
|
||
const ALL_PRODUCTS_QUERY = `#graphql | ||
query AllProducts( | ||
$country: CountryCode | ||
$language: LanguageCode | ||
$first: Int | ||
$last: Int | ||
$startCursor: String | ||
$endCursor: String | ||
) @inContext(country: $country, language: $language) { | ||
products(first: $first, last: $last, before: $startCursor, after: $endCursor) { | ||
nodes { id | ||
title | ||
handle | ||
} | ||
pageInfo { | ||
hasPreviousPage | ||
hasNextPage | ||
startCursor | ||
endCursor | ||
} | ||
} | ||
} | ||
`; |
Oops, something went wrong.