Skip to content

Commit

Permalink
feat #93 - Tooltip component
Browse files Browse the repository at this point in the history
Closes #93
  • Loading branch information
github-actions committed Sep 25, 2020
1 parent 06873bc commit 720ec23
Show file tree
Hide file tree
Showing 6 changed files with 785 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/__snapshots__/storybook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ exports[`Storyshots Select Default 1`] = `
>
<div
className="ant-select-selector"
onClick={[Function]}
onMouseDown={[Function]}
>
<span
Expand Down Expand Up @@ -607,7 +606,6 @@ exports[`Storyshots Select Full Width 1`] = `
>
<div
className="ant-select-selector"
onClick={[Function]}
onMouseDown={[Function]}
>
<span
Expand Down Expand Up @@ -704,7 +702,6 @@ exports[`Storyshots Select Icon 1`] = `
>
<div
className="ant-select-selector"
onClick={[Function]}
onMouseDown={[Function]}
>
<span
Expand Down Expand Up @@ -810,7 +807,6 @@ exports[`Storyshots Select Search 1`] = `
>
<div
className="ant-select-selector"
onClick={[Function]}
onMouseDown={[Function]}
>
<span
Expand Down Expand Up @@ -1050,6 +1046,27 @@ exports[`Storyshots Toggle Small 1`] = `
</button>
`;

exports[`Storyshots Tooltip Default 1`] = `
<div
style={
Object {
"padding": 75,
}
}
>
<span
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<img
alt="dassana"
height={32}
src="dassana-blue.png"
/>
</span>
</div>
`;

exports[`Storyshots Tree Default 1`] = `
<ForwardRef
blockNode={true}
Expand Down
48 changes: 48 additions & 0 deletions src/components/Tooltip/Tooltip.stories.tsx
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'
}
40 changes: 40 additions & 0 deletions src/components/Tooltip/Tooltip.test.tsx
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')
})
})
41 changes: 41 additions & 0 deletions src/components/Tooltip/index.tsx
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
Loading

0 comments on commit 720ec23

Please sign in to comment.