Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/image-tooltip/ImageTooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';

import Button, { ButtonType } from '../button/Button';

// @ts-ignore flow import
import testImageSrc from './getTestImageSrc';
import ImageTooltip from './ImageTooltip';
import notes from './ImageTooltip.stories.md';
Expand Down
10 changes: 3 additions & 7 deletions src/components/image-tooltip/ImageTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as React from 'react';
import classNames from 'classnames';

// @ts-ignore flow import
import Tooltip, { TooltipProps, TooltipTheme } from '../tooltip';
import Tooltip, { TooltipTheme, type TooltipProps } from '../tooltip';
import ImageTooltipContent from './ImageTooltipContent';

import './ImageTooltip.scss';

// We manually set "text" with our specific visual tooltip content.
type OtherTooltipProps = Omit<TooltipProps, 'text'>;

export type ImageTooltipProps = {
export interface ImageTooltipProps extends Omit<TooltipProps, 'text'> {
/** A React element to put the tooltip on */
children: React.ReactChild;
/** A string to be used in the tooltip's paragraph content */
Expand All @@ -19,7 +15,7 @@ export type ImageTooltipProps = {
image: React.ReactElement;
/** A string to be used in the tooltip's title heading */
title: string;
} & OtherTooltipProps;
}

const ImageTooltip = ({ children, className, content, image, title, ...otherTooltipProps }: ImageTooltipProps) => {
// State to track if the image has been loaded before displaying the tooltip
Expand Down
12 changes: 5 additions & 7 deletions src/components/image-tooltip/ImageTooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import classNames from 'classnames';

import './ImageTooltipContent.scss';

type OnImageLoad = () => void;

export type ImageTooltipContentProps = {
interface ImageTooltipContentProps {
Comment thread
bonchevskyi marked this conversation as resolved.
/** A React component representing the image used in the visual tooltip */
children: React.ReactElement;
/** A string to be used in the tooltip's paragraph content */
content: string;
/** A callback triggered onLoad for the image element */
onImageLoad: OnImageLoad;
onImageLoad: () => void;
/** A string to be used in the tooltip's title heading */
title: string;
};
}
Comment thread
bonchevskyi marked this conversation as resolved.

function cloneTooltipChildWithNewProps(child: React.ReactElement, onImageLoad: OnImageLoad): React.ReactElement {
const cloneTooltipChildWithNewProps = (child: React.ReactElement, onImageLoad: () => void): React.ReactElement => {
const {
props: { className: existingClasses },
} = child;
Expand All @@ -26,7 +24,7 @@ function cloneTooltipChildWithNewProps(child: React.ReactElement, onImageLoad: O
className,
onLoad: onImageLoad,
});
}
};

const ImageTooltipContent = ({ children, content, onImageLoad, title }: ImageTooltipContentProps) => (
<div className="bdl-ImageTooltipContent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { shallow, ShallowWrapper } from 'enzyme';

import Button from '../../button/Button';
import ImageTooltip from '../ImageTooltip';
// @ts-ignore flow import
import testImageSrc from '../getTestImageSrc';

describe('components/image-tooltip/ImageTooltip', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';

import ImageTooltipContent from '../ImageTooltipContent';
// @ts-ignore flow import
import testImageSrc from '../getTestImageSrc';

describe('components/image-tooltip/ImageTooltipContent', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/components/image-tooltip/getTestImageSrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore png import has no type declaration
import testImageSrc from './__tests__/test-image.png';

export default testImageSrc;
1 change: 1 addition & 0 deletions src/components/image-tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './ImageTooltip';
export type { ImageTooltipProps } from './ImageTooltip';
Loading