odaptos_design_system 2.0.0 → 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.0",
2
+ "version": "2.0.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -79,3 +79,8 @@
79
79
  width: 1rem;
80
80
  }
81
81
  }
82
+ .canBeRemoved {
83
+ svg {
84
+ cursor: pointer;
85
+ }
86
+ }
@@ -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';
@@ -23,6 +23,7 @@ interface TagProps extends HTMLAttributes<HTMLDivElement> {
23
23
  amountNumber?: number | undefined;
24
24
  customColor?: string;
25
25
  className?: string;
26
+ canBeRemoved?: boolean;
26
27
  }
27
28
 
28
29
  /** Figma link : https://www.figma.com/file/fjnhhbL12HvKccPmJchVnr/Atomic-Library?type=design&node-id=1359-33355&mode=dev */
@@ -35,6 +36,7 @@ export const Tag = ({
35
36
  amountNumber,
36
37
  customColor,
37
38
  className,
39
+ canBeRemoved = false,
38
40
  ...props
39
41
  }: TagProps) => {
40
42
  const tagCustomColor = customColor ? colord(customColor) : undefined;
@@ -80,31 +82,53 @@ export const Tag = ({
80
82
  else return 'sm';
81
83
  };
82
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
+
83
100
  return (
84
- <div
85
- {...props}
86
- style={{ backgroundColor: customColor }}
87
- className={`${styles.tag} ${getTagStatus()} ${getTagSize()} ${
88
- className ?? ''
89
- }`}
90
- >
91
- {iconLeft &&
92
- React.cloneElement(iconLeft, {
93
- style: { fill: getTextColor(), stroke: getTextColor() },
94
- })}
95
- <Text size={getTextSize()} text={text} color={getTextColor()} />
96
- {(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
+ })}
97
113
  <Text
98
- text={`${amountNumber}`}
99
- weight="bold"
114
+ id="tag_text"
100
115
  size={getTextSize()}
116
+ text={text}
101
117
  color={getTextColor()}
102
118
  />
103
- )}
104
- {iconRight &&
105
- React.cloneElement(iconRight, {
106
- style: { fill: getTextColor(), stroke: getTextColor() },
107
- })}
108
- </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>
109
133
  );
110
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 : ''
@@ -234,10 +234,11 @@ export const MultiSelect = ({
234
234
  size="sm"
235
235
  status="info"
236
236
  key={`chipt-option-${index}`}
237
+ canBeRemoved
237
238
  iconRight={
238
239
  <RemoveCircledIcon
239
240
  fill={colors.blue_700}
240
- style={{ cursor: 'pointer' }}
241
+ style={{ cursor: 'pointer !important' }}
241
242
  onClick={() => deleteOption(option)}
242
243
  />
243
244
  }
@@ -256,6 +256,7 @@ export const MultiSelectWithCategories = ({
256
256
  size="sm"
257
257
  status="info"
258
258
  key={`chipt-option-${index}`}
259
+ canBeRemoved
259
260
  iconRight={
260
261
  <RemoveCircledIcon
261
262
  fill={colors.blue_700}