Pagination Search
ReadyA pagination component with additional search sorting functionality.
Preview
Code
Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdPaginationSearch } from '@fbin-web/neighborhood-core';
Usage
<nbhd-pagination-search
selected-sort="relevance"
heading="Search Results for"
search-term="faucet"
current-page="1"
total-pages="10"
total-results="75"
max-visible-pages="3"
surface="secondary">
</nbhd-pagination-search>
<script>
const paginationSearch = document.querySelector('nbhd-pagination-search');
paginationSearch.sortOptions = [
{ name: 'Relevance', value: 'relevance' },
{ name: 'Price: Low to High', value: 'price-asc' },
{ name: 'Price: High to Low', value: 'price-desc' },
{ name: 'Newest', value: 'newest' },
];
</script>
Install
npm install @fbin-web/neighborhood-react
Import
import { NbhdPaginationSearch } from '@fbin-web/neighborhood-react';
Usage
import { NbhdPaginationSearch } from '@fbin-web/neighborhood-react';
const sortOptions = [
{ name: 'Relevance', value: 'relevance' },
{ name: 'Price: Low to High', value: 'price-asc' },
{ name: 'Price: High to Low', value: 'price-desc' },
{ name: 'Newest', value: 'newest' },
];
const App = () => (
<>
<NbhdPaginationSearch
selectedSort="relevance"
heading="Search Results for"
searchTerm="faucet"
currentPage={1}
totalPages={10}
totalResults={75}
maxVisiblePages={3}
sortOptions={sortOptions}
surface="secondary"></NbhdPaginationSearch>
</>
);
Usage
- Pagination Search extends the Pagination component by adding search and sorting functionality.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
surface | surface | noneprimarysecondaryinverseinverse-secondary | primary | Surface to apply to the component. |
marginTop | margin-top | nonesmallmediumlarge | none | Top margin spacing. |
marginBottom | margin-bottom | nonesmallmediumlarge | none | Bottom margin spacing. |
paddingTop | padding-top | defaultnonesmallmediumlarge | default | Top padding spacing. |
paddingBottom | padding-bottom | defaultnonesmallmediumlarge | default | Bottom padding spacing. |
maxVisiblePages | max-visible-pages | number | 3 | The maximum number of page buttons to display at once. |
showLabels | show-labels | boolean | false | Whether to show labels on the pagination arrows. |
currentPage | current-page | number | 1 | The current active page. |
totalPages | total-pages | number | 1 | The total number of pages. |
nextLabel | next-label | string | Next | The label for the next page arrow button. |
previousLabel | previous-label | string | Previous | The label for the previous page arrow button. |
label | label | string | Pagination | Accessible name of the pagination navigation landmark. |
onNbhdPageChanged | on-nbhd-page-changed | (event: CustomEvent<{ page: number }>) => void | — | Callback function when page changes. |
heading | heading | string | Search Results for | Text displayed before the search term in the results summary. |
headingLevel | heading-level | 123456 | 2 | Level of the results summary heading ("Search Results for “term” [N]"). Match it to the page outline. |
resultsAnnouncement | results-announcement | string | {count} results | Announced to screen readers when the result count or search term changes (not on first load). `{count}` is replaced with `total-results`. |
searchTerm | search-term | string | — | The current search term to display alongside the results summary. |
totalResults | total-results | number | 0 | The total number of search results. |
selectedSort | selected-sort | string | relevance | The currently selected sort option. |
sortLabel | sort-label | string | Sort By: | The label shown before the sort select dropdown. |
onNbhdSortChanged | on-nbhd-sort-changed | (event: CustomEvent<{ value: string }>) => void | — | Callback function when the sort option changes. |
sortOptions | — | SelectOptionContent[] | [] | An array of sort options for the select dropdown. |
No properties match.
Select Option Content Structure
Each item in sortOptions must match the SelectOptionContent shape used by the shared select component.
| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display label shown for the sort option in the dropdown. |
value | string | Yes | Value assigned to the option and used when the selection changes. |
Events
| Name | Description | Event Detail |
|---|---|---|
nbhd-page-changed | Emitted when the user navigates to a different page. | { page: number } |
nbhd-sort-changed | Emitted when the sort option changes. | { value: string } |
CSS Parts
Parts exposed for styling the pagination-search component.
| Name | Description |
|---|---|
base | The component's outer wrapper. |
container | The internal container that wraps the search summary and controls. |
wrapper | The content wrapper containing the summary, pagination, and sort controls. |
summary | The results summary row showing the heading, term, and result count. |
summary-heading | The heading text before the search term. |
summary-term | The active search term shown in the summary. |
summary-results | The results count displayed in the summary. |
pagination | The pagination section wrapper. |
nav | The |
controls | The
|
page-button | Each page number button in the pagination set. |
previous-button | The Previous button. Stays rendered on the first page with aria-disabled="true". |
next-button | The Next button. Stays rendered on the last page with aria-disabled="true". |
previous-label | The label text for the previous button when labels are visible. |
next-label | The label text for the next button when labels are visible. |
ellipsis | The ellipsis indicators between pagination groups. |
pagination-item-svg | The SVG icon rendered inside the previous and next buttons. |
sort | The sort row wrapper containing the dropdown and label. |
sort-label | The label text before the sort select control. |
sort-select | The select control used for sorting options. |
No css parts match.
nbhd-pagination-search::part(base) {
/* your styles */
}
CSS Properties
Set these on nbhd-pagination-search or an ancestor to override the defaults. Token is the design token a default comes from and Value is what it resolves to in core Neighborhood; brands may override them. Properties that adapt to surface follow the light or inverse surface they sit on until you set them.
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-paginationSearch-inlineSize | — | 100% |
|
--nbhd-paginationSearch-minInlineSize | --nbhd-size-container-min | 320px |
|
--nbhd-paginationSearch-paddingBlock | --nbhd-space-5 | 20px |
|
--nbhd-paginationSearch-position | — | relative |
|
--nbhd-paginationSearch-sort-alignItems | — | center |
|
--nbhd-paginationSearch-sort-display | — | flex |
|
--nbhd-paginationSearch-sort-gap | --nbhd-space-2 | 8px |
|
--nbhd-paginationSearch-sort-justifyContent | — | center |
|
--nbhd-paginationSearch-sort-select-inlineSize | — | 165px |
|
--nbhd-paginationSearch-sort-text-display | — | inline |
|
--nbhd-paginationSearch-sort-text-hostDisplay | — | inline-block |
|
--nbhd-paginationSearch-summary-alignItems | — | center |
|
--nbhd-paginationSearch-summary-display | — | flex |
|
--nbhd-paginationSearch-summary-gap | --nbhd-space-1 | 4px |
|
--nbhd-paginationSearch-summary-justifyContent | — | center |
|
--nbhd-paginationSearch-summary-maxInlineSize | — | content |
|
--nbhd-paginationSearch-summary-text-display | — | inline |
|
--nbhd-paginationSearch-summary-text-hostDisplay | — | inline-block |
|
--nbhd-paginationSearch-wrapper-alignItems | — | center |
|
--nbhd-paginationSearch-wrapper-bpMd-flexDirection | — | row |
|
--nbhd-paginationSearch-wrapper-display | — | flex |
|
--nbhd-paginationSearch-wrapper-flexDirection | — | column |
|
--nbhd-paginationSearch-wrapper-flexWrap | — | wrap |
|
--nbhd-paginationSearch-wrapper-gap | --nbhd-space-5 | 20px |
|
--nbhd-paginationSearch-wrapper-inlineSize | — | 100% |
|
--nbhd-paginationSearch-wrapper-justifyContent | — | space-between |
|
--nbhd-paginationSearch-zIndex | --nbhd-z-1 | 1 |
No pagination search match.
Dependencies
Child components <nbhd-pagination-search> renders internally. Import them too when you tree-shake.