Skip to content

Merge pull request #207 from puppetlabs/pds-378-add-truncate-table-content-option #207

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

Merged
merged 2 commits into from
Jan 29, 2020
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 @@ -20,6 +20,8 @@ const propTypes = {
dataKey: PropTypes.string.isRequired,
/** Column header text */
label: PropTypes.node,
/** Truncate long cell content with ellipses. Must also specify a maxWidth in either the style prop or through a className. Default: false */
hideOverflow: PropTypes.bool,
/** Column header text */
style: PropTypes.shape({}),
}),
Expand Down Expand Up @@ -94,6 +96,7 @@ const Table = ({
cellRenderer,
columnData,
dataKey,
hideOverflow,
className: cellClassName,
style,
} = {
Expand All @@ -104,7 +107,11 @@ const Table = ({
return (
<td
key={dataKey}
className={classNames('rc-table-cell', cellClassName)}
className={classNames(
'rc-table-cell',
{ 'rc-table-cell-hide-overflow': hideOverflow },
cellClassName,
)}
style={style}
>
{cellRenderer({
Expand Down
25 changes: 24 additions & 1 deletion packages/react-components/source/react/library/table/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tables display data and sometimes allow users to take action on that data. Table
- 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.
- 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.

### Basic use
## Basic use

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

Expand All @@ -32,6 +32,8 @@ const columns = [
```
<!-- prettier-ignore-end -->

## Variations

### Fixed layouts

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.
Expand Down Expand Up @@ -185,3 +187,24 @@ A unique key can also be provided via a function:
rowKey={rowData => rowdata.nested.uniqueKey}
/>
```

### Hidden Overflow

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.

<!-- prettier-ignore-start -->
```jsx
const data = [
{ 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 },
{ id: 2, type: 'Cicero', passage: 'Sed ut perspiciatis', characters: 19 },
{ id: 3, type: '1914', passage: 'But I must explain to you how all this mistaken idea', characters: 52 },
];

const columns = [
{ label: 'Types', dataKey: 'type' },
{ label: 'Passage', dataKey: 'passage', style: { width: '50%'}, hideOverflow: true },
{ label: 'Character Length', dataKey: 'characters' },
];

<Table fixed data={data} columns={columns} />;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
border-radius: $puppet-common-border-radius;
box-shadow: $puppet-common-elevation-50;
overflow: hidden;

.rc-table-row:last-of-type .rc-table-cell {
border-bottom: 0;
}
Expand Down Expand Up @@ -55,4 +55,10 @@
.rc-table-cell {
@include puppet-type-small();
padding: 15px 16px;

&.rc-table-cell-hide-overflow {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}