Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 2 additions & 167 deletions packages/react-table/src/docs/demos/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -2612,174 +2612,9 @@ class ComplexPaginationTableDemo extends React.Component {
}
```

### Pagination
### Static bottom pagination on mobile

```js
import React from 'react';
import {
Checkbox,
Pagination,
Title,
Toolbar,
ToolbarContent,
ToolbarItem,
EmptyState,
EmptyStateIcon,
EmptyStateBody,
EmptyStateVariant,
Bullseye
} from '@patternfly/react-core';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import globalDangerColor200 from '@patternfly/react-tokens/dist/esm/global_danger_color_200';
import { Table, TableHeader, TableBody } from '@patternfly/react-table';
import { Spinner } from '@patternfly/react-core';

class ComplexPaginationTableDemo extends React.Component {
constructor(props) {
super(props);
this.state = {
res: [],
perPage: 0,
total: 0,
page: 0,
error: null,
loading: true,
forceLoadingState: false
};

this.handleCheckboxChange = checked => {
console.log(checked);
this.setState({ forceLoadingState: checked });
};
}

fetch(page, perPage) {
this.setState({ loading: true });
fetch(`https://jsonplaceholder.typicode.com/posts?_page=${page}&_limit=${perPage}`)
.then(resp => resp.json())
.then(resp => this.setState({ res: resp, perPage, page, loading: false, total: 100 }))
.catch(err => this.setState({ error: err, loading: false, perPage: 0, page: 0, total: 0 }));
}

componentDidMount() {
this.fetch(this.state.page || 1, this.state.perPage || 20);
}

renderPagination(variant = 'top') {
const { page, perPage, total } = this.state;
return (
<Pagination
isCompact
itemCount={total}
page={page}
perPage={perPage}
onSetPage={(_evt, value) => this.fetch(value, perPage)}
onPerPageSelect={(_evt, value) => this.fetch(1, value)}
variant={variant}
titles={{
paginationTitle: `Pagination demo ${variant} pagination`
}}
/>
);
}

render() {
const { loading, res, error, forceLoadingState } = this.state;

const toolbarItems = (
<React.Fragment>
<ToolbarContent>
<ToolbarItem>
<Checkbox
label="View loading state"
isChecked={this.state.forceLoadingState}
onChange={this.handleCheckboxChange}
aria-label="view loading state checkbox"
id="check"
name="check"
/>
</ToolbarItem>
<ToolbarItem variant="pagination">{this.renderPagination()}</ToolbarItem>
</ToolbarContent>
</React.Fragment>
);

if (error) {
const noResultsRows = [
{
heightAuto: true,
cells: [
{
props: { colSpan: 8 },
title: (
<Bullseye>
<EmptyState variant={EmptyStateVariant.small}>
<EmptyStateIcon icon={ExclamationCircleIcon} color={globalDangerColor200.value} />
<Title headingLevel="h2" size="lg">
Check your connection and reload the page.
</Title>
<EmptyStateBody>
There was an error retrieving data. Check your connection and try again.
</EmptyStateBody>
</EmptyState>
</Bullseye>
)
}
]
}
];

return (
<React.Fragment>
<Table cells={['Title', 'Body']} rows={noResultsRows} aria-label="Pagination Table Demo">
<TableHeader />
<TableBody />
</Table>
</React.Fragment>
);
}

const loadingRows = [
{
heightAuto: true,
cells: [
{
props: { colSpan: 8 },
title: (
<Bullseye>
<center>
<Spinner size="xl" />
</center>
</Bullseye>
)
}
]
}
];

return (
<React.Fragment>
<Toolbar>{toolbarItems}</Toolbar>
{!(loading || forceLoadingState) && (
<Table
cells={['Title', 'Body']}
rows={res.map(post => [post.title, post.body])}
aria-label="Pagination Table Demo"
>
<TableHeader />
<TableBody />
</Table>
)}
{(loading || forceLoadingState) && (
<Table cells={['Title', 'Body']} rows={loadingRows} aria-label="Pagination Table Demo">
<TableHeader />
<TableBody />
</Table>
)}
</React.Fragment>
);
}
}
```js isFullscreen file="table-demos/StaticBottomPagination.jsx"
```

### Sticky header
Expand Down
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 perPageComponent="button" prop on <Pagination>, but our demos that reference <Pagination> are not using it.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding .pf-m-static to the top pagination, too. It isn't doing anything since it only styles .pf-c-pagination.pf-m-bottom but could be confusing as to why it's there.

https://github.com/patternfly/patternfly/blob/b6fdfb59baeeca10a5942c66c3ae208379a20a3f/src/patternfly/components/Pagination/pagination.scss#L139-L145

/>
);

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>
);
};