-
Notifications
You must be signed in to change notification settings - Fork 30
ExpandableText: Adds the expandable text component previously known as truncate component. #39
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 | ||||||||||||||||
|
|
||||||||||||||||
| The **expandable text** component enables you to truncate text and allow users to display the full text by selecting a button. | ||||||||||||||||
|
|
||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving below the "intro" text |
||||||||||||||||
| ### Basic ExpandableText component | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| ```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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.`; | ||
dlabaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
dlabaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.`; | ||
|
|
||
dlabaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.