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

Commit 2cb9c1b

Browse files
committed
chore: Merge branch 'dev'
2 parents 174dfc5 + 8e7f327 commit 2cb9c1b

File tree

42 files changed

+525
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+525
-388
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"alias": {
5353
"@containers":"./containers",
5454
"@components":"./components",
55+
"@hooks":"./components/Hooks",
5556
"@config":"./config",
5657
"@stores":"./stores",
5758
"@model":"./stores/SharedModel",

components/AvatarsRow/index.js

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

1211
import { ATATARS_LIST_LENGTH } from '@config/general'
13-
1412
import { buildLog, prettyNum } from '@utils'
13+
14+
import Tooltip from '@components/Tooltip'
15+
1516
import {
1617
Wrapper,
1718
AvatarsItem,
@@ -50,15 +51,15 @@ const AvatarsRow = ({
5051
<span />
5152
) : (
5253
<MoreItem onClick={onTotalSelect.bind(this, { users, total })}>
53-
<Tooltip title={`所有评论共 ${total} 条`}>
54+
<Tooltip content={`所有评论共 ${total} 条`}>
5455
<AvatarsMore total={total}>{prettyNum(total)}</AvatarsMore>
5556
</Tooltip>
5657
</MoreItem>
5758
)}
5859

5960
{R.slice(0, limit, sortedUsers).map(user => (
6061
<AvatarsItem key={user.id} onClick={onUserSelect.bind(this, user)}>
61-
<Tooltip title={user.nickname}>
62+
<Tooltip content={user.nickname} delay={200}>
6263
<AvatarsImg src={user.avatar} />
6364
</Tooltip>
6465
</AvatarsItem>

components/Hooks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as useShortcut } from './useShortcut'
22
export { default as useMedia } from './useMedia'
33
export { default as usePlatform } from './usePlatform'
4+
export { default as useScript } from './useScript'

components/Hooks/useScript.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { useState, useEffect } from 'react'
2+
3+
const cachedScripts = []
4+
5+
const useScript = src => {
6+
// Keeping track of script loaded and error state
7+
const [state, setState] = useState({
8+
loaded: false,
9+
error: false,
10+
})
11+
12+
useEffect(
13+
() => {
14+
// If cachedScripts array already includes src that means another instance ...
15+
// ... of this hook already loaded this script, so no need to load again.
16+
if (cachedScripts.includes(src)) {
17+
setState({
18+
loaded: true,
19+
error: false,
20+
})
21+
} else {
22+
cachedScripts.push(src)
23+
24+
// Create script
25+
const script = document.createElement('script')
26+
script.src = src
27+
script.async = true
28+
29+
// Script event listener callbacks for load and error
30+
const onScriptLoad = () => {
31+
setState({
32+
loaded: true,
33+
error: false,
34+
})
35+
}
36+
37+
const onScriptError = () => {
38+
// Remove from cachedScripts we can try loading again
39+
const index = cachedScripts.indexOf(src)
40+
if (index >= 0) cachedScripts.splice(index, 1)
41+
script.remove()
42+
43+
setState({
44+
loaded: true,
45+
error: true,
46+
})
47+
}
48+
49+
script.addEventListener('load', onScriptLoad)
50+
script.addEventListener('error', onScriptError)
51+
52+
// Add script to document body
53+
document.body.appendChild(script)
54+
55+
// Remove event listeners on cleanup
56+
return () => {
57+
script.removeEventListener('load', onScriptLoad)
58+
script.removeEventListener('error', onScriptError)
59+
}
60+
}
61+
},
62+
[src] // Only re-run effect if script src changes
63+
)
64+
65+
return [state.loaded, state.error]
66+
}
67+
68+
export default useScript

components/Tooltip/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 = ({
17+
children,
18+
content,
19+
animation,
20+
arrow,
21+
delay,
22+
duration,
23+
placement,
24+
onTrigger,
25+
}) => (
26+
<Wrapper
27+
content={content}
28+
animation={animation}
29+
arrow={arrow}
30+
delay={[delay, 20]}
31+
duration={duration}
32+
placement={placement}
33+
onTrigger={onTrigger}
34+
>
35+
{children}
36+
</Wrapper>
37+
)
38+
39+
Tooltip.propTypes = {
40+
children: T.node.isRequired,
41+
content: T.oneOfType([T.string, T.node]).isRequired,
42+
// options
43+
animation: T.oneOf([
44+
'shift-away',
45+
'shift-toward',
46+
'fade',
47+
'scale',
48+
'perspective',
49+
]),
50+
arrow: T.bool,
51+
delay: T.number,
52+
duration: T.number,
53+
placement: T.oneOf([
54+
'top',
55+
'top-start',
56+
'top-end',
57+
'bottom',
58+
'bottom-start',
59+
'bottom-end',
60+
'left',
61+
'left-start',
62+
'left-end',
63+
'right',
64+
'right-start',
65+
'right-end',
66+
]),
67+
// hooks
68+
onTrigger: T.func,
69+
// more options see: https://atomiks.github.io/tippyjs/all-options/
70+
}
71+
72+
Tooltip.defaultProps = {
73+
animation: 'fade',
74+
arrow: true,
75+
delay: 0,
76+
duration: 100,
77+
placement: 'top',
78+
// hooks
79+
onTrigger: log,
80+
}
81+
82+
export default React.memo(Tooltip)

components/Tooltip/styles/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: ${theme('tooltip.bg')};
9+
color: ${theme('tooltip.text')};
10+
11+
/* Styling the arrow for different placements */
12+
&[x-placement^='top'] {
13+
.tippy-arrow {
14+
border-top-color: ${theme('tooltip.bg')};
15+
}
16+
}
17+
&[x-placement^='bottom'] {
18+
.tippy-arrow {
19+
border-top-color: ${theme('tooltip.bg')};
20+
}
21+
}
22+
&[x-placement^='left'] {
23+
.tippy-arrow {
24+
border-top-color: ${theme('tooltip.bg')};
25+
}
26+
}
27+
&[x-placement^='right'] {
28+
.tippy-arrow {
29+
border-top-color: ${theme('tooltip.bg')};
30+
}
31+
}
32+
`
33+
34+
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+
})

components/index.bak.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

containers/AccountViewer/ContributeMap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const log = buildLog('C:Comments')
2626

2727
const customTooltipDataAttrs = value => ({
2828
'data-tip': value.date === null ? '' : `${value.count} 次 (${value.date})`,
29-
'data-for': 'user_comtribute_map',
29+
'data-for': 'user_contribute_map',
3030
'data-offset': JSON.stringify({ right: 7 }),
3131
})
3232

@@ -103,7 +103,7 @@ const ContributeMap = ({ data }) => {
103103
type="error"
104104
effect="solid"
105105
place="top"
106-
id="user_comtribute_map"
106+
id="user_contribute_map"
107107
/>
108108
<DotWrapper>
109109
<DotList>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
3+
// import { ICON_CMD } from 'config'
4+
import { Wrapper, Title, Desc } from './styles/hinter'
5+
6+
const Hinter = ({ title, desc }) => (
7+
<Wrapper>
8+
<Title>{title}</Title>
9+
<Desc>{desc}</Desc>
10+
</Wrapper>
11+
)
12+
13+
export default Hinter

0 commit comments

Comments
 (0)