@platformatic/ui-components 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/components/TooltipV2.jsx +72 -0
- package/src/components/TooltipV2.module.css +31 -0
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import SearchBarV2 from './src/components/SearchBarV2'
|
|
|
37
37
|
import SimpleMetric from './src/components/SimpleMetric'
|
|
38
38
|
import Status from './src/components/Status'
|
|
39
39
|
import Tooltip from './src/components/Tooltip'
|
|
40
|
+
import TooltipV2 from './src/components/TooltipV2'
|
|
40
41
|
import TabbedWindow from './src/components/TabbedWindow'
|
|
41
42
|
import TabbedWindowV2 from './src/components/TabbedWindowV2'
|
|
42
43
|
import Tag from './src/components/Tag'
|
|
@@ -87,6 +88,7 @@ export {
|
|
|
87
88
|
Tag,
|
|
88
89
|
TextWithLabel,
|
|
89
90
|
Tooltip,
|
|
91
|
+
TooltipV2,
|
|
90
92
|
TwoColumnsLayout,
|
|
91
93
|
Versions,
|
|
92
94
|
VerticalSeparator
|
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import styles from './TooltipV2.module.css'
|
|
4
|
+
import { useEffect, useRef, useState } from 'react'
|
|
5
|
+
import { ALIGNMENT_LEFT, ALIGNMENTS } from './constants'
|
|
6
|
+
|
|
7
|
+
function TooltipV2 ({ tooltipClassName, text, visible, alignment, elementClassName }) {
|
|
8
|
+
const ref = useRef(null)
|
|
9
|
+
const alignmentClassName = styles[`${alignment}PltTooltip`]
|
|
10
|
+
const [className, setClassName] = useState(normalClassName())
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (visible) {
|
|
14
|
+
setClassName(visibleClassName())
|
|
15
|
+
if (ref.current) {
|
|
16
|
+
console.log('elementClassName', elementClassName)
|
|
17
|
+
const referenceBoundingClientRect = document.getElementsByClassName(elementClassName)[0]?.getBoundingClientRect()
|
|
18
|
+
if (referenceBoundingClientRect) {
|
|
19
|
+
const topPosition = referenceBoundingClientRect.y - (referenceBoundingClientRect.height)
|
|
20
|
+
const leftPosition = referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2)
|
|
21
|
+
ref.current.style.top = `${topPosition}px`
|
|
22
|
+
ref.current.style.left = `${leftPosition}px`
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
setClassName(normalClassName())
|
|
27
|
+
}
|
|
28
|
+
}, [visible])
|
|
29
|
+
|
|
30
|
+
function normalClassName () {
|
|
31
|
+
return `${styles.pltTooltipText} ${tooltipClassName} ${alignmentClassName}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function visibleClassName () {
|
|
35
|
+
return `${normalClassName()} ${styles.pltTooltipTextVisible}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return <span ref={ref} className={className}>{text}</span>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
TooltipV2.propTypes = {
|
|
42
|
+
/**
|
|
43
|
+
* text
|
|
44
|
+
*/
|
|
45
|
+
text: PropTypes.string,
|
|
46
|
+
/**
|
|
47
|
+
* tooltipClassName
|
|
48
|
+
*/
|
|
49
|
+
tooltipClassName: PropTypes.string,
|
|
50
|
+
/**
|
|
51
|
+
* visible
|
|
52
|
+
*/
|
|
53
|
+
visible: PropTypes.bool,
|
|
54
|
+
/**
|
|
55
|
+
* alignment
|
|
56
|
+
*/
|
|
57
|
+
alignment: PropTypes.oneOf(ALIGNMENTS),
|
|
58
|
+
/**
|
|
59
|
+
* alignment
|
|
60
|
+
*/
|
|
61
|
+
elementClassName: PropTypes.string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
TooltipV2.defaultProps = {
|
|
65
|
+
text: '',
|
|
66
|
+
tooltipClassName: '',
|
|
67
|
+
visible: false,
|
|
68
|
+
alignment: ALIGNMENT_LEFT,
|
|
69
|
+
elementClassName: ''
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default TooltipV2
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
.pltTooltipText {
|
|
3
|
+
@apply bg-white text-rich-black text-center p-2;
|
|
4
|
+
z-index: 20;
|
|
5
|
+
position: fixed;
|
|
6
|
+
visibility: hidden;
|
|
7
|
+
border-radius: 6px;
|
|
8
|
+
padding: 0.25rem;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
transition: opacity 0.3s;
|
|
11
|
+
transform: translateX(-50%);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.pltTooltipText::after {
|
|
15
|
+
content: "";
|
|
16
|
+
position: absolute;
|
|
17
|
+
top: 100%;
|
|
18
|
+
border-width: 5px;
|
|
19
|
+
border-style: solid;
|
|
20
|
+
border-color: white transparent transparent transparent;
|
|
21
|
+
left: 50%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.leftPltTooltip::after {
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.pltTooltipTextVisible {
|
|
29
|
+
visibility: visible;
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|