generated from ConductionNL/product-website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
133 additions
and
8 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
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
12 changes: 12 additions & 0 deletions
12
pwa/src/components/paginationLimitSelect/PaginationLimitSelect.module.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 8px; | ||
align-items: center; | ||
list-style-type: none; | ||
|
||
padding: 0; | ||
margin: 0; | ||
|
||
user-select: none; | ||
} |
72 changes: 72 additions & 0 deletions
72
pwa/src/components/paginationLimitSelect/PaginationLimitSelect.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,72 @@ | ||
import * as React from "react"; | ||
import * as styles from "./PaginationLimitSelect.module.css"; | ||
import clsx from "clsx"; | ||
import { useForm } from "react-hook-form"; | ||
import { SelectSingle } from "@conduction/components"; | ||
import { IQueryLimitContext, queryLimitDefault, useQueryLimitContext } from "../../context/queryLimit"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
interface PaginationLimitSelectProps { | ||
queryLimitName: string; | ||
layoutClassName?: string; | ||
} | ||
|
||
export const PaginationLimitSelectComponent: React.FC<PaginationLimitSelectProps> = ({ | ||
queryLimitName, | ||
layoutClassName, | ||
}) => { | ||
const { | ||
watch, | ||
register, | ||
control, | ||
setValue, | ||
formState: { errors }, | ||
} = useForm(); | ||
const { queryLimit, setQueryLimit } = useQueryLimitContext(); | ||
const { t } = useTranslation(); | ||
|
||
const watchLimit = watch("limit"); | ||
|
||
const value = queryLimit[queryLimitName as keyof IQueryLimitContext]; | ||
|
||
React.useEffect(() => { | ||
if (!watchLimit) return; | ||
if (parseInt(watchLimit.value) === value) return; | ||
|
||
const selectedLimit = limitSelectOptions.find((LimitOption) => LimitOption.value === watchLimit.value); | ||
|
||
selectedLimit !== undefined && setQueryLimit({ ...queryLimit, [queryLimitName]: parseInt(selectedLimit.value) }); | ||
}, [watchLimit]); | ||
|
||
React.useEffect(() => { | ||
setValue( | ||
"limit", | ||
limitSelectOptions.find((LimitOption) => LimitOption.value === (value !== undefined && value.toString())), | ||
); | ||
}, []); | ||
|
||
return ( | ||
<div className={clsx(styles.container, layoutClassName && layoutClassName)}> | ||
<span>{`${t("Results per page")}:`}</span> | ||
<SelectSingle | ||
ariaLabel={t("Select result limit")} | ||
{...{ register, errors, control }} | ||
defaultValue={queryLimitDefault} | ||
name="limit" | ||
options={limitSelectOptions} | ||
menuPlacement="auto" | ||
placeholder={t("Limit")} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
const limitSelectOptions = [ | ||
{ label: "6", value: "6" }, | ||
{ label: "9", value: "9" }, | ||
{ label: "12", value: "12" }, | ||
{ label: "21", value: "21" }, | ||
{ label: "30", value: "30" }, | ||
{ label: "60", value: "60" }, | ||
{ label: "120", value: "120" }, | ||
]; |
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,24 @@ | ||
import * as React from "react"; | ||
import { GlobalContext } from "./global"; | ||
|
||
export const queryLimitDefault = 12; | ||
|
||
export interface IQueryLimitContext { | ||
objectsQueryLimit: number; | ||
} | ||
|
||
export const defaultQueryLimitContext: IQueryLimitContext = { | ||
objectsQueryLimit: queryLimitDefault, | ||
}; | ||
|
||
export const useQueryLimitContext = () => { | ||
const [globalContext, setGlobalContext] = React.useContext(GlobalContext); | ||
|
||
const queryLimit: IQueryLimitContext = globalContext.queryLimit; | ||
|
||
const setQueryLimit = (query: IQueryLimitContext) => { | ||
setGlobalContext((context) => ({ ...context, queryLimit: { ...globalContext.queryLimit, ...query } })); | ||
}; | ||
|
||
return { setQueryLimit, queryLimit }; | ||
}; |
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