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

Commit 9bd0162

Browse files
authored
chore(share): adjust naming & general styles (#1122)
* chore(share): adjust naming & general styles * style(tooltip): add animation & re-org codebase * style(tooltip): default delay set to 0
1 parent b4298ae commit 9bd0162

File tree

35 files changed

+2972
-3452
lines changed

35 files changed

+2972
-3452
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"react-svg": "11.1.2",
123123
"react-swipeable": "^5.5.1",
124124
"react-textarea-autosize": "^8.3.0",
125-
"react-tooltip": "^3.4.0",
125+
"react-tooltip": "^4.2.21",
126126
"react-trend": "^1.2.4",
127127
"react-use": "15.1.1",
128128
"react-useportal": "^1.0.13",

src/components/TheAvatar/ArticleAuthorAvatar.js

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FC, memo } from 'react'
2+
3+
import { TUser, TAccount } from '@/spec'
4+
// import { ICON } from '@/config'
5+
import ImgFallback from '@/components/ImgFallback'
6+
7+
import { Wrapper, Avatar } from './styles/article_author_avatar'
8+
9+
type TProps = {
10+
user: TUser
11+
onSelect: (user: TUser | TAccount) => void
12+
}
13+
14+
const ArticleAuthorAvatar: FC<TProps> = ({ user, onSelect }) => {
15+
return (
16+
<Wrapper onClick={() => onSelect(user)}>
17+
<Avatar
18+
src={user.avatar}
19+
fallback={<ImgFallback user={user} size={38} top={2} />}
20+
/>
21+
{/* <Tail src={`${ICON}/shape/tail.svg`} /> */}
22+
</Wrapper>
23+
)
24+
}
25+
26+
export default memo(ArticleAuthorAvatar)
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React from 'react'
1+
import { FC, memo } from 'react'
22

