-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(LongTextTooltip): Added LongTextTooltip component. #41
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd7ec23
feat(LongTextTooltip): Added LongTextTooltip component.
dlabaj c1efad3
fixed issue with props in documentation.
dlabaj 99fba75
Updated with review comments.
dlabaj 79c91f3
Removed name export
dlabaj 6ad53a6
Update packages/module/patternfly-docs/content/extensions/component-g…
dlabaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...content/extensions/component-groups/examples/LongTextTooltip/LongTextTooltip.md
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
section: extensions | ||
subsection: Component groups | ||
id: Long text tooltip | ||
source: react | ||
propComponents: ['LongTextTooltip'] | ||
--- | ||
|
||
import LongTextTooltip from "@patternfly/react-component-groups/dist/dynamic/LongTextTooltip"; | ||
|
||
The **long text tooltip** component is a tooltip that can be used to display long text to users. It uses the `Tooltip` component to display the truncated text passed in as `content`. It uses `maxLength` prop to control the size of the content, and the `Tooltip` component to display the rest of the content. | ||
|
||
## Examples | ||
|
||
### LongTextTooltip component | ||
|
||
To provide users with long text, a basic long text tooltip should contain an appropriate and informative `content` and `maxLength`. Additionally you can pass in a `tooltipPosition` to control the position of the tooltip, and `tooltipMaxWidth` to control the tool tip width. | ||
|
||
```js file="./LongTextTooltipExample.tsx" | ||
|
||
``` |
10 changes: 10 additions & 0 deletions
10
...s/content/extensions/component-groups/examples/LongTextTooltip/LongTextTooltipExample.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { TooltipPosition } from '@patternfly/react-core'; | ||
import LongTextTooltip from "@patternfly/react-component-groups/dist/dynamic/LongTextTooltip"; | ||
|
||
export const LongTextTooltipExample: React.FunctionComponent = () => ( | ||
<LongTextTooltip | ||
content="This is a very long tooltip that will be truncated to fit the screen. It will also have a max width of 400px." | ||
maxLength={40} | ||
tooltipPosition={TooltipPosition.bottom}/> | ||
) |
39 changes: 39 additions & 0 deletions
39
packages/module/src/LongTextTooltip/LongTextTooltip.test.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import LongTextTooltip from './LongTextTooltip'; | ||
import { render } from '@testing-library/react'; | ||
import { TooltipPosition } from '@patternfly/react-core'; | ||
|
||
describe('LongTextTooltip component', () => { | ||
it('should render', () => { | ||
expect(render(<LongTextTooltip />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render content', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render content with maxLength', () => { | ||
expect( | ||
render(<LongTextTooltip content="Lorem Impsum" maxLength={50} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render content with maxLength shorter than content', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" maxLength={1} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render tooltip in a different spot', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" tooltipPosition={TooltipPosition.bottom}/>)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render tooltip in a different spot', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" tooltipPosition={TooltipPosition.left} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render tooltip in a different spot', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" tooltipPosition={TooltipPosition.right} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render content tooltip in a different spot with different width', () => { | ||
expect(render(<LongTextTooltip content="Lorem Impsum" tooltipPosition={TooltipPosition.left} tooltipMaxWidth="10vw" />)).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Tooltip, TooltipPosition, TooltipProps } from '@patternfly/react-core'; | ||
import React from 'react'; | ||
|
||
export interface LongTextTooltipProps extends Omit<TooltipProps, 'content'> { | ||
/** Content to display */ | ||
content?: string; | ||
/** Maximum length of the content being displayed in pixels */ | ||
maxLength?: number; | ||
/** Position of the tooltip */ | ||
tooltipPosition?: TooltipPosition; | ||
/** Maximum width of the tooltip */ | ||
tooltipMaxWidth?: string; | ||
} | ||
|
||
const LongTextTooltip: React.FC<LongTextTooltipProps> = ({ | ||
content = '', | ||
maxLength = Infinity, | ||
tooltipMaxWidth = '50vw', | ||
tooltipPosition = TooltipPosition.top, | ||
...rest | ||
}: LongTextTooltipProps) => { | ||
const truncate = (str: string, max: number) => (str.length > max ? str.substr(0, max - 1) + '…' : str); | ||
|
||
return content.length > maxLength ? ( | ||
<Tooltip maxWidth={tooltipMaxWidth} position={tooltipPosition} content={<div>{content}</div>} {...rest}> | ||
<div>{truncate(content, maxLength)}</div> | ||
</Tooltip> | ||
) : ( | ||
<span>{content}</span> | ||
); | ||
}; | ||
|
||
export default LongTextTooltip; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.