Skip to content
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

Adds display prop to EuiTooltip for common display block needs #4148

Merged
merged 11 commits into from
Oct 21, 2020
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test-env/
npm-debug.log
yarn-error.log
.cache-loader
**/*.out
snide marked this conversation as resolved.
Show resolved Hide resolved

# typescript output
types/
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `30.0.0`.
- Added display prop to `EuiTooltip` for common display block needs([4148](https://github.com/elastic/eui/pull/4148))
snide marked this conversation as resolved.
Show resolved Hide resolved

## [`30.0.0`](https://github.com/elastic/eui/tree/v30.0.0)

Expand Down
13 changes: 13 additions & 0 deletions src-docs/src/views/tool_tip/tool_tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export default () => (

<EuiSpacer />

<p>
<EuiToolTip
position="top"
content="Here is some tooltip text"
display="block">
<EuiLink href="#">
I am a block level tooltip, applied to the span anchor
</EuiLink>
snide marked this conversation as resolved.
Show resolved Hide resolved
</EuiToolTip>
</p>

<EuiSpacer />

<EuiToolTip position="right" content="Works on anything">
<EuiFieldText
placeholder="Hover over me"
Expand Down
10 changes: 10 additions & 0 deletions src/components/tool_tip/__snapshots__/tool_tip.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiToolTip applies our block stylings 1`] = `
<span
class="euiToolTipAnchor eui-displayBlock"
>
<button>
Trigger
</button>
</span>
`;

exports[`EuiToolTip is rendered 1`] = `
<span
class="euiToolTipAnchor"
Expand Down
15 changes: 15 additions & 0 deletions src/components/tool_tip/tool_tip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ describe('EuiToolTip', () => {
await sleep(260); // wait for showToolTip setTimout
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});

test('applies our block stylings', async () => {
snide marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiToolTip
title="title"
id="id"
content="content"
{...requiredProps}
display="block">
<button>Trigger</button>
</EuiToolTip>
);

expect(component).toMatchSnapshot();
});
});
16 changes: 15 additions & 1 deletion src/components/tool_tip/tool_tip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ interface ToolTipStyles {
opacity?: number;
}

const displayToClassNameMap = {
inlineBlock: undefined,
block: 'eui-displayBlock',
snide marked this conversation as resolved.
Show resolved Hide resolved
};

const DEFAULT_TOOLTIP_STYLES: ToolTipStyles = {
// position the tooltip content near the top-left
// corner of the window so it can't create scrollbars
Expand Down Expand Up @@ -89,6 +94,10 @@ export interface Props {
* The main content of your tooltip.
*/
content?: ReactNode;
/**
* Common diplay alternatives for the component.
snide marked this conversation as resolved.
Show resolved Hide resolved
*/
display?: keyof typeof displayToClassNameMap;
/**
* Delay before showing tooltip. Good for repeatable items.
*/
Expand Down Expand Up @@ -286,6 +295,7 @@ export class EuiToolTip extends Component<Props, State> {
content,
title,
delay,
display,
snide marked this conversation as resolved.
Show resolved Hide resolved
...rest
} = this.props;

Expand All @@ -297,7 +307,11 @@ export class EuiToolTip extends Component<Props, State> {
className
);

const anchorClasses = classNames('euiToolTipAnchor', anchorClassName);
const anchorClasses = classNames(
'euiToolTipAnchor',
display ? displayToClassNameMap[display] : null,
anchorClassName
);

let tooltip;
if (visible && (content || title)) {
Expand Down