Skip to content

Commit

Permalink
tooltip component (#174)
Browse files Browse the repository at this point in the history
* tooltip from pivotal-ui

* updates from bevacqua review

* add title property

* update demo with warning and show source + html

* put title in tooltip-content div

* do not allow tooltip to overflow window bounds

* add space to demos

* fix lint errors

* check cross dimension for tooltip placement

* rename cross dimension overflow function for better readability

* ensure tooltip opened by click does not get clipped by window viewport

* move overflow logic to service
  • Loading branch information
nreese authored Dec 6, 2017
1 parent a4adf2e commit c970d73
Show file tree
Hide file tree
Showing 14 changed files with 708 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src-docs/src/services/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ import { TitleExample }
import { ToastExample }
from '../../views/toast/toast_example';

import { TooltipExample }
from '../../views/tooltip/tooltip_example';


// Sandboxes

import AdvancedSettingsSandbox
Expand Down Expand Up @@ -201,6 +205,7 @@ const components = [
TextExample,
TitleExample,
ToastExample,
TooltipExample,
].map(example => createExample(example));

const sandboxes = [{
Expand Down
59 changes: 59 additions & 0 deletions src-docs/src/views/tooltip/examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';

import {
TooltipTrigger,
} from '../../../../src/components';

const autoPlacementTooltip = `I should be on the top but may get placed in another location
if I overflow the browser window. This will come in handy when tooltips get placed near the top
of pages. Its very hard to read a tooltip when part of it gets cut off and if you can't read it
then what is the point?`;

export default () => (
<div>
<div>
Check out this {(
<TooltipTrigger tooltip="I am the body" title="I am the title">
<span className="overlay-trigger" tabIndex="0"> tooltip with title.</span>
</TooltipTrigger>
)}
</div>
<div>
Check out this {(
<TooltipTrigger tooltip={autoPlacementTooltip} placement="top" size="m">
<span className="overlay-trigger" tabIndex="0"> tooltip on the top.</span>
</TooltipTrigger>
)}
</div>
<div>
Check out this {(
<TooltipTrigger tooltip={autoPlacementTooltip} placement="top" size="m" trigger="click">
<span className="overlay-trigger" tabIndex="0"> tooltip on click.</span>
</TooltipTrigger>
)}
</div>
<div>
Check out this {(
<TooltipTrigger tooltip="I should be on the left" placement="left">
<span className="overlay-trigger" tabIndex="0"> tooltip on the left.</span>
</TooltipTrigger>
)}
</div>

<div>
Check out this {(
<TooltipTrigger tooltip="I should be on the right" placement="right">
<span className="overlay-trigger" tabIndex="0"> tooltip on the right.</span>
</TooltipTrigger>
)}
</div>

<div>
Check out this {(
<TooltipTrigger tooltip="I should be on the bottom" placement="bottom">
<span className="overlay-trigger" tabIndex="0"> tooltip on the bottom.</span>
</TooltipTrigger>
)}
</div>
</div>
);
49 changes: 49 additions & 0 deletions src-docs/src/views/tooltip/tooltip_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';

import { renderToHtml } from '../../services';

import {
GuideSectionTypes,
} from '../../components';

import {
EuiCallOut,
EuiSpacer,
} from '../../../../src/components';

import TooltipExamples from './examples';
const examplesSource = require('!!raw-loader!./examples');
const examplesHtml = renderToHtml(TooltipExamples);

export const TooltipExample = {
title: 'Tooltip',
intro: (
<div>
<EuiCallOut
title="Work in progress"
color="warning"
>
<p>
This component is still undergoing active development, and its interface and implementation
are both subject to change.
</p>
</EuiCallOut>

<EuiSpacer size="l" />
</div>
),
sections: [{
title: 'Tooltip',
source: [{
type: GuideSectionTypes.JS,
code: examplesSource,
}, {
type: GuideSectionTypes.HTML,
code: examplesHtml,
}],
text: (
<p />
),
demo: <TooltipExamples />,
}],
};
5 changes: 5 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ export {
EuiToast,
} from './toast';

export {
Tooltip,
TooltipTrigger
} from './tooltip';

export {
EuiTitle,
} from './title';
Expand Down
1 change: 1 addition & 0 deletions src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
@import 'tabs/index';
@import 'title/index';
@import 'toast/index';
@import 'tooltip/index';
@import 'text/index';
1 change: 1 addition & 0 deletions src/components/tooltip/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "tooltip";
Loading

0 comments on commit c970d73

Please sign in to comment.