-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(headless commerce react samples): add products per page (#4275)
- Loading branch information
1 parent
8790fbb
commit b5c868c
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...es/samples/headless-commerce-react/src/components/products-per-page/products-per-page.tsx
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,47 @@ | ||
import {Pagination} from '@coveo/headless/commerce'; | ||
import {useEffect, useState} from 'react'; | ||
|
||
interface IProductsPerPageProps { | ||
controller: Pagination; | ||
} | ||
|
||
export default function ProductsPerPage(props: IProductsPerPageProps) { | ||
const {controller} = props; | ||
|
||
const [state, setState] = useState(controller.state); | ||
|
||
useEffect(() => { | ||
controller.subscribe(() => setState(controller.state)); | ||
}, [controller]); | ||
|
||
const options = [5, 10, 20, 50]; | ||
return ( | ||
<div className="ProductsPerPage"> | ||
<label className="ProductsPerPageLabel">Products per page:</label> | ||
{options.map((pageSize) => ( | ||
<label key={pageSize} className="ProductsPerPageOption"> | ||
<input | ||
type="radio" | ||
name="page" | ||
value={pageSize} | ||
checked={state.pageSize === pageSize} | ||
onChange={() => controller.setPageSize(pageSize)} | ||
/> | ||
{pageSize} | ||
</label> | ||
))} | ||
<label key={0} className="ProductsPerPageOptionOther"> | ||
<input | ||
type="radio" | ||
name="page" | ||
value={state.pageSize} | ||
checked={state.pageSize === 0 || !options.includes(state.pageSize)} | ||
onChange={() => controller.setPageSize(0)} | ||
/> | ||
{state.pageSize !== 0 && !options.includes(state.pageSize) | ||
? `Other (${state.pageSize})` | ||
: 'Default'} | ||
</label> | ||
</div> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
...ct/src/components/use-cases/search-and-listing-interface/search-and-listing-interface.css
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