@visns-studio/visns-components 5.10.2 → 5.10.3

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.
@@ -197,8 +197,6 @@ function Field({
197
197
  };
198
198
  }
199
199
 
200
- console.info(JSON.stringify(filter));
201
-
202
200
  CustomFetch(settings.url, 'POST', filter, function (result) {
203
201
  setOptions(result.data);
204
202
 
@@ -0,0 +1,123 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { Tooltip } from 'react-tooltip';
3
+ import moment from 'moment';
4
+ import numeral from 'numeral';
5
+
6
+ // Utility function to check if text content is truncated
7
+ const isTextTruncated = (element) => {
8
+ if (!element) return false;
9
+ return (
10
+ element.scrollWidth > element.clientWidth ||
11
+ element.scrollHeight > element.clientHeight
12
+ );
13
+ };
14
+
15
+ // Utility function to format cell value for tooltip display
16
+ const formatCellValueForTooltip = (value, columnType) => {
17
+ if (value === null || value === undefined || value === '') {
18
+ return '';
19
+ }
20
+
21
+ switch (columnType) {
22
+ case 'date':
23
+ case 'datetime':
24
+ if (
25
+ moment(value).isValid() &&
26
+ moment(value).format('YYYY-MM-DD') !== '1970-01-01'
27
+ ) {
28
+ return moment(value).format('DD-MM-YYYY HH:mm');
29
+ }
30
+ return String(value);
31
+ case 'currency':
32
+ return numeral(value).format('$0,0.00');
33
+ case 'number':
34
+ return numeral(value).format('0,0');
35
+ case 'boolean':
36
+ return value ? 'Yes' : 'No';
37
+ case 'richtext':
38
+ // Strip HTML tags for tooltip
39
+ const tempDiv = document.createElement('div');
40
+ tempDiv.innerHTML = value;
41
+ return tempDiv.textContent || tempDiv.innerText || '';
42
+ default:
43
+ return String(value);
44
+ }
45
+ };
46
+
47
+ // Component to wrap cell content with tooltip functionality
48
+ const CellWithTooltip = ({
49
+ children,
50
+ value,
51
+ columnType = 'text',
52
+ className = '',
53
+ }) => {
54
+ const cellRef = useRef(null);
55
+ const [showTooltip, setShowTooltip] = useState(false);
56
+ const [tooltipId] = useState(
57
+ () => `cell-tooltip-${Math.random().toString(36).substr(2, 9)}`
58
+ );
59
+
60
+ useEffect(() => {
61
+ const checkTruncation = () => {
62
+ if (cellRef.current) {
63
+ const isTruncated = isTextTruncated(cellRef.current);
64
+ setShowTooltip(isTruncated);
65
+ }
66
+ };
67
+
68
+ // Check truncation on mount and when content changes
69
+ checkTruncation();
70
+
71
+ // Also check on window resize
72
+ const handleResize = () => checkTruncation();
73
+ window.addEventListener('resize', handleResize);
74
+
75
+ return () => {
76
+ window.removeEventListener('resize', handleResize);
77
+ };
78
+ }, [children, value]);
79
+
80
+ const tooltipContent = formatCellValueForTooltip(value, columnType);
81
+
82
+ // Only show tooltip if content is truncated and we have meaningful content
83
+ const shouldShowTooltip =
84
+ showTooltip && tooltipContent && tooltipContent.trim() !== '';
85
+
86
+ return (
87
+ <div
88
+ ref={cellRef}
89
+ className={className}
90
+ style={{
91
+ overflow: 'hidden',
92
+ textOverflow: 'ellipsis',
93
+ whiteSpace: 'nowrap',
94
+ width: '100%',
95
+ }}
96
+ {...(shouldShowTooltip && {
97
+ 'data-tooltip-id': tooltipId,
98
+ 'data-tooltip-html': tooltipContent,
99
+ })}
100
+ >
101
+ {children}
102
+ {shouldShowTooltip && (
103
+ <Tooltip
104
+ id={tooltipId}
105
+ style={{
106
+ backgroundColor: 'rgba(0, 0, 0, 0.9)',
107
+ color: 'white',
108
+ borderRadius: '6px',
109
+ padding: '8px 12px',
110
+ fontSize: '13px',
111
+ maxWidth: '500px',
112
+ wordWrap: 'break-word',
113
+ zIndex: 1000,
114
+ }}
115
+ place="top"
116
+ offset={5}
117
+ />
118
+ )}
119
+ </div>
120
+ );
121
+ };
122
+
123
+ export default CellWithTooltip;