Skip to content

Commit b0d838d

Browse files
feat: Add plain variants for table and data list. (#12112)
* feat: Added isPlain for data list. * feat: Added isPlain for data list. * fix: Updated code to support isPlain for table. * Update packages/react-core/src/components/DataList/DataList.tsx Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> * Update packages/react-table/src/components/Table/Table.tsx Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> --------- Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
1 parent 20fb229 commit b0d838d

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

packages/react-core/src/components/DataList/DataList.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface DataListProps extends React.HTMLProps<HTMLUListElement> {
3131
selectedDataListItemId?: string;
3232
/** Flag indicating if DataList should have compact styling */
3333
isCompact?: boolean;
34+
/** @beta Flag indicating if DataList should have plain styling with a transparent background */
35+
isPlain?: boolean;
3436
/** Specifies the grid breakpoints */
3537
gridBreakpoint?: 'none' | 'always' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
3638
/** Determines which wrapping modifier to apply to the DataList */
@@ -59,6 +61,7 @@ export const DataListBase: React.FunctionComponent<DataListProps> = ({
5961
onSelectDataListItem,
6062
selectedDataListItemId = '',
6163
isCompact = false,
64+
isPlain = false,
6265
gridBreakpoint = 'md',
6366
wrapModifier = null,
6467
onSelectableRowChange,
@@ -84,6 +87,7 @@ export const DataListBase: React.FunctionComponent<DataListProps> = ({
8487
className={css(
8588
styles.dataList,
8689
isCompact && styles.modifiers.compact,
90+
isPlain && styles.modifiers.plain,
8791
gridBreakpointClasses[gridBreakpoint],
8892
wrapModifier && styles.modifiers[wrapModifier],
8993
className

packages/react-core/src/components/DataList/examples/DataList.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ import { DragDropSort, DragDropContainer, Droppable as NewDroppable } from '@pat
3838

3939
```ts file="./DataListCompact.tsx"
4040

41+
```
42+
### Plain
43+
44+
```ts file="./DataListPlain.tsx"
45+
4146
```
4247

4348
### Checkboxes, actions and additional cells
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core';
2+
3+
export const DataListPlain: React.FunctionComponent = () => (
4+
<DataList aria-label="Plain data list example" isPlain>
5+
<DataListItem aria-labelledby="plain-item1">
6+
<DataListItemRow>
7+
<DataListItemCells
8+
dataListCells={[
9+
<DataListCell key="primary content">
10+
<span id="plain-item1">Primary content</span>
11+
</DataListCell>,
12+
<DataListCell key="secondary content">Secondary content</DataListCell>
13+
]}
14+
/>
15+
</DataListItemRow>
16+
</DataListItem>
17+
<DataListItem aria-labelledby="plain-item2">
18+
<DataListItemRow>
19+
<DataListItemCells
20+
dataListCells={[
21+
<DataListCell isFilled={false} key="secondary content fill">
22+
<span id="plain-item2">Secondary content (pf-m-no-fill)</span>
23+
</DataListCell>,
24+
<DataListCell isFilled={false} alignRight key="secondary content align">
25+
Secondary content (pf-m-align-right pf-m-no-fill)
26+
</DataListCell>
27+
]}
28+
/>
29+
</DataListItemRow>
30+
</DataListItem>
31+
</DataList>
32+
);

packages/react-table/src/components/Table/Table.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface TableProps extends React.HTMLProps<HTMLTableElement>, OUIAProps
4848
gridBreakPoint?: '' | 'grid' | 'grid-md' | 'grid-lg' | 'grid-xl' | 'grid-2xl';
4949
/** A valid WAI-ARIA role to be applied to the table element */
5050
role?: string;
51+
/** @beta Flag indicating if the table should have plain styling with a transparent background */
52+
isPlain?: boolean;
5153
/** If set to true, the table header sticks to the top of its container */
5254
isStickyHeader?: boolean;
5355
/** @hide Forwarded ref */
@@ -94,6 +96,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
9496
variant,
9597
borders = true,
9698
isStickyHeader = false,
99+
isPlain = false,
97100
gridBreakPoint = TableGridBreakpoint.gridMd,
98101
'aria-label': ariaLabel,
99102
role = 'grid',
@@ -222,6 +225,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
222225
isTreeTable && stylesTreeView.modifiers.treeView,
223226
isStriped && styles.modifiers.striped,
224227
isExpandable && styles.modifiers.expandable,
228+
isPlain && styles.modifiers.plain,
225229
hasNoInset && stylesTreeView.modifiers.noInset,
226230
isNested && 'pf-m-nested',
227231
hasAnimations && styles.modifiers.animateExpand

packages/react-table/src/components/Table/examples/Table.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ Some general notes:
7878
```ts file="TableBasic.tsx"
7979

8080
```
81+
### Table Plain
82+
``` file="TablePlain.tsx"
8183
84+
```
8285
### Custom row wrapper, header tooltips & popovers
8386

8487
- If you add the `noWrap` prop to `Thead`, it won't wrap it if there is no space
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Table, Caption, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
2+
3+
interface Repository {
4+
name: string;
5+
branches: string | null;
6+
prs: string | null;
7+
workspaces: string;
8+
lastCommit: string;
9+
}
10+
11+
export const TablePlain: React.FunctionComponent = () => {
12+
// In real usage, this data would come from some external source like an API via props.
13+
const repositories: Repository[] = [
14+
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
15+
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
16+
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' }
17+
];
18+
19+
const columnNames = {
20+
name: 'Repositories',
21+
branches: 'Branches',
22+
prs: 'Pull requests',
23+
workspaces: 'Workspaces',
24+
lastCommit: 'Last commit'
25+
};
26+
27+
return (
28+
<Table aria-label="Plain table" isPlain={true}>
29+
<Caption>Simple table with plain styling using composable components</Caption>
30+
<Thead>
31+
<Tr>
32+
<Th>{columnNames.name}</Th>
33+
<Th>{columnNames.branches}</Th>
34+
<Th>{columnNames.prs}</Th>
35+
<Th>{columnNames.workspaces}</Th>
36+
<Th>{columnNames.lastCommit}</Th>
37+
</Tr>
38+
</Thead>
39+
<Tbody>
40+
{repositories.map((repo) => (
41+
<Tr key={repo.name}>
42+
<Td dataLabel={columnNames.name}>{repo.name}</Td>
43+
<Td dataLabel={columnNames.branches}>{repo.branches}</Td>
44+
<Td dataLabel={columnNames.prs}>{repo.prs}</Td>
45+
<Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td>
46+
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
47+
</Tr>
48+
))}
49+
</Tbody>
50+
</Table>
51+
);
52+
};

0 commit comments

Comments
 (0)