@addev-be/ui 0.16.8 → 0.16.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/ui",
3
- "version": "0.16.8",
3
+ "version": "0.16.9",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc -b --watch",
@@ -8,30 +8,34 @@ export const HighlightedText: FC<
8
8
  } & HTMLAttributes<HTMLSpanElement>
9
9
  > = ({ text, highlight, ...props }) => {
10
10
  const textWithoutHtml = useMemo(() => extractTextFromHTML(text), [text]);
11
- console.log('textWithoutHtml', textWithoutHtml);
12
- if (!highlight) return <span {...props}>{textWithoutHtml}</span>;
11
+ const parts = useMemo(
12
+ () =>
13
+ highlight
14
+ ? textWithoutHtml
15
+ ?.split(new RegExp(`(${escapeForRegExp(highlight)})`, 'gi'))
16
+ .filter(Boolean) ?? []
17
+ : [],
18
+ [highlight, textWithoutHtml]
19
+ );
13
20
 
14
- const parts =
15
- textWithoutHtml?.split(
16
- new RegExp(`(${escapeForRegExp(highlight)})`, 'gi')
17
- ) ?? [];
21
+ if (!highlight || !parts.length) {
22
+ return <span {...props}>{textWithoutHtml}</span>;
23
+ }
18
24
 
19
25
  return (
20
26
  <span {...props}>
21
- {parts
22
- .filter((part) => !!part)
23
- .map((part, index) => (
24
- <span
25
- key={index}
26
- style={
27
- part.toLowerCase() === highlight.toLowerCase()
28
- ? { backgroundColor: 'gold' }
29
- : {}
30
- }
31
- >
32
- {part}
33
- </span>
34
- ))}
27
+ {parts.map((part, index) => (
28
+ <span
29
+ key={index}
30
+ style={
31
+ part.toLowerCase() === highlight.toLowerCase()
32
+ ? { backgroundColor: 'gold' }
33
+ : {}
34
+ }
35
+ >
36
+ {part}
37
+ </span>
38
+ ))}
35
39
  </span>
36
40
  );
37
41
  };