@visns-studio/visns-components 5.10.2 → 5.10.4
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/README.md +42 -1
- package/package.json +3 -3
- package/src/components/crm/DataGrid.jsx +707 -2686
- package/src/components/crm/Field.jsx +0 -2
- package/src/components/crm/cells/CellWithTooltip.jsx +138 -0
- package/src/components/crm/columns/ColumnRenderers.jsx +1358 -0
- package/src/components/crm/controls/AudioPlayer.jsx +19 -0
- package/src/components/crm/controls/AutoRefreshControls.jsx +37 -0
- package/src/components/crm/controls/DataGridSearch.jsx +238 -0
- package/src/components/crm/modals/GalleryModal.jsx +405 -0
- package/src/components/crm/styles/DataGrid.module.scss +296 -0
- package/src/components/crm/styles/global-datagrid.css +21 -0
- package/src/index.js +11 -0
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
wordWrap = false,
|
|
54
|
+
}) => {
|
|
55
|
+
const cellRef = useRef(null);
|
|
56
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
57
|
+
const [tooltipId] = useState(
|
|
58
|
+
() => `cell-tooltip-${Math.random().toString(36).substr(2, 9)}`
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const checkTruncation = () => {
|
|
63
|
+
if (cellRef.current) {
|
|
64
|
+
const isTruncated = isTextTruncated(cellRef.current);
|
|
65
|
+
setShowTooltip(isTruncated);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Check truncation on mount and when content changes
|
|
70
|
+
checkTruncation();
|
|
71
|
+
|
|
72
|
+
// Also check on window resize
|
|
73
|
+
const handleResize = () => checkTruncation();
|
|
74
|
+
window.addEventListener('resize', handleResize);
|
|
75
|
+
|
|
76
|
+
return () => {
|
|
77
|
+
window.removeEventListener('resize', handleResize);
|
|
78
|
+
};
|
|
79
|
+
}, [children, value]);
|
|
80
|
+
|
|
81
|
+
const tooltipContent = formatCellValueForTooltip(value, columnType);
|
|
82
|
+
|
|
83
|
+
// For wordWrap columns, only show tooltip if explicitly requested (content is still truncated due to height limits)
|
|
84
|
+
// For non-wordWrap columns, show tooltip when content is truncated
|
|
85
|
+
const shouldShowTooltip =
|
|
86
|
+
wordWrap
|
|
87
|
+
? false // Disable tooltip for wordWrap columns since content is visible
|
|
88
|
+
: showTooltip && tooltipContent && tooltipContent.trim() !== '';
|
|
89
|
+
|
|
90
|
+
// Dynamic styles based on wordWrap setting
|
|
91
|
+
const cellStyles = wordWrap
|
|
92
|
+
? {
|
|
93
|
+
width: '100%',
|
|
94
|
+
whiteSpace: 'normal',
|
|
95
|
+
wordWrap: 'break-word',
|
|
96
|
+
overflowWrap: 'break-word',
|
|
97
|
+
overflow: 'visible',
|
|
98
|
+
}
|
|
99
|
+
: {
|
|
100
|
+
overflow: 'hidden',
|
|
101
|
+
textOverflow: 'ellipsis',
|
|
102
|
+
whiteSpace: 'nowrap',
|
|
103
|
+
width: '100%',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
ref={cellRef}
|
|
109
|
+
className={className}
|
|
110
|
+
style={cellStyles}
|
|
111
|
+
{...(shouldShowTooltip && {
|
|
112
|
+
'data-tooltip-id': tooltipId,
|
|
113
|
+
'data-tooltip-html': tooltipContent,
|
|
114
|
+
})}
|
|
115
|
+
>
|
|
116
|
+
{children}
|
|
117
|
+
{shouldShowTooltip && (
|
|
118
|
+
<Tooltip
|
|
119
|
+
id={tooltipId}
|
|
120
|
+
style={{
|
|
121
|
+
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
|
122
|
+
color: 'white',
|
|
123
|
+
borderRadius: '6px',
|
|
124
|
+
padding: '8px 12px',
|
|
125
|
+
fontSize: '13px',
|
|
126
|
+
maxWidth: '500px',
|
|
127
|
+
wordWrap: 'break-word',
|
|
128
|
+
zIndex: 1000,
|
|
129
|
+
}}
|
|
130
|
+
place="top"
|
|
131
|
+
offset={5}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default CellWithTooltip;
|