-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat #93 - Tooltip component Closes #93 * feat #93 - Fix tooltip placement * feat #93 - Extract out placement options to utils and allow tooltip style customization * feat #93 - Add dataTag to tooltip trigger * feat #93 - Use storybook decorator for tooltip story * Update package.json Co-authored-by: github-actions <[email protected]>
- Loading branch information
1 parent
06873bc
commit 6f85686
Showing
10 changed files
with
1,731 additions
and
650 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,38 @@ | ||
import Icon from '../Icon' | ||
import { placementOptions } from '../utils' | ||
import React from 'react' | ||
import { Meta, Story } from '@storybook/react/types-6-0' | ||
import Tooltip, { TooltipProps } from './index' | ||
|
||
export default { | ||
argTypes: { | ||
children: { control: { disable: true } }, | ||
placement: { | ||
control: { | ||
options: placementOptions, | ||
type: 'select' | ||
} | ||
}, | ||
title: { control: { type: 'text' } } | ||
}, | ||
component: Tooltip, | ||
decorators: [ | ||
(PopoverStory: Story) => ( | ||
<div style={{ padding: 75 }}> | ||
<PopoverStory /> | ||
</div> | ||
) | ||
], | ||
title: 'Tooltip' | ||
} as Meta | ||
|
||
const Template: Story<TooltipProps> = args => ( | ||
<Tooltip {...args}> | ||
<Icon iconKey='dassana' /> | ||
</Tooltip> | ||
) | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
title: 'Dassana' | ||
} |
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,40 @@ | ||
import { Tooltip as AntDTooltip } from 'antd' | ||
import React from 'react' | ||
import { shallow, ShallowWrapper } from 'enzyme' | ||
import Tooltip, { TooltipProps } from './index' | ||
|
||
let wrapper: ShallowWrapper | ||
|
||
const mockTitle = 'foo' | ||
|
||
const getWrapper = ( | ||
additionalProps?: Omit<TooltipProps, 'children' | 'title'> | ||
): ShallowWrapper => | ||
shallow( | ||
<Tooltip title={mockTitle} {...additionalProps}> | ||
<div>Hello World</div> | ||
</Tooltip> | ||
) | ||
|
||
beforeEach(() => { | ||
wrapper = getWrapper() | ||
}) | ||
|
||
describe('Tooltip', () => { | ||
it('renders', () => { | ||
expect(wrapper).toHaveLength(1) | ||
}) | ||
|
||
it('correctly passes the title prop', () => { | ||
expect(wrapper.find(AntDTooltip).props().title).toEqual(mockTitle) | ||
}) | ||
|
||
it('correctly passes the placement prop if one is provided', () => { | ||
wrapper = getWrapper({ placement: 'top' }) | ||
expect(wrapper.find(AntDTooltip).props().placement).toEqual('top') | ||
}) | ||
|
||
it('has a default placement of right', () => { | ||
expect(wrapper.find(AntDTooltip).props().placement).toBe('right') | ||
}) | ||
}) |
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,51 @@ | ||
import '../assets/styles/antdAnimations.css' | ||
import 'antd/lib/tooltip/style/index.css' | ||
import { Tooltip as AntDTooltip } from 'antd' | ||
import cn from 'classnames' | ||
import { CommonComponentProps } from '../types' | ||
import { getDataTestAttributeProp } from '../utils' | ||
import { TooltipPlacement } from 'antd/es/tooltip' | ||
import React, { FC, ReactNode } from 'react' | ||
|
||
export type TooltipTitle = string | ReactNode | ||
|
||
export interface TooltipProps extends CommonComponentProps { | ||
/** | ||
* Element tooltip should be anchored to | ||
*/ | ||
children: ReactNode | ||
/** | ||
* Array of classes to pass to element | ||
* @default [] | ||
*/ | ||
classes?: string[] | ||
/** | ||
* Position of tooltip relative to the target | ||
*/ | ||
placement?: TooltipPlacement | ||
/** | ||
* Text shown in the tooltip | ||
*/ | ||
title: TooltipTitle | ||
} | ||
|
||
const Tooltip: FC<TooltipProps> = ({ | ||
children, | ||
classes = [], | ||
dataTag, | ||
placement = 'right', | ||
title | ||
}: TooltipProps) => ( | ||
<AntDTooltip | ||
overlayClassName={cn(classes)} | ||
overlayStyle={{ borderRadius: 4 }} | ||
placement={placement} | ||
title={title} | ||
> | ||
<span {...getDataTestAttributeProp('tooltip-trigger', dataTag)}> | ||
{children} | ||
</span> | ||
</AntDTooltip> | ||
) | ||
|
||
export default Tooltip |
Oops, something went wrong.