Skip to content

Commit

Permalink
update(Tooltip): Render Popover's popup in Overlay component (#392)
Browse files Browse the repository at this point in the history
* Refactor popover to render in Overlay with enableMouseInteraction prop

* Add missing periods

* Add story
  • Loading branch information
FelixCodes authored Jul 24, 2020
1 parent cc6a932 commit e7812ce
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
20 changes: 7 additions & 13 deletions packages/core/src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ export type TooltipProps = {
content: NonNullable<React.ReactNode>;
/** True to disable tooltip but still show children. */
disabled?: boolean;
/** Manually override calculated horizontal align */
/** Manually override calculated horizontal align. */
horizontalAlign?: 'center' | 'left' | 'right';
/** True to use a light background with dark text. */
inverted?: boolean;
/** Callback fired when the tooltip is closed. */
onClose?: () => void;
/** Callback fired when the tooltip is shown. */
onShow?: () => void;
/** True to enable interactive popover functionality */
/** True to enable interactive popover functionality. */
popover?: boolean;
/** True to prevent dismissmal on mouse down. */
remainOnMouseDown?: boolean;
/** True to toggle tooltip display on click. */
toggleOnClick?: boolean;
/** True to add a dotted bottom border. */
underlined?: boolean;
/** Manually override calculated vertical align */
/** Manually override calculated vertical align. */
verticalAlign?: 'above' | 'below';
/** Width of the tooltip in units. */
width?: number;
Expand Down Expand Up @@ -314,23 +314,17 @@ export class Tooltip extends React.Component<TooltipProps & WithStylesProps, Too
marginTop: above ? -(tooltipHeight + targetRect.height + distance) : distance,
textAlign: align,
})}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div
className={cx(styles.content, invert && styles.content_inverted)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className={cx(styles.content, invert && styles.content_inverted)}>
<Text inverted={invert}>{content}</Text>
</div>
</div>
);

if (popover) {
return open && <div className={cx(styles.popover)}>{popupContent}</div>;
}

return (
<Overlay noBackground open={open} onClose={this.handleClose}>
<Overlay noBackground enableMouseInteraction={popover} open={open} onClose={this.handleClose}>
{popupContent}
</Overlay>
);
Expand Down
51 changes: 51 additions & 0 deletions packages/core/src/components/Tooltip/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import LoremIpsum from ':storybook/components/LoremIpsum';
import { withexpandMultiple } from '../Accordion/story';
import Button from '../Button';
import DataTable from '../DataTable';
import { RendererProps } from '../DataTable/types';
import Text from '../Text';
import Spacing from '../Spacing';
import Link from '../Link';
Expand Down Expand Up @@ -389,3 +391,52 @@ export function popoverExpandsAndShrinksWithContent() {
popoverExpandsAndShrinksWithContent.story = {
name: 'Popover expands and shrinks with content.',
};

export function popoverEscapesDataTableRow() {
return (
<DataTable
showRowDividers
data={[
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
{ data: { name: 'John' } },
]}
keys={['name']}
renderers={{
name: ({ row }: RendererProps<{ name: string }>) => {
const { name } = row.rowData.data;

return (
<Tooltip
popover
content={
<>
<Text bold>Certified by {name}</Text>
<div>
<LoremIpsum short />
</div>
<Link openInNewWindow href="https://github.com/airbnb/lunar">
Click me!
</Link>
</>
}
>
<Text>{name}</Text>
</Tooltip>
);
},
}}
/>
);
}

popoverEscapesDataTableRow.story = {
name: 'Popover can escape a DataTable row.',
};
5 changes: 0 additions & 5 deletions packages/core/src/components/Tooltip/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,4 @@ export const styleSheetTooltip: StyleSheet = ({ unit, color, pattern, ui }) => (
color: color.base,
backgroundColor: color.baseInverse,
},

popover: {
position: 'absolute',
zIndex: 1,
},
});

0 comments on commit e7812ce

Please sign in to comment.