-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9607 from marmelab/fix-pagination-rowsperpage-type
[TypeScript] Fix `<Pagination rowsPerPageOptions>` doesn't accept an array of objects
- Loading branch information
Showing
4 changed files
with
118 additions
and
2 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
98 changes: 98 additions & 0 deletions
98
packages/ra-ui-materialui/src/list/pagination/Pagination.stories.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,98 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import { ListPaginationContext, I18nContextProvider } from 'ra-core'; | ||
import { defaultI18nProvider } from 'react-admin'; | ||
|
||
import { Pagination } from './Pagination'; | ||
|
||
export default { | ||
title: 'ra-ui-materialui/list/Pagination', | ||
}; | ||
|
||
const theme = createTheme(); | ||
|
||
const defaultProps = { | ||
resource: 'posts', | ||
page: 1, | ||
perPage: 10, | ||
setPage: () => null, | ||
isLoading: false, | ||
hasNextPage: undefined, | ||
hasPreviousPage: undefined, | ||
}; | ||
|
||
const Wrapper = ({ children, listContext }) => ( | ||
<I18nContextProvider value={defaultI18nProvider}> | ||
<ThemeProvider theme={theme}> | ||
<ListPaginationContext.Provider value={listContext}> | ||
{children} | ||
</ListPaginationContext.Provider> | ||
</ThemeProvider> | ||
</I18nContextProvider> | ||
); | ||
|
||
export const Basic = () => { | ||
const [page, setPage] = React.useState(1); | ||
return ( | ||
<Wrapper | ||
listContext={{ | ||
...defaultProps, | ||
setPage, | ||
perPage: 10, | ||
total: 43, | ||
page, | ||
}} | ||
> | ||
<Pagination rowsPerPageOptions={[1]} /> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export const Loading = () => ( | ||
<Wrapper listContext={{ ...defaultProps, isLoading: true }}> | ||
<Pagination rowsPerPageOptions={[1]} /> | ||
</Wrapper> | ||
); | ||
|
||
export const OnePage = () => ( | ||
<Wrapper | ||
listContext={{ | ||
...defaultProps, | ||
perPage: 10, | ||
total: 7, | ||
page: 1, | ||
}} | ||
> | ||
<Pagination rowsPerPageOptions={[1]} /> | ||
</Wrapper> | ||
); | ||
|
||
export const RowsPerPageOptions = () => { | ||
const [page, setPage] = React.useState(1); | ||
const [perPage, setPerPage] = React.useState(10); | ||
return ( | ||
<Wrapper | ||
listContext={{ | ||
...defaultProps, | ||
setPage, | ||
setPerPage, | ||
perPage, | ||
total: 73, | ||
page, | ||
}} | ||
> | ||
<h2>Default</h2> | ||
<Pagination /> | ||
<h2>Custom</h2> | ||
<Pagination rowsPerPageOptions={[10, 20, 100]} /> | ||
<h2>With Labels</h2> | ||
<Pagination | ||
rowsPerPageOptions={[ | ||
{ label: 'ten', value: 10 }, | ||
{ label: 'twenty', value: 20 }, | ||
{ label: 'one hundred', value: 100 }, | ||
]} | ||
/> | ||
</Wrapper> | ||
); | ||
}; |
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