Skip to content

Commit cc4ff32

Browse files
authored
Merge pull request #207 from puppetlabs/pds-378-add-truncate-table-content-option
Allow cell content to be truncated with ellipses
2 parents b635157 + b78033a commit cc4ff32

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

packages/react-components/source/react/library/table/Table.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const propTypes = {
2020
dataKey: PropTypes.string.isRequired,
2121
/** Column header text */
2222
label: PropTypes.node,
23+
/** Truncate long cell content with ellipses. Must also specify a maxWidth in either the style prop or through a className. Default: false */
24+
hideOverflow: PropTypes.bool,
2325
/** Column header text */
2426
style: PropTypes.shape({}),
2527
}),
@@ -94,6 +96,7 @@ const Table = ({
9496
cellRenderer,
9597
columnData,
9698
dataKey,
99+
hideOverflow,
97100
className: cellClassName,
98101
style,
99102
} = {
@@ -104,7 +107,11 @@ const Table = ({
104107
return (
105108
<td
106109
key={dataKey}
107-
className={classNames('rc-table-cell', cellClassName)}
110+
className={classNames(
111+
'rc-table-cell',
112+
{ 'rc-table-cell-hide-overflow': hideOverflow },
113+
cellClassName,
114+
)}
108115
style={style}
109116
>
110117
{cellRenderer({

packages/react-components/source/react/library/table/Table.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Tables display data and sometimes allow users to take action on that data. Table
77
- Use headings to eliminate redundant words in columns. For example, instead of Version 3.8.4 and Version 3.8.5, title the column Version, and use only the version numbers in the table cells. This makes it easier for users to scan the options and reduces word count for Localization. Use sentence case capitalization.
88
- Use capitalization appropriate to the item named in the cell. For example, if the cell lists an environment, use the same capitalization as the environment name.
99

10-
### Basic use
10+
## Basic use
1111

1212
A basic table displays content and doesn't add additional capabilities.
1313

@@ -32,6 +32,8 @@ const columns = [
3232
```
3333
<!-- prettier-ignore-end -->
3434

35+
## Variations
36+
3537
### Fixed layouts
3638

3739
The `fixed` prop allows the table to be used in fixed layout mode. Provide explicit widths with the inline `style` parameter on each column or with an additional className.
@@ -185,3 +187,24 @@ A unique key can also be provided via a function:
185187
rowKey={rowData => rowdata.nested.uniqueKey}
186188
/>
187189
```
190+
191+
### Hidden Overflow
192+
193+
Use the `hideOverflow` flag if you want to hide long cell content with an ellipses. The flag only affects the column it is turned on for. You must provide explicit widths with the inline `style` parameter on each column you want to use it on or with an additional className.
194+
195+
<!-- prettier-ignore-start -->
196+
```jsx
197+
const data = [
198+
{ id: 1, type: 'Lorem ipsum', passage: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', characters: 123 },
199+
{ id: 2, type: 'Cicero', passage: 'Sed ut perspiciatis', characters: 19 },
200+
{ id: 3, type: '1914', passage: 'But I must explain to you how all this mistaken idea', characters: 52 },
201+
];
202+
203+
const columns = [
204+
{ label: 'Types', dataKey: 'type' },
205+
{ label: 'Passage', dataKey: 'passage', style: { width: '50%'}, hideOverflow: true },
206+
{ label: 'Character Length', dataKey: 'characters' },
207+
];
208+
209+
<Table fixed data={data} columns={columns} />;
210+
```

packages/react-components/source/scss/library/components/_table.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
border-radius: $puppet-common-border-radius;
1717
box-shadow: $puppet-common-elevation-50;
1818
overflow: hidden;
19-
19+
2020
.rc-table-row:last-of-type .rc-table-cell {
2121
border-bottom: 0;
2222
}
@@ -55,4 +55,10 @@
5555
.rc-table-cell {
5656
@include puppet-type-small();
5757
padding: 15px 16px;
58+
59+
&.rc-table-cell-hide-overflow {
60+
overflow: hidden;
61+
text-overflow: ellipsis;
62+
white-space: nowrap;
63+
}
5864
}

0 commit comments

Comments
 (0)