odaptos_design_system 2.0.1 → 2.0.2

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,5 +1,5 @@
1
1
  {
2
- "version": "2.0.1",
2
+ "version": "2.0.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,6 +1,6 @@
1
- import React, { HTMLAttributes } from 'react';
1
+ import React, { HTMLAttributes, useEffect, useState } from 'react';
2
2
  import styles from './Tag.modules.scss';
3
- import { Text } from '../..';
3
+ import { Text, Tooltip } from '../..';
4
4
  import { colord, extend } from 'colord';
5
5
  import mixPlugin from 'colord/plugins/mix';
6
6
  import { getReadableTextColor } from '../../utils/getReadableTextColor';
@@ -82,31 +82,53 @@ export const Tag = ({
82
82
  else return 'sm';
83
83
  };
84
84
 
85
+ const [isEllipsisActive, setIsEllipsisActive] = useState(false);
86
+
87
+ useEffect(() => {
88
+ const checkEllipsis = () => {
89
+ const element = document.querySelector('#tag_text') as HTMLElement;
90
+ if (element) {
91
+ setIsEllipsisActive(element.scrollWidth > element.clientWidth);
92
+ }
93
+ };
94
+
95
+ checkEllipsis();
96
+ window.addEventListener('resize', checkEllipsis);
97
+ return () => window.removeEventListener('resize', checkEllipsis);
98
+ }, []);
99
+
85
100
  return (
86
- <div
87
- {...props}
88
- style={{ backgroundColor: customColor }}
89
- className={`${styles.tag} ${getTagStatus()} ${getTagSize()} ${
90
- className ?? ''
91
- } ${canBeRemoved && styles.canBeRemoved}`}
92
- >
93
- {iconLeft &&
94
- React.cloneElement(iconLeft, {
95
- style: { fill: getTextColor(), stroke: getTextColor() },
96
- })}
97
- <Text size={getTextSize()} text={text} color={getTextColor()} />
98
- {(amountNumber || amountNumber === 0) && (
101
+ <Tooltip tooltipDescription={text} arrow isTooltipActive={isEllipsisActive}>
102
+ <div
103
+ {...props}
104
+ style={{ backgroundColor: customColor }}
105
+ className={`${styles.tag} ${getTagStatus()} ${getTagSize()} ${
106
+ className ?? ''
107
+ } ${canBeRemoved && styles.canBeRemoved}`}
108
+ >
109
+ {iconLeft &&
110
+ React.cloneElement(iconLeft, {
111
+ style: { fill: getTextColor(), stroke: getTextColor() },
112
+ })}
99
113
  <Text
100
- text={`${amountNumber}`}
101
- weight="bold"
114
+ id="tag_text"
102
115
  size={getTextSize()}
116
+ text={text}
103
117
  color={getTextColor()}
104
118
  />
105
- )}
106
- {iconRight &&
107
- React.cloneElement(iconRight, {
108
- style: { fill: getTextColor(), stroke: getTextColor() },
109
- })}
110
- </div>
119
+ {(amountNumber || amountNumber === 0) && (
120
+ <Text
121
+ text={`${amountNumber}`}
122
+ weight="bold"
123
+ size={getTextSize()}
124
+ color={getTextColor()}
125
+ />
126
+ )}
127
+ {iconRight &&
128
+ React.cloneElement(iconRight, {
129
+ style: { fill: getTextColor(), stroke: getTextColor() },
130
+ })}
131
+ </div>
132
+ </Tooltip>
111
133
  );
112
134
  };
@@ -11,6 +11,7 @@ interface TextProps extends HTMLAttributes<HTMLParagraphElement> {
11
11
  textDecoration?: 'underline' | 'line-through';
12
12
  className?: string;
13
13
  required?: boolean;
14
+ id?: string;
14
15
  }
15
16
 
16
17
  /** This text should be use to display basic text
@@ -25,6 +26,7 @@ export const Text = ({
25
26
  textDecoration,
26
27
  className,
27
28
  required,
29
+ id,
28
30
  ...props
29
31
  }: TextProps) => {
30
32
  const getTextSize = (): string => {
@@ -53,6 +55,7 @@ export const Text = ({
53
55
  return (
54
56
  <p
55
57
  {...props}
58
+ id={id}
56
59
  style={{ color: color }}
57
60
  className={`${styles.text} ${
58
61
  italic ? styles.text_italic : ''