Skip to content

Commit 35b4322

Browse files
authored
Merge pull request #20 from fhlavac/actions-toggle
Add row actions example and actions prop to the toolbar
2 parents 8c14e4c + 6e5530b commit 35b4322

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
33
import { ExclamationCircleIcon } from '@patternfly/react-icons';
44
import { Button } from '@patternfly/react-core';
5+
import { ActionsColumn } from '@patternfly/react-table';
56

67
interface Repository {
78
id: number;
@@ -21,14 +22,33 @@ const repositories: Repository[] = [
2122
{ id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
2223
];
2324

25+
const rowActions = [
26+
{
27+
title: 'Some action',
28+
onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
29+
},
30+
{
31+
title: <div>Another action</div>,
32+
onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
33+
},
34+
{
35+
isSeparator: true
36+
},
37+
{
38+
title: 'Third action',
39+
onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
40+
}
41+
];
42+
2443
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
2544
const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
2645
{ id, cell: workspaces, props: { favorites: { isFavorited: true } } },
2746
{ cell: <Button href='#' variant='link' isInline>{name}</Button> },
2847
branches,
2948
prs,
3049
workspaces,
31-
lastCommit
50+
lastCommit,
51+
{ cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } },
3252
]);
3353

3454
const columns: DataViewTh[] = [
@@ -37,7 +57,7 @@ const columns: DataViewTh[] = [
3757
{ cell: <>Branches<ExclamationCircleIcon className='pf-v5-u-ml-sm' color='var(--pf-v5-global--danger-color--100)'/></> },
3858
'Pull requests',
3959
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
40-
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
60+
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } },
4161
];
4262

4363
const ouiaId = 'TableExample';

packages/module/src/DataViewToolbar/DataViewToolbar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ export interface DataViewToolbarProps extends PropsWithChildren {
1010
bulkSelect?: React.ReactNode;
1111
/** React component to display pagination */
1212
pagination?: React.ReactNode;
13+
/** React component to display actions */
14+
actions?: React.ReactNode;
1315
}
1416

15-
export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children, ...props }: DataViewToolbarProps) => (
17+
export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, actions = null, pagination, children, ...props }: DataViewToolbarProps) => (
1618
<Toolbar ouiaId={ouiaId} className={className} {...props}>
1719
<ToolbarContent>
1820
{bulkSelect && (
1921
<ToolbarItem data-ouia-component-id={`${ouiaId}-bulk-select`}>
2022
{bulkSelect}
2123
</ToolbarItem>
2224
)}
25+
{actions}
2326
{pagination && (
2427
<ToolbarItem variant={ToolbarItemVariant.pagination} data-ouia-component-id={`${ouiaId}-pagination`}>
2528
{pagination}

0 commit comments

Comments
 (0)