Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 0716901

Browse files
committed
refactor(Tooltip): extract the awesome component
1 parent f86a29a commit 0716901

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

components/AvatarsRow/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import React from 'react'
88
import T from 'prop-types'
99
import R from 'ramda'
10-
import { Tooltip } from 'antd'
10+
// import { Tooltip } from 'antd'
1111

1212
import { ATATARS_LIST_LENGTH } from '@config/general'
13-
1413
import { buildLog, prettyNum } from '@utils'
14+
15+
import Tooltip from '@components/Tooltip'
16+
1517
import {
1618
Wrapper,
1719
AvatarsItem,
@@ -50,15 +52,15 @@ const AvatarsRow = ({
5052
<span />
5153
) : (
5254
<MoreItem onClick={onTotalSelect.bind(this, { users, total })}>
53-
<Tooltip title={`所有评论共 ${total} 条`}>
55+
<Tooltip content={`所有评论共 ${total} 条`}>
5456
<AvatarsMore total={total}>{prettyNum(total)}</AvatarsMore>
5557
</Tooltip>
5658
</MoreItem>
5759
)}
5860

5961
{R.slice(0, limit, sortedUsers).map(user => (
6062
<AvatarsItem key={user.id} onClick={onUserSelect.bind(this, user)}>
61-
<Tooltip title={user.nickname}>
63+
<Tooltip content={user.nickname} delay={200}>
6264
<AvatarsImg src={user.avatar} />
6365
</Tooltip>
6466
</AvatarsItem>

components/Tooltip/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* Tooltip
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import T from 'prop-types'
9+
10+
import { Wrapper } from './styles'
11+
import { buildLog } from '@utils'
12+
13+
/* eslint-disable-next-line */
14+
const log = buildLog('c:Tooltip:index')
15+
16+
const Tooltip = ({ children, content, animation, arrow, delay, duration }) => (
17+
<Wrapper
18+
content={content}
19+
animation={animation}
20+
arrow={arrow}
21+
delay={[delay, 20]}
22+
duration={duration}
23+
>
24+
{children}
25+
</Wrapper>
26+
)
27+
28+
Tooltip.propTypes = {
29+
children: T.node.isRequired,
30+
content: T.oneOfType([T.string, T.node]).isRequired,
31+
// options
32+
animation: T.oneOf([
33+
'shift-away',
34+
'shift-toward',
35+
'fade',
36+
'scale',
37+
'perspective',
38+
]),
39+
arrow: T.bool,
40+
delay: T.number,
41+
duration: T.number,
42+
// more options see: https://atomiks.github.io/tippyjs/all-options/
43+
}
44+
45+
Tooltip.defaultProps = {
46+
animation: 'fade',
47+
arrow: true,
48+
delay: 0,
49+
duration: 100,
50+
}
51+
52+
export default React.memo(Tooltip)

components/Tooltip/styles/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import styled from 'styled-components'
2+
import Tippy from '@tippy.js/react'
3+
4+
// import Img from '@Img'
5+
// import { theme } from '@utils'
6+
7+
export const Wrapper = styled(Tippy)`
8+
background: tomato;
9+
10+
/* Styling the arrow for different placements */
11+
&[x-placement^='top'] {
12+
.tippy-arrow {
13+
border-top-color: tomato;
14+
}
15+
}
16+
`
17+
18+
export const Title = styled.div``
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import Tooltip from '../index'
5+
6+
describe('TODO <Tooltip />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

0 commit comments

Comments
 (0)