Skip to content

Commit

Permalink
feat(core): add Pagination component (bigcommerce#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya authored Aug 6, 2024
1 parent b7d4986 commit 53ccd31
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-cooks-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Add `Pagination` component.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { NextIntlClientProvider } from 'next-intl';
import { getMessages, getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { ProductCard } from '~/components/product-card';
import { Pagination } from '~/components/ui/pagination';
import { LocaleType } from '~/i18n';

import { FacetedSearch } from '../../_components/faceted-search';
import { MobileSideNav } from '../../_components/mobile-side-nav';
import { Pagination } from '../../_components/pagination';
import { SortBy } from '../../_components/sort-by';
import { fetchFacetedSearch } from '../../fetch-faceted-search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { getMessages, getTranslations, unstable_setRequestLocale } from 'next-in

import { Breadcrumbs } from '~/components/breadcrumbs';
import { ProductCard } from '~/components/product-card';
import { Pagination } from '~/components/ui/pagination';
import { LocaleType } from '~/i18n';

import { FacetedSearch } from '../../_components/faceted-search';
import { MobileSideNav } from '../../_components/mobile-side-nav';
import { Pagination } from '../../_components/pagination';
import { SortBy } from '../../_components/sort-by';
import { fetchFacetedSearch } from '../../fetch-faceted-search';

Expand Down
2 changes: 1 addition & 1 deletion core/app/[locale]/(default)/(faceted)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { getMessages, getTranslations } from 'next-intl/server';

import { ProductCard } from '~/components/product-card';
import { SearchForm } from '~/components/search-form';
import { Pagination } from '~/components/ui/pagination';
import { LocaleType } from '~/i18n';

import { FacetedSearch } from '../_components/faceted-search';
import { MobileSideNav } from '../_components/mobile-side-nav';
import { Pagination } from '../_components/pagination';
import { SortBy } from '../_components/sort-by';
import { fetchFacetedSearch } from '../fetch-faceted-search';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getLocale, getTranslations } from 'next-intl/server';

import { getCustomerAddresses } from '~/client/queries/get-customer-addresses';
import { Pagination } from '~/components/ui/pagination';

import { Pagination } from '../../../../(faceted)/_components/pagination';
import { TabHeading } from '../tab-heading';

import { AddressBook } from './address-book';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const AddressesContent = async ({
<TabHeading heading="addresses" />
<AddressBook addressesCount={addressesCount} customerAddresses={addresses} key={endCursor}>
<Pagination
className="my-0 flex inline-flex justify-center text-center"
className="my-0 inline-flex justify-center text-center"
endCursor={endCursor}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
Expand Down
3 changes: 3 additions & 0 deletions core/components/ui/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';

export * from './pagination';
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use client';

import { ChevronLeft, ChevronRight } from 'lucide-react';
import { usePathname, useSearchParams } from 'next/navigation';
import { ComponentPropsWithoutRef } from 'react';

import { Link } from '~/components/link';
import { cn } from '~/lib/utils';

interface PaginationProps {
className?: string;
interface Props extends ComponentPropsWithoutRef<'nav'> {
endCursor: string | null;
hasPreviousPage: boolean;
hasNextPage: boolean;
Expand All @@ -16,15 +14,17 @@ interface PaginationProps {
nextLabel: string;
}

export const Pagination = ({
const Pagination = ({
className,
children,
endCursor,
hasPreviousPage,
hasNextPage,
startCursor,
prevLabel,
nextLabel,
}: PaginationProps) => {
...props
}: Props) => {
const pathname = usePathname();
const searchParams = useSearchParams();

Expand All @@ -45,7 +45,11 @@ export const Pagination = ({
}

return (
<nav aria-label="Pagination" className={cn('my-6 text-center text-primary', className)}>
<nav
aria-label="Pagination"
className={cn('my-6 text-center text-primary', className)}
{...props}
>
{hasPreviousPage ? (
<Link className="inline-block" href={`${pathname}?${beforeSearchParams.toString()}`}>
<span className="sr-only">{prevLabel}</span>
Expand All @@ -66,3 +70,5 @@ export const Pagination = ({
</nav>
);
};

export { Pagination };

0 comments on commit 53ccd31

Please sign in to comment.