Skip to content
Closed
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
155 changes: 145 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"lint:md:fix": "eslint packages --ext md --no-eslintrc --config .eslintrc-md.json --cache --fix",
"lint": "npm run lint:js && npm run lint:md",
"lint:fix": "npm run lint:js:fix && npm run lint:md:fix",
"serve:a11y": "npm run serve:a11y -w @patternfly/react-component-groups",
"test": "TZ=EST jest packages",
"test:a11y": "npm run test:a11y -w @patternfly/react-component-groups",
"serve:a11y": "npm run serve:a11y -w @patternfly/react-component-groups"
"test:a11y": "npm run test:a11y -w @patternfly/react-component-groups"
},
"devDependencies": {
"@babel/core": "^7.19.6",
Expand Down
7 changes: 4 additions & 3 deletions packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"docs:build": "pf-docs-framework build all --output public",
"docs:serve": "pf-docs-framework serve public --port 5001",
"docs:screenshots": "pf-docs-framework screenshots --urlPrefix http://localhost:5001",
"test:a11y": "patternfly-a11y --config patternfly-a11y.config",
"serve:a11y": "serve coverage"
"serve:a11y": "serve coverage",
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
},
"repository": "git+https://github.com/patternfly/react-component-groups.git",
"author": "Red Hat",
Expand All @@ -33,7 +33,8 @@
"dependencies": {
"@patternfly/react-core": "^5.0.0",
"@patternfly/react-icons": "^5.0.0",
"react-jss": "^10.9.2"
"react-jss": "^10.9.2",
"sanitize-html": "^2.3.3"
},
"peerDependencies": {
"react": "^17 || ^18",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
section: extensions
subsection: Component groups
id: Expandable text
source: react
propComponents: ['ExpandableText', 'ExpandableTextCustomButtonProps']
---

import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

## Component usage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Component usage


The **expandable text** component enables you to truncate text and allow users to display the full text by selecting a button.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Examples

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving below the "intro" text

### Basic ExpandableText component
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Basic ExpandableText component
### Basic expandable text


A basic expandable text component truncates text and displays a button below the truncated text. Users can view the full text by selecting the button, which toggles expansion.

```js file="./ExpandableTextExample.tsx"

```

### ExpandableText component with inline text

This is an example of a ExpandableText component with inline text. It will truncate the text and display the full text when the button is clicked. The button will be display inline with the text and will toggle the text.
Comment on lines +23 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### ExpandableText component with inline text
This is an example of a ExpandableText component with inline text. It will truncate the text and display the full text when the button is clicked. The button will be display inline with the text and will toggle the text.
### With an inline button
To style the button inline with the truncated text, rather than below, pass in `inline={true}`.


```js file="./ExpandableTextInlineExample.tsx"

```

### With custom button text

You can customize the button text to fit your needs with the `customButton` property.

The following example customizes the text to change when expanded and collapsed.


```js file="./ExpandableTextCustomLinkButtonExample.tsx"

```

### With a custom button

You can use a custom button to adjust the appearance, style, and variation of the expansion toggle.

```js file="./ExpandableTextCustomButtonExample.tsx"

```

### Without a button

You can remove the button to instead allow users to toggle full text by hovering over the truncated text.

To enable expansion on hover, use the `expandOnMouseOver` and `hideExpandText` properties.

```js file="ExpandableTextNoButtonExample.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Button } from '@patternfly/react-core';
import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;
Comment on lines +5 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;
const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunatly this change doesn't work since the text spans multiple lines.


export const ExpandableTextCustomButtonExample: React.FunctionComponent = () => {
const expandButton = <Button> Custom expand </Button>
const collapseButton = <Button> Custom collapse </Button>
return <ExpandableText text={text} customButton={{ expand: expandButton, collapse: collapseButton }} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;
Comment on lines +4 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;
const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried the suggestion but we need the ` to allow the paragraph to run on multiple lines. Otherwise we would need to add '+ a the end of each line.


export const ExpandableTextLinkButtonExample: React.FunctionComponent = () => <ExpandableText text={text} inline={true} customButton={{ expand: "Custom expand", collapse: "Custom collapse" }} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;

export const BasicExample: React.FunctionComponent = () => <ExpandableText text={text} length={10} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;

export const InlineExample: React.FunctionComponent = () => <ExpandableText text={text} length={10} inline={true} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ExpandableText from "@patternfly/react-component-groups/dist/dynamic/ExpandableText";

const text = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.`;

export const ExpandableTextNoButtonExample: React.FunctionComponent = () => <ExpandableText data-testid="expandable-text-hover" length={50} inline={true} text={text} expandOnMouseOver hideExpandText />;
Loading