@platformatic/ui-components 0.2.14 → 0.2.16
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
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
|
+
}
|
|
@@ -32,14 +32,13 @@ function Select ({
|
|
|
32
32
|
const [showOptions, setShowOptions] = useState(false)
|
|
33
33
|
const [isSelected, setIsSelected] = useState(false)
|
|
34
34
|
const [isOnFocus, setIsOnFocus] = useState(false)
|
|
35
|
+
|
|
35
36
|
const showError = errorMessage.length > 0
|
|
36
37
|
const containerClassName = `${styles.container} ${defaultContainerClassName} `
|
|
37
38
|
let inputClassName = `${commonStyles.fullWidth} ${styles.select} ${inputTextClassName}`
|
|
38
39
|
inputClassName += ' ' + styles[`select-${mainColor}`]
|
|
39
40
|
inputClassName += ' ' + commonStyles[`text--${borderColor}`]
|
|
40
41
|
let optionsClassName = `${styles.options} ${defaultOptionsClassName} `
|
|
41
|
-
if (showError) inputClassName += ' ' + commonStyles['bordered--error-red']
|
|
42
|
-
if (disabled) inputClassName += ' ' + commonStyles['apply-opacity-30']
|
|
43
42
|
inputClassName += ' ' + commonStyles[`background-color-${backgroundColor}`]
|
|
44
43
|
optionsClassName += commonStyles[`background-color-${backgroundColor}`]
|
|
45
44
|
|
|
@@ -55,12 +54,20 @@ function Select ({
|
|
|
55
54
|
const optionSpanClassName = commonStyles[`text--${mainColor}`]
|
|
56
55
|
|
|
57
56
|
const [wrapperClassName, setWrapperClassName] = useState(normalClassName())
|
|
57
|
+
|
|
58
58
|
function onFocusClassName () {
|
|
59
59
|
return inputClassName + ' ' + commonStyles[`bordered--${borderColor}-100`]
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function normalClassName () {
|
|
63
|
-
|
|
63
|
+
const baseClassName = inputClassName
|
|
64
|
+
if (showError) {
|
|
65
|
+
inputClassName += ' ' + commonStyles['bordered--error-red']
|
|
66
|
+
} else {
|
|
67
|
+
inputClassName += ' ' + commonStyles[`bordered--${borderColor}-70`]
|
|
68
|
+
}
|
|
69
|
+
if (disabled) inputClassName += ' ' + commonStyles['apply-opacity-30']
|
|
70
|
+
return baseClassName
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
const dataProps = {}
|
|
@@ -101,6 +108,15 @@ function Select ({
|
|
|
101
108
|
}
|
|
102
109
|
}, [optionSelected])
|
|
103
110
|
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (disabled) {
|
|
113
|
+
const className = normalClassName() + ' ' + commonStyles['apply-opacity-30']
|
|
114
|
+
setWrapperClassName(className)
|
|
115
|
+
} else {
|
|
116
|
+
setWrapperClassName(normalClassName())
|
|
117
|
+
}
|
|
118
|
+
}, [disabled])
|
|
119
|
+
|
|
104
120
|
function renderLi (option, index) {
|
|
105
121
|
return (
|
|
106
122
|
<li
|
|
@@ -173,8 +189,8 @@ function Select ({
|
|
|
173
189
|
<div className={styles.selectContainer}>
|
|
174
190
|
<input type='text' name={name} value={value} className={wrapperClassName} ref={inputRef} onChange={onChange} disabled={disabled} placeholder={placeholder} onFocus={() => handleFocus()} onBlur={(e) => handleBlur(e)} />
|
|
175
191
|
<div className={styles.icons}>
|
|
176
|
-
{value?.length > 0 && <PlatformaticIcon iconName='CircleCloseIcon' color={borderColor} onClick={() => clearValue()} size={SMALL} />}
|
|
177
|
-
<PlatformaticIcon iconName={showOptions ? 'ArrowUpIcon' : 'ArrowDownIcon'} color={borderColor} onClick={() =>
|
|
192
|
+
{value?.length > 0 && !disabled && <PlatformaticIcon iconName='CircleCloseIcon' color={borderColor} onClick={() => clearValue()} size={SMALL} />}
|
|
193
|
+
<PlatformaticIcon iconName={showOptions ? 'ArrowUpIcon' : 'ArrowDownIcon'} color={borderColor} disabled={disabled} onClick={() => setShowOptions(!showOptions)} size={SMALL} />
|
|
178
194
|
</div>
|
|
179
195
|
</div>
|
|
180
196
|
{showOptions && !showError && renderOptions()}
|