-
Notifications
You must be signed in to change notification settings - Fork 377
docs(Table): update pagination demo to match core #7896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Button, | ||
| Card, | ||
| Toolbar, | ||
| ToolbarContent, | ||
| ToolbarGroup, | ||
| ToolbarItem, | ||
| Pagination, | ||
| Select, | ||
| SelectVariant, | ||
| SelectOption, | ||
| PageSection, | ||
| Label | ||
| } from '@patternfly/react-core'; | ||
| import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; | ||
| import { rows, columns } from '../../examples/Data.jsx'; | ||
|
|
||
| import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon'; | ||
| import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper'; | ||
|
|
||
| export const StaticBottomPagination = () => { | ||
| const [isSelectOpen, setIsSelectOpen] = React.useState(false); | ||
| const [page, setPage] = React.useState(1); | ||
| const [perPage, setPerPage] = React.useState(10); | ||
| const [paginatedRows, setPaginatedRows] = React.useState(rows.slice(0, 10)); | ||
| const handleSetPage = (_evt, newPage, perPage, startIdx, endIdx) => { | ||
| setPaginatedRows(rows.slice(startIdx, endIdx)); | ||
| setPage(newPage); | ||
| }; | ||
| handlePerPageSelect = (_evt, newPerPage, newPage, startIdx, endIdx) => { | ||
| setPaginatedRows(rows.slice(startIdx, endIdx)); | ||
| setPage(newPage); | ||
| setPerPage(newPerPage); | ||
| }; | ||
|
|
||
|
|
||
| const renderPagination = (variant, isCompact) => ( | ||
| <Pagination | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be out of scope but I noticed a spacing difference between core and react, and looks like it's due to a difference in the toggle between the core and react demos. We recently made an update to the plain text options menu (what's used in pagination) that makes the entire toggle clickable versus just the toggle icon. @thatblindgeye added that in #7192 as a I dunno if it makes sense to add that to this demo and have a separate issue to add it to the other demos - or handle it some other way, but wanted to mention it. |
||
| isCompact={isCompact} | ||
| itemCount={rows.length} | ||
| page={page} | ||
| perPage={perPage} | ||
| onSetPage={handleSetPage} | ||
| onPerPageSelect={handlePerPageSelect} | ||
| variant={variant} | ||
| titles={{ | ||
| paginationTitle: `${variant} pagination` | ||
| }} | ||
| isStatic | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is adding |
||
| /> | ||
| ); | ||
|
|
||
| const renderLabel = labelText => { | ||
| switch (labelText) { | ||
| case 'Running': | ||
| return <span><Label color="green">{labelText}</Label></span>; | ||
| case 'Stopped': | ||
| return <span><Label color="orange">{labelText}</Label></span>; | ||
| case 'Needs Maintenance': | ||
| return <span><Label color="blue">{labelText}</Label></span>; | ||
| case 'Down': | ||
| return <span><Label color="red">{labelText}</Label></span>; | ||
| } | ||
| }; | ||
|
|
||
| const tableToolbar = ( | ||
| <Toolbar usePageInsets id="pagination-toolbar"> | ||
| <ToolbarContent> | ||
| <ToolbarItem> | ||
| <Select | ||
| id="select-example" | ||
| variant={SelectVariant.single} | ||
| aria-label="Select Input" | ||
| placeholderText={ | ||
| <> | ||
| <FilterIcon /> Status | ||
| </> | ||
| } | ||
| isOpen={isSelectOpen} | ||
| onToggle={() => setIsSelectOpen(!isSelectOpen)} | ||
| onSelect={() => setIsSelectOpen(!isSelectOpen)} | ||
| > | ||
| {[ | ||
| <SelectOption key={0} value="Debug" />, | ||
| <SelectOption key={1} value="Info" />, | ||
| <SelectOption key={2} value="Warn" />, | ||
| <SelectOption key={3} value="Error" /> | ||
| ]} | ||
| </Select> | ||
| </ToolbarItem> | ||
| <ToolbarGroup> | ||
| <ToolbarItem> | ||
| <Button variant="primary">Action</Button> | ||
| </ToolbarItem> | ||
| </ToolbarGroup> | ||
| <ToolbarItem variant="pagination">{renderPagination('top', true)}</ToolbarItem> | ||
| </ToolbarContent> | ||
| </Toolbar> | ||
| ); | ||
|
|
||
| return ( | ||
| <React.Fragment> | ||
| <DashboardWrapper hasPageTemplateTitle> | ||
| <PageSection isFilled> | ||
| <Card> | ||
| {tableToolbar} | ||
| <TableComposable variant="compact" aria-label="Paginated Table"> | ||
| <Thead> | ||
| <Tr> | ||
| {columns.map((column, columnIndex) => ( | ||
| <Th key={columnIndex}>{column}</Th> | ||
| ))} | ||
| </Tr> | ||
| </Thead> | ||
| <Tbody> | ||
| {paginatedRows.map((row, rowIndex) => ( | ||
| <Tr key={rowIndex}> | ||
| <Td dataLabel={columns[0]}>{row.name}</Td> | ||
| <Td dataLabel={columns[1]}>{row.threads}</Td> | ||
| <Td dataLabel={columns[2]}>{row.applications}</Td> | ||
| <Td dataLabel={columns[3]}>{row.workspaces}</Td> | ||
| <Td dataLabel={columns[4]}>{renderLabel(row.status)}</Td> | ||
| <Td dataLabel={columns[5]}>{row.location}</Td> | ||
| <Td dataLabel={columns[6]}>{row.lastModified}</Td> | ||
| <Td dataLabel={columns[7]} modifier="truncate"> | ||
| <TableText> | ||
| <a href="#">{row.url}</a> | ||
| </TableText> | ||
| </Td> | ||
| </Tr> | ||
| ))} | ||
| </Tbody> | ||
| </TableComposable> | ||
| {renderPagination('bottom', false)} | ||
| </Card> | ||
| </PageSection> | ||
| </DashboardWrapper> | ||
| </React.Fragment> | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.