@platformatic/ui-components 0.7.26 → 0.7.27

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@platformatic/ui-components",
3
3
  "description": "Platformatic UI Components",
4
- "version": "0.7.26",
4
+ "version": "0.7.27",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -2,7 +2,7 @@
2
2
  import PropTypes from 'prop-types'
3
3
  import styles from './Tooltip.module.css'
4
4
  import { useEffect, useRef, useState } from 'react'
5
- import { DIRECTIONS, DIRECTION_BOTTOM, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_TOP } from './constants'
5
+ import { DIRECTIONS, DIRECTION_BOTTOM, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_TOP, POSITIONS, POSITION_CENTER, POSITION_END, POSITION_START } from './constants'
6
6
 
7
7
  function Tooltip ({
8
8
  immediateActive = true,
@@ -13,13 +13,17 @@ function Tooltip ({
13
13
  delay = 0,
14
14
  children = null,
15
15
  tooltipClassName = '',
16
- offset = 0
16
+ offset = 0,
17
+ position = POSITION_CENTER
17
18
  }) {
18
19
  let timeout
19
20
  // const [active, setActive] = useState(activeDependsOnVisible ? visible : false)
20
21
  const [active, setActive] = useState(immediateActive)
21
22
  let componentClassName = tooltipClassName || styles.tooltipTipBaseClass
22
23
  componentClassName += ` ${styles.tooltipTip} ` + styles[`${direction}`]
24
+ if (direction === DIRECTION_BOTTOM || direction === DIRECTION_TOP) {
25
+ componentClassName += ' ' + styles[`${position}`]
26
+ }
23
27
  const fixedStyle = { top: '0px', left: '0px' }
24
28
  const wrapperRef = useRef()
25
29
 
@@ -39,6 +43,19 @@ function Tooltip ({
39
43
  fixedStyle.top = `${referenceBoundingClientRect.y + referenceBoundingClientRect.height + offset}px`
40
44
  fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2)}px`
41
45
  fixedStyle.transform = 'translateX(-50%)'
46
+ switch (position) {
47
+ case POSITION_END:
48
+ fixedStyle.transform = 'translateX(0%)'
49
+ fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2) - 10}px`
50
+ break
51
+ case POSITION_START:
52
+ fixedStyle.transform = 'translateX(-100%)'
53
+ fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2) + 10}px`
54
+ break
55
+ default:
56
+ fixedStyle.transform = 'translateX(-50%)'
57
+ break
58
+ }
42
59
  break
43
60
  case DIRECTION_LEFT:
44
61
  fixedStyle.top = `${referenceBoundingClientRect.y + referenceBoundingClientRect.height / 2}px`
@@ -53,7 +70,19 @@ function Tooltip ({
53
70
  default:
54
71
  fixedStyle.top = `${referenceBoundingClientRect.y - referenceBoundingClientRect.height - offset}px`
55
72
  fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2)}px`
56
- fixedStyle.transform = 'translateX(-50%)'
73
+ switch (position) {
74
+ case POSITION_END:
75
+ fixedStyle.transform = 'translateX(0%)'
76
+ fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2) - 10}px`
77
+ break
78
+ case POSITION_START:
79
+ fixedStyle.transform = 'translateX(-100%)'
80
+ fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2) + 10}px`
81
+ break
82
+ default:
83
+ fixedStyle.transform = 'translateX(-50%)'
84
+ break
85
+ }
57
86
  break
58
87
  }
59
88
  }
@@ -123,7 +152,11 @@ Tooltip.propTypes = {
123
152
  /**
124
153
  * offset
125
154
  */
126
- offset: PropTypes.number
155
+ offset: PropTypes.number,
156
+ /**
157
+ * position
158
+ */
159
+ position: PropTypes.oneOf(POSITIONS)
127
160
  }
128
161
 
129
162
  export default Tooltip
@@ -66,3 +66,11 @@
66
66
  top: 50%;
67
67
  transform: translateX(0) translateY(-50%);
68
68
  }
69
+
70
+ .start::before {
71
+ left: calc(100% - 10px);
72
+ right: 10px;
73
+ }
74
+ .end::before {
75
+ left: 10px;
76
+ }
@@ -4,10 +4,9 @@ import Tooltip from '../components/Tooltip'
4
4
  import {
5
5
  ANTI_FLASH_WHITE,
6
6
  CHANGE_BACKGROUND_COLOR,
7
- COLORS_BUTTON,
8
- HOVER_EFFECTS_BUTTONS,
7
+ DIRECTIONS,
8
+ POSITIONS,
9
9
  RICH_BLACK,
10
- SIZES,
11
10
  WHITE
12
11
  } from '../components/constants'
13
12
  import Button from '../components/Button'
@@ -29,43 +28,38 @@ export default {
29
28
  )
30
29
  ],
31
30
  argTypes: {
32
- label: {
33
- type: 'string',
34
- control: 'text'
35
- },
36
- bold: {
31
+ immediateActive: {
37
32
  type: 'boolean'
38
33
  },
39
- backgroundColor: {
34
+ direction: {
40
35
  type: 'radio',
41
- options: COLORS_BUTTON
36
+ options: DIRECTIONS
42
37
  },
43
- color: {
44
- type: 'radio',
45
- options: COLORS_BUTTON
38
+ visible: {
39
+ type: 'boolean'
46
40
  },
47
- disabled: {
41
+ activeDependsOnVisible: {
48
42
  type: 'boolean'
49
43
  },
50
- size: {
51
- type: 'string',
52
- control: {
53
- type: 'radio',
54
- options: SIZES
55
- }
44
+ content: {
45
+ type: 'node'
56
46
  },
57
- hoverEffect: {
58
- type: 'radio',
59
- options: HOVER_EFFECTS_BUTTONS
47
+ delay: {
48
+ type: 'number'
60
49
  },
61
- bordered: {
62
- type: 'boolean'
50
+ children: {
51
+ type: 'node'
63
52
  },
64
- fullWidth: {
65
- type: 'boolean'
53
+ tooltipClassName: {
54
+ type: 'string',
55
+ control: 'text'
66
56
  },
67
- selected: {
68
- type: 'boolean'
57
+ offset: {
58
+ type: 'number'
59
+ },
60
+ position: {
61
+ type: 'radio',
62
+ options: POSITIONS
69
63
  }
70
64
  }
71
65
  }