Skip to content
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

chore(Table) convert demos to ts #9621

Merged
merged 15 commits into from
Nov 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ToolbarToggleGroup extends React.Component<ToolbarToggleGroupProps> {
aria-label="Show Filters"
{...(_isExpanded && { 'aria-expanded': true })}
aria-haspopup={_isExpanded && this.isContentPopup()}
aria-controls={expandableContentId}
aria-controls={_isExpanded ? expandableContentId : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

As an FYI, Jenny and I discussed this and I opened #9827 as an investigation as to whether this should be a temporary fix or not

ref={this.toggleRef}
>
{toggleIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ exports[`Toolbar should render with custom chip content 1`] = `
class="pf-v5-c-toolbar__toggle"
>
<button
aria-controls="toolbar-with-filter-expandable-content-3"
aria-disabled="false"
aria-haspopup="false"
aria-label="Show Filters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Td,
InnerScrollContainer,
OuterScrollContainer,
ThProps
ThProps,
ISortBy
} from '@patternfly/react-table';
import BlueprintIcon from '@patternfly/react-icons/dist/esm/icons/blueprint-icon';

Expand Down Expand Up @@ -53,10 +54,10 @@ export const TableStickyColumnsAndHeader: React.FunctionComponent = () => {
// Index of the currently sorted column
// Note: if you intend to make columns reorderable, you may instead want to use a non-numeric key
// as the identifier of the sorted column. See the "Compound expandable" example.
const [activeSortIndex, setActiveSortIndex] = React.useState<number | null>(null);
const [activeSortIndex, setActiveSortIndex] = React.useState(-1);

// Sort direction of the currently sorted column
const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | null>(null);
const [activeSortDirection, setActiveSortDirection] = React.useState<ISortBy['direction']>();

// Since OnSort specifies sorted columns by index, we need sortable values for our object by column index.
// This example is trivial since our data objects just contain strings, but if the data was more complex
Expand All @@ -69,7 +70,7 @@ export const TableStickyColumnsAndHeader: React.FunctionComponent = () => {
// Note that we perform the sort as part of the component's render logic and not in onSort.
// We shouldn't store the list of data in state because we don't want to have to sync that with props.
let sortedFacts = facts;
if (activeSortIndex !== null) {
if (activeSortIndex > -1) {
sortedFacts = facts.sort((a, b) => {
const aValue = getSortableRowValues(a)[activeSortIndex];
const bValue = getSortableRowValues(b)[activeSortIndex];
Expand Down
159 changes: 159 additions & 0 deletions packages/react-table/src/demos/Table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
id: Table
section: components
---

import {
Checkbox,
Label,
PageSection,
ToolbarExpandIconWrapper,
ToolbarContent,
Toolbar,
ToolbarItem,
SearchInput,
Masthead,
MastheadToggle,
MastheadMain,
MastheadContent,
SkipToContent,
Breadcrumb,
BreadcrumbItem,
Page,
PageSectionVariants,
TextContent,
Text,
Divider } from '@patternfly/react-core';
import { Table as TableDeprecated, TableHeader, TableBody } from '@patternfly/react-table/deprecated';
import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
import CloneIcon from '@patternfly/react-icons/dist/esm/icons/clone-icon';
import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
import EditIcon from '@patternfly/react-icons/dist/esm/icons/edit-icon';
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
import SortAmountDownIcon from '@patternfly/react-icons/dist/esm/icons/sort-amount-down-icon';
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
import SyncIcon from '@patternfly/react-icons/dist/esm/icons/sync-icon';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
import QuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/question-circle-icon';
import globalDangerColor200 from '@patternfly/react-tokens/dist/esm/global_danger_color_200';
import imgBrand from '@patternfly/react-core/src/components/assets/pfLogo.svg';
import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg';
import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon';
import AttentionBellIcon from '@patternfly/react-icons/dist/esm/icons/attention-bell-icon';
import BlueprintIcon from '@patternfly/react-icons/dist/esm/icons/blueprint-icon';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
import { DashboardWrapper } from '@patternfly/react-core/dist/esm/demos/DashboardWrapper';
import { rows, columns } from '@patternfly/react-table/dist/esm/demos/sampleData';
import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing';

## Demos

### Bulk select

```js isFullscreen file="./examples/TableBulkSelect.tsx"
```

### Expand/collapse all

```js isFullscreen file="./examples/TableExpandCollapseAll.tsx"

```

### Compact

```js isFullscreen file="./examples/TableCompact.tsx"

```

### Compound expansion

```js isFullscreen file="./examples/TableCompoundExpansion.tsx"

```

### Column management

```js isFullscreen file="./examples/TableColumnManagement.tsx"

```

### Column management with draggable

```js isFullscreen file="./examples/TableColumnManagementWithDraggable.tsx"
```

### Filterable

```js isFullscreen file="./examples/TableFilterable.tsx"
```

### Sortable - responsive

```js isFullscreen file="./examples/TableSortableResponsive.tsx"

```

### Automatic pagination

The below example illustrates the `isLastFullPageShown` prop, which makes the following changes when the user sets the number of items to display per page to an amount that exceeds the remaining amount of data:

- The component automatically changes the page back to the last full page of results, rather than defaulting to the final page of results.

To demonstrate this, navigate to the last page of data below using the `>>` navigation arrows, then use the dropdown selector to change the view to 5 per page.

- The default behavior would show the last page of results, which would only contain the last two rows (rows 11 - 12).
- The `isLastFullPageShown` prop navigates you back to the previous page which does contain a full page of 5 rows (rows 6 - 10).

```js isFullscreen file="./examples/TableAutomaticPagination.tsx"
```

### Static bottom pagination on mobile

```ts isFullscreen file="./examples/TableStaticBottomPagination.tsx"

```

### Sticky header

```js isFullscreen file="./examples/TableStickyHeader.tsx"

```

### Sticky first column

```js isFullscreen file="./examples/TableStickyFirstColumn.tsx"

```

### Sticky columns and header with toolbar

A toolbar may be added above a sticky table either inside or outside the `OuterScrollContainer`.

```js isFullscreen file="../components/Table/examples/TableStickyColumnsAndHeader.tsx"

```

## Empty states

These examples demonstrate the use of an [Empty State component](/components/empty-state) inside of a [Table](/components/table). Empty states are useful in a table when a filter returns no results, while data is loading, or when any type of error or exception condition occurs.

### Empty

```js isFullscreen file="./examples/TableEmptyStateDefault.tsx"
```

### Loading

```js isFullscreen file="./examples/TableEmptyStateLoading.tsx"
```

### Error

```js isFullscreen file="./examples/TableEmptyStateError.tsx"
```
101 changes: 101 additions & 0 deletions packages/react-table/src/demos/examples/TableAutomaticPagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from 'react';
import { Pagination } from '@patternfly/react-core';
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';

export const TableAutomaticPagination: React.FunctionComponent = () => {
const columns = {
firstColumn: 'First column',
secondColumn: 'Second column',
thirdColumn: 'Third column'
};

const defaultRows = [
{ firstColumn: 'Row 1 column 1', secondColumn: 'Row 1 column 2', thirdColumn: 'Row 1 column 3' },
{ firstColumn: 'Row 2 column 1', secondColumn: 'Row 2 column 2', thirdColumn: 'Row 2 column 3' },
{ firstColumn: 'Row 3 column 1', secondColumn: 'Row 3 column 2', thirdColumn: 'Row 3 column 3' },
{ firstColumn: 'Row 4 column 1', secondColumn: 'Row 4 column 2', thirdColumn: 'Row 4 column 3' },
{ firstColumn: 'Row 5 column 1', secondColumn: 'Row 5 column 2', thirdColumn: 'Row 5 column 3' },
{ firstColumn: 'Row 6 column 1', secondColumn: 'Row 6 column 2', thirdColumn: 'Row 6 column 3' },
{ firstColumn: 'Row 7 column 1', secondColumn: 'Row 7 column 2', thirdColumn: 'Row 7 column 3' },
{ firstColumn: 'Row 8 column 1', secondColumn: 'Row 8 column 2', thirdColumn: 'Row 8 column 3' },
{ firstColumn: 'Row 9 column 1', secondColumn: 'Row 9 column 2', thirdColumn: 'Row 9 column 3' },
{ firstColumn: 'Row 10 column 1', secondColumn: 'Row 10 column 2', thirdColumn: 'Row 10 column 3' },
{ firstColumn: 'Row 11 column 1', secondColumn: 'Row 11 column 2', thirdColumn: 'Row 11 column 3' },
{ firstColumn: 'Row 12 column 1', secondColumn: 'Row 12 column 2', thirdColumn: 'Row 12 column 3' }
];
const defaultPerPage = 10;

const [perPage, setPerPage] = React.useState(defaultPerPage);
const [page, setPage] = React.useState(1);
const [rows, setRows] = React.useState(defaultRows.slice(0, defaultPerPage));

const handleSetPage = (
_evt: React.MouseEvent | React.KeyboardEvent | MouseEvent,
newPage: number,
_perPage: number,
startIdx: number,
endIdx: number
) => {
setPage(newPage);
setRows(defaultRows.slice(startIdx, endIdx));
};

const handlePerPageSelect = (
_evt: React.MouseEvent | React.KeyboardEvent | MouseEvent,
newPerPage: number,
newPage: number,
startIdx: number,
endIdx: number
) => {
setPerPage(newPerPage);
setPage(newPage);
setRows(defaultRows.slice(startIdx, endIdx));
};

const renderPagination = (variant = 'top') => (
<Pagination
isCompact
itemCount={defaultRows.length}
page={page}
perPage={perPage}
isLastFullPageShown
onSetPage={handleSetPage}
onPerPageSelect={handlePerPageSelect}
perPageOptions={[
{ title: '3', value: 3 },
{ title: '5', value: 5 },
{ title: '12', value: 12 },
{ title: '20', value: 20 }
]}
titles={{
paginationAriaLabel: `${variant} pagination`
}}
/>
);

return (
<React.Fragment>
{renderPagination()}
<Table aria-label="Automated Pagination Table Demo">
<Thead>
<Tr>
<Th>{columns.firstColumn}</Th>
<Th>{columns.secondColumn}</Th>
<Th>{columns.thirdColumn}</Th>
</Tr>
</Thead>
<Tbody>
{rows.map((row, rowIndex) => (
<Tr key={rowIndex}>
<>
<Td dataLabel={columns.firstColumn}>{row.firstColumn}</Td>
<Td dataLabel={columns.secondColumn}>{row.secondColumn}</Td>
<Td dataLabel={columns.thirdColumn}>{row.thirdColumn}</Td>
</>
</Tr>
))}
</Tbody>
</Table>
</React.Fragment>
);
};
Loading
Loading