@platformatic/ui-components 0.6.7 → 0.6.9

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/.nvmrc CHANGED
@@ -1 +1 @@
1
- 20.14.0
1
+ 20.15.0
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.6.7",
4
+ "version": "0.6.9",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -3,7 +3,8 @@ import React from 'react'
3
3
  import PropTypes from 'prop-types'
4
4
  import commonStyles from './Common.module.css'
5
5
  import styles from './Tag.module.css'
6
- import { COLORS_BUTTON, OPACITY_100, OPACITY_20, OPACITY_30, OPACITY_60, WHITE } from './constants'
6
+ import { COLORS_BUTTON, OPACITY_100, OPACITY_20, OPACITY_30, OPACITY_60, SIZES, WHITE } from './constants'
7
+ import PlatformaticIcon from './PlatformaticIcon'
7
8
 
8
9
  function Tag ({
9
10
  text = '',
@@ -12,7 +13,9 @@ function Tag ({
12
13
  backgroundColor = '',
13
14
  bordered = true,
14
15
  opaque = OPACITY_100,
15
- fullRounded = false
16
+ fullRounded = false,
17
+ platformaticIcon = null,
18
+ paddingClass = ''
16
19
  }) {
17
20
  const stylesColor = textClassName || commonStyles[`text--${color}`]
18
21
  let stylesBorderColor = ''
@@ -25,10 +28,14 @@ function Tag ({
25
28
  }
26
29
  const stylesBackgroundColor = backgroundColor ? commonStyles[`background-color-${backgroundColor}`] : ''
27
30
  const opacity = commonStyles[`background-color-opaque-${opaque}`]
28
- const className = `${styles.tag} ${stylesColor} ${stylesBorderColor} ${stylesBackgroundColor} ${opacity}`
31
+ let className = `${styles.container} ${styles.tag} ${stylesBorderColor} ${stylesBackgroundColor} ${opacity} `
32
+ className += paddingClass || `${styles.padding} `
29
33
 
30
34
  return (
31
- <span className={className}>{text}</span>
35
+ <div className={className}>
36
+ {platformaticIcon && <PlatformaticIcon iconName={platformaticIcon.iconName} color={platformaticIcon.color} size={platformaticIcon.size} onClick={null} />}
37
+ <span className={stylesColor}>{text}</span>
38
+ </div>
32
39
  )
33
40
  }
34
41
  Tag.propTypes = {
@@ -40,7 +47,6 @@ Tag.propTypes = {
40
47
  * text
41
48
  */
42
49
  text: PropTypes.string,
43
- /**
44
50
  /**
45
51
  * textClassName
46
52
  */
@@ -60,8 +66,19 @@ Tag.propTypes = {
60
66
  /**
61
67
  * fullRounded
62
68
  */
63
- fullRounded: PropTypes.bool
64
-
69
+ fullRounded: PropTypes.bool,
70
+ /**
71
+ * platformaticIcon
72
+ */
73
+ platformaticIcon: PropTypes.shape({
74
+ iconName: PropTypes.string,
75
+ color: PropTypes.oneOf(COLORS_BUTTON),
76
+ size: PropTypes.oneOf(SIZES)
77
+ }),
78
+ /**
79
+ * paddingClass
80
+ */
81
+ paddingClass: PropTypes.string
65
82
  }
66
83
 
67
84
  export default Tag
@@ -1,9 +1,15 @@
1
1
  .tag {
2
- @apply rounded-md px-3 py-1 w-fit;
2
+ @apply rounded-md w-fit;
3
3
  }
4
4
  .bordered {
5
5
  @apply border border-solid;
6
6
  }
7
7
  .fullRounded {
8
8
  @apply rounded-full;
9
+ }
10
+ .container {
11
+ @apply flex flex-row gap-x-2 items-center border-0;
12
+ }
13
+ .padding {
14
+ @apply px-3 py-1
9
15
  }
@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from 'react'
5
5
  import { DIRECTIONS, DIRECTION_BOTTOM, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_TOP } from './constants'
6
6
 
7
7
  function Tooltip ({
8
+ immediateActive = true,
8
9
  direction = DIRECTION_TOP,
9
10
  visible = false,
10
11
  activeDependsOnVisible = false,
@@ -15,8 +16,8 @@ function Tooltip ({
15
16
  offset = 0
16
17
  }) {
17
18
  let timeout
18
- const [active, setActive] = useState(activeDependsOnVisible ? visible : false)
19
- // const [active, setActive] = useState(true)
19
+ // const [active, setActive] = useState(activeDependsOnVisible ? visible : false)
20
+ const [active, setActive] = useState(immediateActive)
20
21
  let componentClassName = tooltipClassName || styles.tooltipTipBaseClass
21
22
  componentClassName += ` ${styles.tooltipTip} ` + styles[`${direction}`]
22
23
  const fixedStyle = { top: '0px', left: '0px' }
@@ -31,17 +32,21 @@ function Tooltip ({
31
32
  if (wrapperRef.current) {
32
33
  const referenceBoundingClientRect = wrapperRef.current.getBoundingClientRect()
33
34
  if (referenceBoundingClientRect) {
34
- let topPosition
35
35
  let leftPosition
36
36
 
37
37
  switch (direction) {
38
38
  case DIRECTION_BOTTOM:
39
- topPosition = referenceBoundingClientRect.y - (referenceBoundingClientRect.height) - offset
40
- fixedStyle.top = `${topPosition}px`
41
- // fixedStyle.bottom = `calc(${offset}px *-1)`
39
+ fixedStyle.top = `${referenceBoundingClientRect.y + referenceBoundingClientRect.height + offset}px`
40
+ fixedStyle.left = `${referenceBoundingClientRect.x + (referenceBoundingClientRect.width / 2)}px`
41
+ fixedStyle.transform = 'translateX(-50%)'
42
42
  break
43
- case DIRECTION_RIGHT:
44
43
  case DIRECTION_LEFT:
44
+ fixedStyle.top = `${referenceBoundingClientRect.y + referenceBoundingClientRect.height / 2}px`
45
+ leftPosition = referenceBoundingClientRect.x - (2 * referenceBoundingClientRect.width) + offset
46
+ fixedStyle.left = `${leftPosition}px`
47
+ break
48
+ case DIRECTION_RIGHT:
49
+ fixedStyle.top = `${referenceBoundingClientRect.y + referenceBoundingClientRect.height / 2}px`
45
50
  leftPosition = referenceBoundingClientRect.x + referenceBoundingClientRect.width + offset
46
51
  fixedStyle.left = `${leftPosition}px`
47
52
  break
@@ -107,6 +112,10 @@ Tooltip.propTypes = {
107
112
  * visible
108
113
  */
109
114
  visible: PropTypes.bool,
115
+ /**
116
+ * immediateActive
117
+ */
118
+ immediateActive: PropTypes.bool,
110
119
  /**
111
120
  * activeDependsOnVisible
112
121
  */
@@ -60,7 +60,8 @@
60
60
  }
61
61
  /* CSS border triangles */
62
62
  .left::before {
63
- left: auto;
63
+ @apply border-l-white;
64
+ left: calc(100% + 6px);
64
65
  right: calc(6px * -2);
65
66
  top: 50%;
66
67
  transform: translateX(0) translateY(-50%);
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  import Tag from '../components/Tag'
3
+ import { MAIN_GREEN, OPACITY_30, SMALL, TERTIARY_BLUE, WHITE } from '../components/constants'
3
4
  export default {
4
5
  title: 'Platformatic/Tag',
5
6
  component: Tag,
@@ -17,10 +18,30 @@ export const Sample = Template.bind({})
17
18
  Sample.args = {
18
19
  text: 'Hello Platformatic!'
19
20
  }
21
+
20
22
  export const Version = Template.bind({})
21
23
  Version.args = {
22
24
  text: 'v1.2.3',
23
- backgroundColor: 'main-green',
25
+ backgroundColor: MAIN_GREEN,
24
26
  bordered: false,
25
27
  opaque: 30
26
28
  }
29
+
30
+ export const FullRounded = Template.bind({})
31
+ FullRounded.args = {
32
+ text: 'v1.2.3',
33
+ backgroundColor: WHITE,
34
+ bordered: false,
35
+ opaque: OPACITY_30,
36
+ fullRounded: true
37
+ }
38
+
39
+ export const WithIcon = Template.bind({})
40
+ WithIcon.args = {
41
+ text: 'adding some icon',
42
+ backgroundColor: TERTIARY_BLUE,
43
+ bordered: false,
44
+ opaque: OPACITY_30,
45
+ fullRounded: true,
46
+ platformaticIcon: { iconName: 'AddIcon', size: SMALL, color: WHITE }
47
+ }
@@ -71,23 +71,26 @@ export default {
71
71
  }
72
72
 
73
73
  const TemplateWithButton = (args) => (
74
- <Tooltip {...args}>
75
- <Button
76
- color={RICH_BLACK}
77
- backgroundColor={WHITE}
78
- onClick={() => alert('clicked Disabled WHITE')}
79
- bordered={false}
80
- hoverEffect={CHANGE_BACKGROUND_COLOR}
81
- hoverEffectProperties={{ changeBackgroundColor: ANTI_FLASH_WHITE }}
82
- label='Test button'
83
- />
84
- </Tooltip>
74
+ <div style={{ width: '100%', textAlign: 'center' }}>
75
+ <Tooltip {...args}>
76
+ <Button
77
+ color={RICH_BLACK}
78
+ backgroundColor={WHITE}
79
+ onClick={() => alert('clicked Disabled WHITE')}
80
+ bordered={false}
81
+ hoverEffect={CHANGE_BACKGROUND_COLOR}
82
+ hoverEffectProperties={{ changeBackgroundColor: ANTI_FLASH_WHITE }}
83
+ label='Test button'
84
+ />
85
+ </Tooltip>
86
+ </div>
85
87
  )
86
88
 
87
89
  export const TooltipBase = TemplateWithButton.bind({})
88
90
  // More on args: https://storybook.js.org/docs/react/writing-stories/args
89
91
  TooltipBase.args = {
90
92
  content: <span>I'm a tooltip over a button</span>,
91
- delay: 100,
92
- offset: 44
93
+ delay: 0,
94
+ offset: 14,
95
+ immediateActive: false
93
96
  }