✨(react) make Pagination goto input optionnal
Based on a recent request we needed to make it optionnal in order to have simpler pagination in some cases. Closes #183
This commit is contained in:
5
.changeset/rude-scissors-peel.md
Normal file
5
.changeset/rude-scissors-peel.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@openfun/cunningham-react": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
make Pagination goto input optionnal
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
.c__pagination {
|
.c__pagination {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
|
height: 3.5rem;
|
||||||
|
|
||||||
&__list {
|
&__list {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ You can also set the page programmatically, for example, if you want to use a qu
|
|||||||
<Story id="components-pagination--force-page"/>
|
<Story id="components-pagination--force-page"/>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
|
|
||||||
|
|
||||||
|
### Hide go to input
|
||||||
|
|
||||||
|
You can also hide the go to input if you don't want to allow the user to go to a specific page or to have a simpler pagination.
|
||||||
|
|
||||||
|
<Canvas of={Stories.WithoutGoto}/>
|
||||||
|
|
||||||
### Things to know
|
### Things to know
|
||||||
|
|
||||||
- The pagination will never render if the number of pages is less than 2.
|
- The pagination will never render if the number of pages is less than 2.
|
||||||
|
|||||||
@@ -201,4 +201,20 @@ describe("<Pagination/>", () => {
|
|||||||
screen.getByRole("button", { name: "You are currently on page 1" }),
|
screen.getByRole("button", { name: "You are currently on page 1" }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it("can hide go to input", async () => {
|
||||||
|
const LocalWrapper = () => {
|
||||||
|
const pagination = usePagination({
|
||||||
|
defaultPage: 50,
|
||||||
|
defaultPagesCount: 100,
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<CunninghamProvider>
|
||||||
|
<Pagination {...pagination} displayGoto={false} />
|
||||||
|
</CunninghamProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<LocalWrapper />);
|
||||||
|
expect(document.querySelector(".c__pagination__goto")).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,3 +71,11 @@ export const ForcePage = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
return <Pagination {...pagination} />;
|
return <Pagination {...pagination} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const WithoutGoto = () => {
|
||||||
|
const pagination = usePagination({
|
||||||
|
defaultPagesCount: 100,
|
||||||
|
defaultPage: 50,
|
||||||
|
});
|
||||||
|
return <Pagination {...pagination} displayGoto={false} />;
|
||||||
|
};
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export interface PaginationProps {
|
|||||||
/** Total number of items per page */
|
/** Total number of items per page */
|
||||||
// eslint-disable-next-line react/no-unused-prop-types
|
// eslint-disable-next-line react/no-unused-prop-types
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
|
/** Display the goto input */
|
||||||
|
displayGoto?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usePagination = ({
|
export const usePagination = ({
|
||||||
@@ -43,6 +45,7 @@ export const Pagination = ({
|
|||||||
page,
|
page,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
pagesCount = 0,
|
pagesCount = 0,
|
||||||
|
displayGoto = true,
|
||||||
}: PaginationProps) => {
|
}: PaginationProps) => {
|
||||||
const { t } = useCunningham();
|
const { t } = useCunningham();
|
||||||
const [gotoValue, setGotoValue] = useState("");
|
const [gotoValue, setGotoValue] = useState("");
|
||||||
@@ -148,6 +151,7 @@ export const Pagination = ({
|
|||||||
size="small"
|
size="small"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{displayGoto && (
|
||||||
<div className="c__pagination__goto">
|
<div className="c__pagination__goto">
|
||||||
<form
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
@@ -169,6 +173,7 @@ export const Pagination = ({
|
|||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user