-
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.
Closes #93
- Loading branch information
github-actions
committed
Sep 25, 2020
1 parent
06873bc
commit 720ec23
Showing
6 changed files
with
785 additions
and
4 deletions.
There are no files selected for viewing
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,48 @@ | ||
import Icon from '../Icon' | ||
import React from 'react' | ||
import { TooltipPlacement } from 'antd/lib/tooltip' | ||
import { Meta, Story } from '@storybook/react/types-6-0' | ||
import Tooltip, { TooltipProps } from './index' | ||
|
||
const placementOptions: TooltipPlacement[] = [ | ||
'bottom', | ||
'bottomLeft', | ||
'bottomRight', | ||
'left', | ||
'leftBottom', | ||
'leftTop', | ||
'right', | ||
'rightBottom', | ||
'rightTop', | ||
'top', | ||
'topLeft', | ||
'topRight' | ||
] | ||
|
||
export default { | ||
argTypes: { | ||
children: { control: { disable: true } }, | ||
placement: { | ||
control: { | ||
options: placementOptions, | ||
type: 'select' | ||
}, | ||
defaultValue: 'right' | ||
} | ||
}, | ||
component: Tooltip, | ||
title: 'Tooltip' | ||
} as Meta | ||
|
||
const Template: Story<TooltipProps> = args => ( | ||
<div style={{ padding: 75 }}> | ||
<Tooltip {...args}> | ||
<Icon iconKey='dassana' /> | ||
</Tooltip> | ||
</div> | ||
) | ||
|
||
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,41 @@ | ||
import '../assets/styles/antdAnimations.css' | ||
import 'antd/lib/tooltip/style/index.css' | ||
// import 'antd/dist/antd.css' | ||
import { Tooltip as AntDTooltip } from 'antd' | ||
import { TooltipPlacement } from 'antd/es/tooltip' | ||
import React, { FC, ReactNode } from 'react' | ||
|
||
export type TooltipTitle = string | ReactNode | ||
|
||
export interface TooltipProps { | ||
/** | ||
* Element tooltip should be anchored to | ||
*/ | ||
children: ReactNode | ||
/** | ||
* Position of tooltip relative to the target | ||
*/ | ||
placement?: TooltipPlacement | ||
/** | ||
* Text shown in the tooltip | ||
*/ | ||
title: TooltipTitle | ||
} | ||
|
||
const Tooltip: FC<TooltipProps> = ({ | ||
children, | ||
placement = 'right', | ||
title | ||
}: TooltipProps) => { | ||
return ( | ||
<AntDTooltip | ||
overlayStyle={{ borderRadius: 4 }} | ||
placement={placement} | ||
title={title} | ||
> | ||
<span>{children}</span> | ||
</AntDTooltip> | ||
) | ||
} | ||
|
||
export default Tooltip |
Oops, something went wrong.