3+
import { TUser, TAccount } from '@/spec'
34
import { ICON } from '@/config'
45
import ImgFallback from '@/components/ImgFallback'
6+
57
import {
68
Wrapper,
79
InnerShadow,
@@ -11,18 +13,23 @@ import {
1113
MaskIcon,
1214
} from './styles/post_item_avatar'
1315

14-
const PostItemAvatar = ({ user, onSelect }) => {
16+
type TProps = {
17+
user: TUser
18+
onSelect: (user: TUser | TAccount) => void
19+
}
20+
21+
const PostItemAvatar: FC<TProps> = ({ user, onSelect }) => {
1522
return (
1623
<Wrapper onClick={() => onSelect(user)}>
1724
{user.login === 'mydearxym' ? (
1825
<QuoteAvatar
1926
src={user.avatar}
20-
fallback={<ImgFallback user={user} size={36} top={2} quote />}
27+
fallback={<ImgFallback user={user} size={32} top={2} quote />}
2128
/>
2229
) : (
2330
<Avatar
2431
src={user.avatar}
25-
fallback={<ImgFallback user={user} size={38} top={-1} left={-1} />}
32+
fallback={<ImgFallback user={user} size={32} top={-1} left={-1} />}
2633
/>
2734
)}
2835
{user.login === 'mydearxym' ? <QuoteShadow /> : <InnerShadow />}
@@ -33,4 +40,4 @@ const PostItemAvatar = ({ user, onSelect }) => {
3340
)
3441
}
3542

36-
export default React.memo(PostItemAvatar)
43+
export default memo(PostItemAvatar)

src/components/TheAvatar/index.js renamed to src/components/TheAvatar/index.tsx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,34 @@
44
*
55
*/
66

7-
import React from 'react'
8-
import T from 'prop-types'
9-
import { values } from 'ramda'
7+
import { FC, memo } from 'react'
108

9+
import { TAccount, TUser } from '@/spec'
1110
import { buildLog } from '@/utils'
12-
import { TYPE } from './constant'
1311

1412
import PostItemAvatar from './PostItemAvatar'
1513
import ArticleAuthorAvatar from './ArticleAuthorAvatar'
14+
import { TYPE } from './constant'
15+
import type { TMetric } from './spec'
1616

1717
import { Wrapper } from './styles'
1818

1919
/* eslint-disable-next-line */
2020
const log = buildLog('c:TheAvatar:index')
2121

22-
const TheAvatar = ({ testid, user, metric, onSelect }) => {
22+
type TProps = {
23+
testid?: string
24+
metric?: TMetric
25+
user: TUser | TAccount
26+
onSelect?: (user: TUser | TAccount) => void
27+
}
28+
29+
const TheAvatar: FC<TProps> = ({
30+
testid = 'the-avatar',
31+
user,
32+
metric = TYPE.POST_ITEM,
33+
onSelect = log,
34+
}) => {
2335
switch (metric) {
2436
case TYPE.POST_ITEM: {
2537
return <PostItemAvatar user={user} onSelect={onSelect} />
@@ -37,21 +49,4 @@ const TheAvatar = ({ testid, user, metric, onSelect }) => {
3749
}
3850
}
3951

40-
TheAvatar.propTypes = {
41-
testid: T.string,
42-
metric: T.oneOf(values(TYPE)),
43-
user: T.shape({
44-
avatar: T.string,
45-
nickname: T.string,
46-
bio: T.string,
47-
}).isRequired,
48-
onSelect: T.func,
49-
}
50-
51-
TheAvatar.defaultProps = {
52-
testid: 'the-avatar',
53-
metric: TYPE.POST_ITEM,
54-
onSelect: log,
55-
}
56-
57-
export default React.memo(TheAvatar)
52+
export default memo(TheAvatar)

src/components/TheAvatar/spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type TMetric = 'post-item' | 'article-author'
2+
export const holder = 1

src/components/TheAvatar/styles/article_author_avatar.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import styled from 'styled-components'
22

3-
import type { TTestable } from '@/spec'
43
import Img from '@/Img'
54
import { css, theme } from '@/utils'
65

76
import { Tail as TailBase } from './index'
87

9-
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
10-
'data-test-id': testid,
11-
}))<TTestable>`
8+
export const Wrapper = styled.div`
129
cursor: pointer;
1310
${css.size(36)};
1411
position: relative;

src/components/TheAvatar/styles/post_item_avatar.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
import styled from 'styled-components'
22

3-
import type { TTestable } from '@/spec'
43
import Img from '@/Img'
54
import { css, theme } from '@/utils'
65

76
import { Tail as TailBase } from './index'
87

9-
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
10-
'data-test-id': testid,
11-
}))<TTestable>`
8+
export const Wrapper = styled.div`
129
cursor: pointer;
13-
${css.circle(38)};
10+
${css.circle(32)};
1411
position: relative;
15-
margin-top: 2px;
12+
margin-top: 6px;
1613
`
1714
export const InnerShadow = styled.div`
1815
position: absolute;
19-
${css.circle(38)};
16+
${css.circle(33)};
2017
top: -1px;
2118
left: -1px;
2219
box-shadow: ${theme('avatar.shadow')};
2320
z-index: 2;
2421
`
2522
export const QuoteShadow = styled(InnerShadow)`
26-
${css.circle(34)};
23+
${css.circle(32)};
2724
top: 2px;
2825
left: 2px;
2926
box-shadow: ${theme('avatar.quoteShadow')};
3027
`
3128
export const Avatar = styled(Img)`
32-
${css.circle(36)};
29+
${css.circle(32)};
3330
fill: ${theme('thread.articleTitle')};
3431
opacity: ${theme('avatar.opacity')};
3532
`
3633
export const QuoteAvatar = styled(Avatar)`
37-
${css.circle(38)};
34+
${css.circle(34)};
3835
border: 2px solid;
3936
border-color: ${theme('avatar.quote')};
4037
`

src/components/Tooltip/index.tsx

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
*
32
* Tooltip
4-
*
3+
4+
* use custom animation Globally at GlobalStyle.ts
55
*/
66

77
import { FC, ReactNode, useState, useRef, memo } from 'react'
88

9-
import type { TTooltipPlacement, TTooltipAnimation } from '@/spec'
9+
import type { TTooltipPlacement } from '@/spec'
1010
import { css, buildLog, isDescendant } from '@/utils'
1111
import { useOutsideClick } from '@/hooks'
1212

@@ -28,7 +28,6 @@ const log = buildLog('c:Tooltip:index')
2828
type TProps = {
2929
children: ReactNode
3030
content: string | ReactNode
31-
animation?: TTooltipAnimation
3231
placement?: TTooltipPlacement
3332
// more options see: https://atomiks.github.io/tippyjs/all-options/
3433
delay?: number
@@ -49,7 +48,6 @@ type TProps = {
4948

5049
const Tooltip: FC<TProps> = ({
5150
children,
52-
animation = 'scale',
5351
noPadding = false,
5452
onHide,
5553
onShow,
@@ -116,56 +114,34 @@ const Tooltip: FC<TProps> = ({
116114
}
117115
})
118116

117+
const props = {
118+
ref,
119+
content: PopoverContent,
120+
placement,
121+
hideOnClick,
122+
zIndex: css.zIndex.popover,
123+
interactive: true,
124+
delay: [delay, 0] as [number, number],
125+
offset: [5, 5] as [number, number],
126+
duration,
127+
trigger,
128+
129+
onHide: () => {
130+
setInstance(null)
131+
setActive(false)
132+
onHide?.()
133+
},
134+
onShow: (instance) => {
135+
setInstance(instance)
136+
setActive(true)
137+
onShow?.()
138+
},
139+
}
140+
119141
return !noPadding ? (
120-
<StyledTippy
121-
ref={ref}
122-
content={PopoverContent}
123-
placement={placement}
124-
hideOnClick={hideOnClick}
125-
onHide={() => {
126-
setInstance(null)
127-
setActive(false)
128-
onHide?.()
129-
}}
130-
onShow={(instance) => {
131-
setInstance(instance)
132-
setActive(true)
133-
onShow?.()
134-
}}
135-
zIndex={css.zIndex.popover}
136-
interactive
137-
delay={delay}
138-
duration={duration}
139-
animation={animation}
140-
trigger={trigger}
141-
>
142-
{ContentComp}
143-
</StyledTippy>
142+
<StyledTippy {...props}>{ContentComp}</StyledTippy>
144143
) : (
145-
<NoPaddingStyledTippy
146-
ref={ref}
147-
content={PopoverContent}
148-
placement={placement}
149-
hideOnClick={hideOnClick}
150-
animation={animation}
151-
onHide={(instance) => {
152-
setInstance(instance)
153-
setActive(false)
154-
onHide?.()
155-
}}
156-
onShow={(instance) => {
157-
setInstance(instance)
158-
setActive(true)
159-
onShow?.()
160-
}}
161-
zIndex={css.zIndex.popover}
162-
interactive
163-
delay={delay}
164-
duration={duration}
165-
trigger={trigger}
166-
>
167-
{ContentComp}
168-
</NoPaddingStyledTippy>
144+
<NoPaddingStyledTippy {...props}>{ContentComp}</NoPaddingStyledTippy>
169145
)
170146
}
171147

src/components/Tooltip/styles/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const StyledTippy = styled(Tippy)`
1414
border-color: ${theme('popover.borderColor')};
1515
1616
border-radius: 5px;
17-
padding: 10px;
17+
padding: 5px;
1818
1919
.tippy-arrow {
2020
display: none;

0 commit comments

Comments
 (0)