FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

improvement(CatalogTile): Removed truncation fade and fixed length by rebeccaalpert · Pull Request #3378 · patternfly/patternfly-react · GitHub

Merged
      • _catalog-tile.scss
      • CatalogTile.tsx
        • CatalogTile.test.tsx.snap
        • CatalogTile.md
        • catalogTile.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@
.catalog-tile-pf-description {
margin-top: 0;

.truncated {
span {
display: -webkit-box;
overflow: hidden;
position: relative;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}

&::after {
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 75%);
bottom: 0;
color: transparent;
content: ".";
position: absolute;
right: 0;
width: 50%;
text-align: right;
}
.has-footer {
-webkit-line-clamp: 1;
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import classNames from 'classnames';

import { Omit } from '../../helpers/typeUtils';
import { CatalogTileBadge } from './CatalogTileBadge';

export interface CatalogTileProps extends Omit<React.HTMLProps<HTMLElement>, 'title'> {
/** Id */
id?: any;
Expand Down Expand Up @@ -63,7 +62,6 @@ export class CatalogTile extends React.Component<CatalogTileProps> {
if (max === -1 || typeof text !== 'string' || text.length <= max) {
return text;
}

return (
<React.Fragment>
{text.substring(0, max - 3)}
Expand All @@ -72,13 +70,6 @@ export class CatalogTile extends React.Component<CatalogTileProps> {
);
};

private isTruncated = (text: string | React.ReactNode, max: number) => {
if (max === -1 || typeof text !== 'string' || text.length <= max) {
return false;
}
return true;
}

private handleClick = (e: React.SyntheticEvent<HTMLElement>) => {
const { onClick, href } = this.props;

Expand Down Expand Up @@ -126,28 +117,27 @@ export class CatalogTile extends React.Component<CatalogTileProps> {
...props
} = this.props;
const truncateDescription = truncateDescriptionFn || this.defaultTruncateDescription;
const isTruncated = this.isTruncated(description, maxDescriptionLength);

return (
<Card component={href || onClick ? 'a' : 'div'} id={id} href={href || '#'} className={classNames('catalog-tile-pf', { featured }, className)} onClick={e => this.handleClick(e)} isHoverable {...props}>
<CardHead>
{(badges.length > 0 || iconImg || iconClass || icon) && <CardHead>
{iconImg && <img className="catalog-tile-pf-icon" src={iconImg} alt={iconAlt} />}
{!iconImg && (iconClass || icon) && <span className={`catalog-tile-pf-icon ${iconClass}`}>{icon}</span>}
<CardActions>
{badges.length > 0 && <CardActions>
{this.renderBadges(badges)}
</CardActions>
</CardHead>
</CardActions>}
</CardHead>}
<CardHeader className="catalog-tile-pf-header">
<div className="catalog-tile-pf-title">{title}</div>
<div className="catalog-tile-pf-subtitle">{vendor}</div>
{vendor && <div className="catalog-tile-pf-subtitle">{vendor}</div>}
</CardHeader>
<CardBody className="catalog-tile-pf-body">
{description && <CardBody className="catalog-tile-pf-body">
<div className="catalog-tile-pf-description">
<span className={classNames({'truncated': isTruncated})}>
<span className={classNames({'has-footer': footer})}>
{truncateDescription(description, maxDescriptionLength, id)}
</span>
</div>
</CardBody>
</CardBody>}
{footer && <CardFooter className="catalog-tile-pf-footer">{footer}</CardFooter>}
</Card>
);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ exports[`CatalogTile href renders properly 1`] = `
id="test-href"
onClick={[Function]}
>
<CardHead>
<div
className="pf-c-card__head"
>
<CardActions>
<div
className="pf-c-card__actions"
/>
</CardActions>
</div>
</CardHead>
<CardHeader
className="catalog-tile-pf-header"
>
Expand Down Expand Up @@ -1139,7 +1128,7 @@ exports[`CatalogTile renders properly 1`] = `
className="catalog-tile-pf-description"
>
<span
className="truncated"
className=""
>
This is a very long description that should be truncated after 112 characters. 112 is the default but can be
Expand Down Expand Up @@ -1462,17 +1451,6 @@ exports[`CatalogTile renders properly 1`] = `
id="test-custom-truncation"
onClick={[Function]}
>
<CardHead>
<div
className="pf-c-card__head"
>
<CardActions>
<div
className="pf-c-card__actions"
/>
</CardActions>
</div>
</CardHead>
<CardHeader
className="catalog-tile-pf-header"
>
Expand Down Expand Up @@ -1508,7 +1486,7 @@ exports[`CatalogTile renders properly 1`] = `
className="catalog-tile-pf-description"
>
<span
className="truncated"
className=""
>
truncated
</span>
Expand Down Expand Up @@ -1786,7 +1764,7 @@ exports[`CatalogTile renders properly 1`] = `
className="catalog-tile-pf-description"
>
<span
className="truncated"
className="has-footer"
>
This is a very long description that should be truncated after 112 characters. 112 is the default but can be
Expand Down Expand Up @@ -1901,11 +1879,6 @@ exports[`CatalogTile renders properly 1`] = `
/>
</svg>
</span>
<CardActions>
<div
className="pf-c-card__actions"
/>
</CardActions>
</div>
</CardHead>
<CardHeader
Expand All @@ -1919,26 +1892,8 @@ exports[`CatalogTile renders properly 1`] = `
>
Custom SVG
</div>
<div
className="catalog-tile-pf-subtitle"
/>
</div>
</CardHeader>
<CardBody
className="catalog-tile-pf-body"
>
<div
className="pf-c-card__body catalog-tile-pf-body"
>
<div
className="catalog-tile-pf-description"
>
<span
className=""
/>
</div>
</div>
</CardBody>
</a>
</Card>
</CatalogTile>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,11 @@ Basic = () => (
]}
title="Patternfly-React"
vendor="provided by Red Hat"
description={
'This is a very long description that should be truncated after 112 characters. ' +
'112 is the default but can be overridden if need be. You can also provide a custom truncation function ' +
'to truncate the description how you see fit. It will be passed the description, max length, and id.'
}
/>
</React.Fragment>
);
```

```js title=Basic-without-truncated-text
import React from 'react';
import { CatalogTile, CatalogTileBadge } from '@patternfly/react-catalog-view-extension';
import { CogIcon } from '@patternfly/react-icons';
import { pfLogo2 } from './examples/pfLogo2.svg'

SimpleNoTrunc = () => (
<React.Fragment>
<CatalogTile
id="simple"
iconImg={pfLogo2}
iconAlt="PatternFly logo"
badges={[
<CatalogTileBadge title="Certified">
<CogIcon />
</CatalogTileBadge>
]}
title="Patternfly-React"
vendor="provided by Red Hat"
maxDescriptionLength={-1}
description={
'This is a very long description that is not truncated after 112 characters. ' +
'To turn off truncation, pass in a maxDescriptionLength of -1. Please note that this has changed from ' +
'PatternFly 3.'
'This is a very, very long description that should be truncated after three lines. ' +
'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +
'This has changed from PatternFly 3.'
}
/>
</React.Fragment>
Expand All @@ -96,10 +67,11 @@ SimpleFooter = () => (
]}
title="Patternfly-React"
vendor="provided by Red Hat"
maxDescriptionLength={-1}
description={
'This is a very long description that should be truncated after 112 characters. ' +
'112 is the default but can be overridden if need be. You can also provide a custom truncation function ' +
'to truncate the description how you see fit. It will be passed the description, max length, and id.'
'This is a very, very long description that should be truncated after one line. ' +
'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +
'This has changed from PatternFly 3.'
}
footer={
<span>
Expand All @@ -120,7 +92,7 @@ import { pfLogo2 } from './examples/pfLogo2.svg'
Link = () => (
<React.Fragment>
<CatalogTile
id="simple"
id="link-variant"
iconImg={pfLogo2}
iconAlt="PatternFly logo"
badges={[
Expand All @@ -130,11 +102,12 @@ Link = () => (
]}
href="http://patternfly.org/v4"
title="Patternfly-React"
vendor={<React.Fragment>provided by <a href="http://redhat.com">Red Hat</a></React.Fragment>}
vendor="provided by Red Hat"
maxDescriptionLength={-1}
description={
'This is a very long description that should be truncated after 112 characters. ' +
'112 is the default but can be overridden if need be. You can also provide a custom truncation function ' +
'to truncate the description how you see fit. It will be passed the description, max length, and id.'
'This is a very, very long description that should be truncated after three lines. ' +
'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +
'This has changed from PatternFly 3.'
}
/>
</React.Fragment>
Expand Down Expand Up @@ -163,10 +136,11 @@ MultiIcon = () => (
]}
title="Patternfly-React"
vendor={<React.Fragment>provided by <a href="http://redhat.com">Red Hat</a></React.Fragment>}
maxDescriptionLength={-1}
description={
'This is a very long description that should be truncated after 112 characters. ' +
'112 is the default but can be overridden if need be. You can also provide a custom truncation function ' +
'to truncate the description how you see fit. It will be passed the description, max length, and id.'
'This is a very, very long description that should be truncated after three lines. ' +
'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +
'This has changed from PatternFly 3.'
}
/>
</React.Fragment>
Expand All @@ -181,21 +155,21 @@ import { pfLogo2 } from './examples/pfLogo2.svg'
TextBadge = () => (
<React.Fragment>
<CatalogTile
id="multiIcon"
id="text-badge"
iconImg={pfLogo2}
iconAlt="PatternFly logo"
badges={[
'Community'
]}
title="Patternfly-React"
vendor={<React.Fragment>provided by <a href="http://redhat.com">Red Hat</a></React.Fragment>}
maxDescriptionLength={-1}
description={
'This is a very long description that should be truncated after 112 characters. ' +
'112 is the default but can be overridden if need be. You can also provide a custom truncation function ' +
'to truncate the description how you see fit. It will be passed the description, max length, and id.'
'This is a very, very long description that should be truncated after three lines. ' +
'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +
'This has changed from PatternFly 3.'
}
/>
</React.Fragment>
);
```

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@
font-size: 16px;
margin-left: 5px;
}
.ws-react-c-catalogtile .catalog-tile-pf-body .catalog-tile-pf-description span.truncated {
.ws-react-c-catalogtile .catalog-tile-pf-body .catalog-tile-pf-description span {
display: -webkit-box;
overflow: hidden;
position: relative;
}
.ws-react-c-catalogtile .catalog-tile-pf-body .catalog-tile-pf-description span.truncated::after {
background: linear-gradient(to right, rgba(255, 255, 255, 0), white 75%);
bottom: 0;
color: transparent;
content: ".";
position: absolute;
right: 0;
width: 50%;
text-align: right;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
.ws-react-c-catalogtile .catalog-tile-pf-body .catalog-tile-pf-description span.has-footer {
-webkit-line-clamp: 1;
}
.ws-react-c-catalogtile .example-ok-icon {
color: #4CB140;
Expand Down

Back | FazBrowse Home | New Git URL