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

Commit 3c811e8

Browse files
committed
refactor(Tooltip): add more option && theme support
1 parent 0716901 commit 3c811e8

File tree

10 files changed

+82
-4
lines changed

10 files changed

+82
-4
lines changed

components/Tooltip/index.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ import { buildLog } from '@utils'
1313
/* eslint-disable-next-line */
1414
const log = buildLog('c:Tooltip:index')
1515

16-
const Tooltip = ({ children, content, animation, arrow, delay, duration }) => (
16+
const Tooltip = ({
17+
children,
18+
content,
19+
animation,
20+
arrow,
21+
delay,
22+
duration,
23+
placement,
24+
onTrigger,
25+
}) => (
1726
<Wrapper
1827
content={content}
1928
animation={animation}
2029
arrow={arrow}
2130
delay={[delay, 20]}
2231
duration={duration}
32+
placement={placement}
33+
onTrigger={onTrigger}
2334
>
2435
{children}
2536
</Wrapper>
@@ -39,6 +50,22 @@ Tooltip.propTypes = {
3950
arrow: T.bool,
4051
delay: T.number,
4152
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,
4269
// more options see: https://atomiks.github.io/tippyjs/all-options/
4370
}
4471

@@ -47,6 +74,9 @@ Tooltip.defaultProps = {
4774
arrow: true,
4875
delay: 0,
4976
duration: 100,
77+
placement: 'top',
78+
// hooks
79+
onTrigger: log,
5080
}
5181

5282
export default React.memo(Tooltip)

components/Tooltip/styles/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@ import styled from 'styled-components'
22
import Tippy from '@tippy.js/react'
33

44
// import Img from '@Img'
5-
// import { theme } from '@utils'
5+
import { theme } from '@utils'
66

77
export const Wrapper = styled(Tippy)`
8-
background: tomato;
8+
background: ${theme('tooltip.bg')};
9+
color: ${theme('tooltip.text')};
910
1011
/* Styling the arrow for different placements */
1112
&[x-placement^='top'] {
1213
.tippy-arrow {
13-
border-top-color: tomato;
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')};
1430
}
1531
}
1632
`

utils/themes/skins/cyan.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ const cyan = {
319319
doramonFg: '#F6DE38',
320320
doramonBg: 'transparent',
321321
},
322+
tooltip: {
323+
text: '#F8FBFC',
324+
bg: '#54A1AA',
325+
},
322326
}
323327

324328
export default cyan

utils/themes/skins/github.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ const github = {
320320
doramonFg: 'orange',
321321
doramonBg: 'transparent',
322322
},
323+
tooltip: {
324+
text: '#F0F6FA',
325+
bg: '#2B2B2B',
326+
},
323327
}
324328

325329
export default github

utils/themes/skins/green.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ const green = {
310310
doramonFg: 'orange',
311311
doramonBg: 'transparent',
312312
},
313+
tooltip: {
314+
text: '#F0F6FA',
315+
bg: '#2B2B2B',
316+
},
313317
}
314318

315319
export default green

utils/themes/skins/iron_green.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ const iconGreen = {
313313
doramonFg: 'orange',
314314
doramonBg: 'transparent',
315315
},
316+
tooltip: {
317+
text: '#F0F6FA',
318+
bg: '#2B2B2B',
319+
},
316320
}
317321

318322
export default iconGreen

utils/themes/skins/monokai.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ const monokai = {
314314
doramonFg: 'orange',
315315
doramonBg: 'transparent',
316316
},
317+
tooltip: {
318+
text: '#B0AFB0',
319+
bg: '#676464',
320+
},
317321
}
318322

319323
export default monokai

utils/themes/skins/purple.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ const purple = {
318318
doramonFg: 'orange',
319319
doramonBg: 'transparent',
320320
},
321+
tooltip: {
322+
text: '#B7B1C1',
323+
bg: '#56526E',
324+
},
321325
}
322326

323327
export default purple

utils/themes/skins/solarized_dark.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ const solarizedDark = {
319319
doramonFg: 'orange',
320320
doramonBg: 'transparent',
321321
},
322+
tooltip: {
323+
text: '#95C1DD',
324+
bg: '#075575',
325+
},
322326
}
323327

324328
export default solarizedDark

utils/themes/skins/yellow.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ const yellow = {
317317
doramonFg: 'orange',
318318
doramonBg: 'transparent',
319319
},
320+
tooltip: {
321+
text: '#F0F6FA',
322+
bg: '#2B2B2B',
323+
},
320324
}
321325

322326
export default yellow

0 commit comments

Comments
 (0)